diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2023-10-31 21:28:45 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-31 21:28:45 -0300 |
| commit | 4cfcf9d8df1abd7cca9f2c3590402ada543df327 (patch) | |
| tree | 84ca4100af7fe6d64bd53a7badefc27f436772d0 | |
| parent | 82cca3c53aeedfa5ed1415f3a63e6d85117a8264 (diff) | |
| download | luarocks-4cfcf9d8df1abd7cca9f2c3590402ada543df327.tar.gz luarocks-4cfcf9d8df1abd7cca9f2c3590402ada543df327.tar.bz2 luarocks-4cfcf9d8df1abd7cca9f2c3590402ada543df327.zip | |
feat: auto-add luarocks-build-<build.type> build dependency (#1542)
| -rw-r--r-- | spec/rockspecs_spec.lua | 126 | ||||
| -rw-r--r-- | src/luarocks/rockspecs.lua | 30 |
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 | |||
| 2 | local rockspecs = require("luarocks.rockspecs") | ||
| 3 | local cfg = require("luarocks.core.cfg") | ||
| 4 | local test_env = require("spec.util.test_env") | ||
| 5 | local lfs = require("lfs") | ||
| 6 | |||
| 7 | describe("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 | |||
| 126 | end) | ||
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") | |||
| 8 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| 9 | local vers = require("luarocks.core.vers") | 9 | local vers = require("luarocks.core.vers") |
| 10 | 10 | ||
| 11 | local 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 | |||
| 11 | local rockspec_mt = {} | 20 | local rockspec_mt = {} |
| 12 | 21 | ||
| 13 | rockspec_mt.__index = rockspec_mt | 22 | rockspec_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 |
