aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/rockspecs_spec.lua126
-rw-r--r--src/luarocks/rockspecs.lua30
2 files changed, 156 insertions, 0 deletions
diff --git a/spec/rockspecs_spec.lua b/spec/rockspecs_spec.lua
new file mode 100644
index 00000000..76b33f65
--- /dev/null
+++ b/spec/rockspecs_spec.lua
@@ -0,0 +1,126 @@
1
2local rockspecs = require("luarocks.rockspecs")
3local cfg = require("luarocks.core.cfg")
4local test_env = require("spec.util.test_env")
5local lfs = require("lfs")
6
7describe("luarocks.rockspecs", function()
8
9 setup(function()
10 cfg.init()
11 end)
12
13 it("auto adds a build dependency for non-vendored build types", function()
14 local filename = "test-1.0-1.rockspec"
15 local rockspec = {
16 package = "test",
17 source = {
18 url = "",
19 },
20 build = {
21 type = "foo"
22 },
23 }
24 local globals = {}
25 local quick = true
26
27 local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)
28
29 assert(rockspec == out)
30 assert.same(rockspec.build_dependencies, {
31 { name = "luarocks-build-foo", constraints = {} },
32 })
33 end)
34
35 it("does not add a build dependency for non-vendored build type if it's already ther", function()
36 local filename = "test-1.0-1.rockspec"
37 local rockspec = {
38 package = "test",
39 source = {
40 url = "",
41 },
42 build_dependencies = {
43 "luarocks-build-cpp >= 1.0",
44 },
45 build = {
46 type = "cpp"
47 },
48 }
49 local globals = {}
50 local quick = true
51
52 local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)
53
54 assert(rockspec == out)
55
56 assert.same(rockspec.build_dependencies, {
57 { name = "luarocks-build-cpp", constraints = { { op = ">=", version = { string = "1.0", 1, 0 } } } },
58 })
59 end)
60
61 it("does not add a build dependency for 'none' build type", function()
62 local filename = "test-1.0-1.rockspec"
63 local rockspec = {
64 package = "test",
65 source = {
66 url = "",
67 },
68 build = {
69 type = "none"
70 },
71 }
72 local globals = {}
73 local quick = true
74
75 local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)
76
77 assert(rockspec == out)
78 assert.same(rockspec.build_dependencies, {})
79 end)
80
81 it("does not add a build dependency for 'module' build type", function()
82 local filename = "test-1.0-1.rockspec"
83 local rockspec = {
84 package = "test",
85 source = {
86 url = "",
87 },
88 build = {
89 type = "none"
90 },
91 }
92 local globals = {}
93 local quick = true
94
95 local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)
96
97 assert(rockspec == out)
98 assert.same(rockspec.build_dependencies, {})
99 end)
100
101 for d in lfs.dir(test_env.testing_paths.src_dir .. "/luarocks/build") do
102 local name = d:match("(.*)%.lua")
103 if name then
104 it("does not add a build dependency for vendored '" .. name .. "' type", function()
105 local filename = "test-1.0-1.rockspec"
106 local rockspec = {
107 package = "test",
108 source = {
109 url = "",
110 },
111 build = {
112 type = name
113 },
114 }
115 local globals = {}
116 local quick = true
117
118 local out = rockspecs.from_persisted_table(filename, rockspec, globals, quick)
119
120 assert(rockspec == out)
121 assert.same(rockspec.build_dependencies, {})
122 end)
123 end
124 end
125
126end)
diff --git a/src/luarocks/rockspecs.lua b/src/luarocks/rockspecs.lua
index 94462951..c9e17530 100644
--- a/src/luarocks/rockspecs.lua
+++ b/src/luarocks/rockspecs.lua
@@ -8,6 +8,15 @@ local type_rockspec = require("luarocks.type.rockspec")
8local util = require("luarocks.util") 8local util = require("luarocks.util")
9local vers = require("luarocks.core.vers") 9local vers = require("luarocks.core.vers")
10 10
11local vendored_build_type_set = {
12 ["builtin"] = true,
13 ["cmake"] = true,
14 ["command"] = true,
15 ["make"] = true,
16 ["module"] = true, -- compatibility alias
17 ["none"] = true,
18}
19
11local rockspec_mt = {} 20local rockspec_mt = {}
12 21
13rockspec_mt.__index = rockspec_mt 22rockspec_mt.__index = rockspec_mt
@@ -151,6 +160,27 @@ function rockspecs.from_persisted_table(filename, rockspec, globals, quick)
151 end 160 end
152 end 161 end
153 162
163 if rockspec.build
164 and rockspec.build.type
165 and not vendored_build_type_set[rockspec.build.type] then
166 local build_pkg_name = "luarocks-build-" .. rockspec.build.type
167 if not rockspec.build_dependencies then
168 rockspec.build_dependencies = {}
169 end
170
171 local found = false
172 for _, dep in ipairs(rockspec.build_dependencies) do
173 if dep.name == build_pkg_name then
174 found = true
175 break
176 end
177 end
178
179 if not found then
180 table.insert(rockspec.build_dependencies, queries.from_dep_string(build_pkg_name))
181 end
182 end
183
154 if not quick then 184 if not quick then
155 configure_paths(rockspec) 185 configure_paths(rockspec)
156 end 186 end