diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-11 14:48:26 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-13 17:11:12 -0300 |
| commit | e145314e263e9daeb99e0586505a81902e5e483b (patch) | |
| tree | c094cf2eef3fc11303778162fe4c3ef1153d2d27 /src | |
| parent | ec6af45866f86485ca6714398d666a3d6f48b28e (diff) | |
| download | luarocks-e145314e263e9daeb99e0586505a81902e5e483b.tar.gz luarocks-e145314e263e9daeb99e0586505a81902e5e483b.tar.bz2 luarocks-e145314e263e9daeb99e0586505a81902e5e483b.zip | |
Add support for build-only dependencies
Adds the `build_dependencies` key to the rockspec format,
for dependencies that are only triggered when building from
source (e.g. via `luarocks build` or running `luarocks install`
on a rockspec) and not when building from a packaged `.rock`
file using `luarocks install`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/build.lua | 25 | ||||
| -rw-r--r-- | src/luarocks/cmd/build.lua | 1 | ||||
| -rw-r--r-- | src/luarocks/cmd/install.lua | 5 | ||||
| -rw-r--r-- | src/luarocks/deps.lua | 7 | ||||
| -rw-r--r-- | src/luarocks/fetch.lua | 33 | ||||
| -rw-r--r-- | src/luarocks/type/rockspec.lua | 9 |
6 files changed, 49 insertions, 31 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index c08fa6c6..c9e36d89 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
| @@ -173,18 +173,25 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m | |||
| 173 | return nil, "Rockspec error: build type not specified" | 173 | return nil, "Rockspec error: build type not specified" |
| 174 | end | 174 | end |
| 175 | 175 | ||
| 176 | local ok | ||
| 177 | if not build_only_deps then | ||
| 178 | ok, err, errcode = deps.check_external_deps(rockspec, "build") | ||
| 179 | if err then | ||
| 180 | return nil, err, errcode | ||
| 181 | end | ||
| 182 | end | ||
| 183 | |||
| 184 | if deps_mode == "none" then | 176 | if deps_mode == "none" then |
| 185 | util.warning("skipping dependency checks.") | 177 | util.warning("skipping dependency checks.") |
| 186 | else | 178 | else |
| 187 | local ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode) | 179 | |
| 180 | if not build_only_deps then | ||
| 181 | local ok, err, errcode = deps.check_external_deps(rockspec, "build") | ||
| 182 | if err then | ||
| 183 | return nil, err, errcode | ||
| 184 | end | ||
| 185 | |||
| 186 | if next(rockspec.build_dependencies) then | ||
| 187 | local ok, err, errcode = deps.fulfill_dependencies(rockspec, "build_dependencies", deps_mode) | ||
| 188 | if err then | ||
| 189 | return nil, err, errcode | ||
| 190 | end | ||
| 191 | end | ||
| 192 | end | ||
| 193 | |||
| 194 | local ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", deps_mode) | ||
| 188 | if err then | 195 | if err then |
| 189 | return nil, err, errcode | 196 | return nil, err, errcode |
| 190 | end | 197 | end |
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index 1b5c8fdc..0a408fb4 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua | |||
| @@ -8,7 +8,6 @@ local path = require("luarocks.path") | |||
| 8 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| 9 | local fetch = require("luarocks.fetch") | 9 | local fetch = require("luarocks.fetch") |
| 10 | local fs = require("luarocks.fs") | 10 | local fs = require("luarocks.fs") |
| 11 | local dir = require("luarocks.dir") | ||
| 12 | local deps = require("luarocks.deps") | 11 | local deps = require("luarocks.deps") |
| 13 | local remove = require("luarocks.remove") | 12 | local remove = require("luarocks.remove") |
| 14 | local cfg = require("luarocks.core.cfg") | 13 | local cfg = require("luarocks.core.cfg") |
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index 80fc4d27..c1d9ccc7 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua | |||
| @@ -12,7 +12,6 @@ local writer = require("luarocks.manif.writer") | |||
| 12 | local remove = require("luarocks.remove") | 12 | local remove = require("luarocks.remove") |
| 13 | local search = require("luarocks.search") | 13 | local search = require("luarocks.search") |
| 14 | local queries = require("luarocks.queries") | 14 | local queries = require("luarocks.queries") |
| 15 | local vers = require("luarocks.core.vers") | ||
| 16 | local cfg = require("luarocks.core.cfg") | 15 | local cfg = require("luarocks.core.cfg") |
| 17 | 16 | ||
| 18 | install.help_summary = "Install a rock." | 17 | install.help_summary = "Install a rock." |
| @@ -89,7 +88,7 @@ function install.install_binary_rock(rock_file, deps_mode, namespace) | |||
| 89 | end | 88 | end |
| 90 | 89 | ||
| 91 | if deps_mode ~= "none" then | 90 | if deps_mode ~= "none" then |
| 92 | ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode) | 91 | ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", deps_mode) |
| 93 | if err then return nil, err, errcode end | 92 | if err then return nil, err, errcode end |
| 94 | end | 93 | end |
| 95 | 94 | ||
| @@ -137,7 +136,7 @@ function install.install_binary_rock_deps(rock_file, deps_mode) | |||
| 137 | return nil, "Failed loading rockspec for installed package: "..err, errcode | 136 | return nil, "Failed loading rockspec for installed package: "..err, errcode |
| 138 | end | 137 | end |
| 139 | 138 | ||
| 140 | ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode) | 139 | ok, err, errcode = deps.fulfill_dependencies(rockspec, "dependencies", deps_mode) |
| 141 | if err then return nil, err, errcode end | 140 | if err then return nil, err, errcode end |
| 142 | 141 | ||
| 143 | util.printout() | 142 | util.printout() |
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index ccbced0c..ae15cd5e 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
| @@ -124,10 +124,11 @@ end | |||
| 124 | -- Packages are installed using the LuaRocks "install" command. | 124 | -- Packages are installed using the LuaRocks "install" command. |
| 125 | -- Aborts the program if a dependency could not be fulfilled. | 125 | -- Aborts the program if a dependency could not be fulfilled. |
| 126 | -- @param rockspec table: A rockspec in table format. | 126 | -- @param rockspec table: A rockspec in table format. |
| 127 | -- @param depskey table: Rockspec key to fetch to get dependency table. | ||
| 127 | -- @return boolean or (nil, string, [string]): True if no errors occurred, or | 128 | -- @return boolean or (nil, string, [string]): True if no errors occurred, or |
| 128 | -- nil and an error message if any test failed, followed by an optional | 129 | -- nil and an error message if any test failed, followed by an optional |
| 129 | -- error code. | 130 | -- error code. |
| 130 | function deps.fulfill_dependencies(rockspec, deps_mode) | 131 | function deps.fulfill_dependencies(rockspec, depskey, deps_mode) |
| 131 | 132 | ||
| 132 | local search = require("luarocks.search") | 133 | local search = require("luarocks.search") |
| 133 | local install = require("luarocks.cmd.install") | 134 | local install = require("luarocks.cmd.install") |
| @@ -160,11 +161,11 @@ function deps.fulfill_dependencies(rockspec, deps_mode) | |||
| 160 | end | 161 | end |
| 161 | end | 162 | end |
| 162 | 163 | ||
| 163 | deps.report_missing_dependencies(rockspec.name, rockspec.version, rockspec.dependencies, deps_mode, rockspec.rocks_provided) | 164 | deps.report_missing_dependencies(rockspec.name, rockspec.version, rockspec[depskey], deps_mode, rockspec.rocks_provided) |
| 164 | 165 | ||
| 165 | local first_missing_dep = true | 166 | local first_missing_dep = true |
| 166 | 167 | ||
| 167 | for _, dep in ipairs(rockspec.dependencies) do | 168 | for _, dep in ipairs(rockspec[depskey]) do |
| 168 | if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then | 169 | if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then |
| 169 | if first_missing_dep then | 170 | if first_missing_dep then |
| 170 | util.printout() | 171 | util.printout() |
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index db99c3d5..ce9aaff5 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
| @@ -180,6 +180,20 @@ function fetch.url_to_base_dir(url) | |||
| 180 | return (base:gsub("%.([^.]*)$", known_exts):gsub("%.tar", "")) | 180 | return (base:gsub("%.([^.]*)$", known_exts):gsub("%.tar", "")) |
| 181 | end | 181 | end |
| 182 | 182 | ||
| 183 | local function convert_dependencies(rockspec, key) | ||
| 184 | if rockspec[key] then | ||
| 185 | for i = 1, #rockspec[key] do | ||
| 186 | local parsed, err = queries.from_dep_string(rockspec[key][i]) | ||
| 187 | if not parsed then | ||
| 188 | return nil, "Parse error processing dependency '"..rockspec[key][i].."': "..tostring(err) | ||
| 189 | end | ||
| 190 | rockspec[key][i] = parsed | ||
| 191 | end | ||
| 192 | else | ||
| 193 | rockspec[key] = {} | ||
| 194 | end | ||
| 195 | end | ||
| 196 | |||
| 183 | --- Back-end function that actually loads the local rockspec. | 197 | --- Back-end function that actually loads the local rockspec. |
| 184 | -- Performs some validation and postprocessing of the rockspec contents. | 198 | -- Performs some validation and postprocessing of the rockspec contents. |
| 185 | -- @param filename string: The local filename of the rockspec file. | 199 | -- @param filename string: The local filename of the rockspec file. |
| @@ -212,10 +226,6 @@ function fetch.load_local_rockspec(filename, quick) | |||
| 212 | end | 226 | end |
| 213 | end | 227 | end |
| 214 | 228 | ||
| 215 | rockspec.format_is_at_least = function(_, v) | ||
| 216 | return parsed_format >= vers.parse_version(v) | ||
| 217 | end | ||
| 218 | |||
| 219 | --- Check if rockspec format version satisfies version requirement. | 229 | --- Check if rockspec format version satisfies version requirement. |
| 220 | -- @param rockspec table: The rockspec table. | 230 | -- @param rockspec table: The rockspec table. |
| 221 | -- @param version string: required version. | 231 | -- @param version string: required version. |
| @@ -229,6 +239,7 @@ function fetch.load_local_rockspec(filename, quick) | |||
| 229 | 239 | ||
| 230 | util.platform_overrides(rockspec.build) | 240 | util.platform_overrides(rockspec.build) |
| 231 | util.platform_overrides(rockspec.dependencies) | 241 | util.platform_overrides(rockspec.dependencies) |
| 242 | util.platform_overrides(rockspec.build_dependencies) | ||
| 232 | util.platform_overrides(rockspec.external_dependencies) | 243 | util.platform_overrides(rockspec.external_dependencies) |
| 233 | util.platform_overrides(rockspec.source) | 244 | util.platform_overrides(rockspec.source) |
| 234 | util.platform_overrides(rockspec.hooks) | 245 | util.platform_overrides(rockspec.hooks) |
| @@ -274,17 +285,9 @@ function fetch.load_local_rockspec(filename, quick) | |||
| 274 | and cfg.rocks_provided_3_0 | 285 | and cfg.rocks_provided_3_0 |
| 275 | or cfg.rocks_provided) | 286 | or cfg.rocks_provided) |
| 276 | 287 | ||
| 277 | if rockspec.dependencies then | 288 | convert_dependencies(rockspec, "dependencies") |
| 278 | for i = 1, #rockspec.dependencies do | 289 | convert_dependencies(rockspec, "build_dependencies") |
| 279 | local parsed, err = queries.from_dep_string(rockspec.dependencies[i]) | 290 | |
| 280 | if not parsed then | ||
| 281 | return nil, "Parse error processing dependency '"..rockspec.dependencies[i].."': "..tostring(err) | ||
| 282 | end | ||
| 283 | rockspec.dependencies[i] = parsed | ||
| 284 | end | ||
| 285 | else | ||
| 286 | rockspec.dependencies = {} | ||
| 287 | end | ||
| 288 | if not quick then | 291 | if not quick then |
| 289 | path.configure_paths(rockspec) | 292 | path.configure_paths(rockspec) |
| 290 | end | 293 | end |
diff --git a/src/luarocks/type/rockspec.lua b/src/luarocks/type/rockspec.lua index 214f8e0f..54ce9db8 100644 --- a/src/luarocks/type/rockspec.lua +++ b/src/luarocks/type/rockspec.lua | |||
| @@ -48,6 +48,15 @@ local rockspec_types = { | |||
| 48 | }, | 48 | }, |
| 49 | }, | 49 | }, |
| 50 | }, | 50 | }, |
| 51 | build_dependencies = { | ||
| 52 | _version = "3.0", | ||
| 53 | platforms = {}, -- recursively defined below | ||
| 54 | _any = { | ||
| 55 | _type = "string", | ||
| 56 | _name = "a valid dependency string", | ||
| 57 | _pattern = "%s*([a-zA-Z0-9%.%-%_]*/?[a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*([^/]*)", | ||
| 58 | }, | ||
| 59 | }, | ||
| 51 | supported_platforms = { | 60 | supported_platforms = { |
| 52 | _any = string_1, | 61 | _any = string_1, |
| 53 | }, | 62 | }, |
