diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-23 10:57:43 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-05-07 19:27:37 -0300 |
| commit | 40792c08eaed0ca44b00aae04885e43c3de0701d (patch) | |
| tree | b4bb410e0946613e2a5011435a0703fa720920b0 /src | |
| parent | 28124aadbeaaa35f2c22b12cae96092466c1ded4 (diff) | |
| download | luarocks-40792c08eaed0ca44b00aae04885e43c3de0701d.tar.gz luarocks-40792c08eaed0ca44b00aae04885e43c3de0701d.tar.bz2 luarocks-40792c08eaed0ca44b00aae04885e43c3de0701d.zip | |
deps: add fulfill_dependency for resolving a single dependency
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/deps.lua | 99 | ||||
| -rw-r--r-- | src/luarocks/manif.lua | 8 |
2 files changed, 64 insertions, 43 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 26373177..b1ff6c47 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
| @@ -22,28 +22,29 @@ local function match_dep(dep, blacklist, deps_mode, rocks_provided) | |||
| 22 | assert(type(dep) == "table") | 22 | assert(type(dep) == "table") |
| 23 | assert(type(rocks_provided) == "table") | 23 | assert(type(rocks_provided) == "table") |
| 24 | 24 | ||
| 25 | local versions | 25 | local versions, locations |
| 26 | local provided = rocks_provided[dep.name] | 26 | local provided = rocks_provided[dep.name] |
| 27 | if provided then | 27 | if provided then |
| 28 | -- Provided rocks have higher priority than manifest's rocks. | 28 | -- Provided rocks have higher priority than manifest's rocks. |
| 29 | versions = { provided } | 29 | versions, locations = { provided }, {} |
| 30 | else | 30 | else |
| 31 | versions = manif.get_versions(dep, deps_mode) | 31 | versions, locations = manif.get_versions(dep, deps_mode) |
| 32 | end | 32 | end |
| 33 | 33 | ||
| 34 | local latest_version | 34 | local latest_version |
| 35 | local latest_vstring | ||
| 35 | for _, vstring in ipairs(versions) do | 36 | for _, vstring in ipairs(versions) do |
| 36 | if not blacklist or not blacklist[vstring] then | 37 | if not blacklist or not blacklist[vstring] then |
| 37 | local version = vers.parse_version(vstring) | 38 | local version = vers.parse_version(vstring) |
| 38 | if vers.match_constraints(version, dep.constraints) then | 39 | if vers.match_constraints(version, dep.constraints) then |
| 39 | if not latest_version or version > latest_version then | 40 | if not latest_version or version > latest_version then |
| 40 | latest_version = version | 41 | latest_version = version |
| 42 | latest_vstring = vstring | ||
| 41 | end | 43 | end |
| 42 | end | 44 | end |
| 43 | end | 45 | end |
| 44 | end | 46 | end |
| 45 | 47 | return latest_vstring, locations[latest_vstring] | |
| 46 | return latest_version and latest_version.string | ||
| 47 | end | 48 | end |
| 48 | 49 | ||
| 49 | --- Attempt to match dependencies of a rockspec to installed rocks. | 50 | --- Attempt to match dependencies of a rockspec to installed rocks. |
| @@ -126,6 +127,56 @@ function deps.report_missing_dependencies(name, version, dependencies, deps_mode | |||
| 126 | end | 127 | end |
| 127 | end | 128 | end |
| 128 | 129 | ||
| 130 | function deps.fulfill_dependency(dep, deps_mode, name, version, rocks_provided) | ||
| 131 | assert(dep:type() == "query") | ||
| 132 | assert(type(deps_mode) == "string" or deps_mode == nil) | ||
| 133 | assert(type(name) == "string" or name == nil) | ||
| 134 | assert(type(version) == "string" or version == nil) | ||
| 135 | assert(type(rocks_provided) == "table" or rocks_provided == nil) | ||
| 136 | deps_mode = deps_mode or "all" | ||
| 137 | rocks_provided = rocks_provided or {} | ||
| 138 | |||
| 139 | local found, where = match_dep(dep, nil, deps_mode, rocks_provided) | ||
| 140 | if found then | ||
| 141 | return true, found, where | ||
| 142 | end | ||
| 143 | |||
| 144 | local search = require("luarocks.search") | ||
| 145 | local install = require("luarocks.cmd.install") | ||
| 146 | |||
| 147 | if name and version then | ||
| 148 | util.printout(("%s %s depends on %s (%s)"):format( | ||
| 149 | name, version, tostring(dep), rock_status(dep.name, deps_mode, rocks_provided))) | ||
| 150 | else | ||
| 151 | util.printout(("Fulfilling dependency on %s (%s)"):format( | ||
| 152 | tostring(dep), rock_status(dep.name, deps_mode, rocks_provided))) | ||
| 153 | end | ||
| 154 | |||
| 155 | if dep.constraints[1] and dep.constraints[1].no_upgrade then | ||
| 156 | util.printerr("This version of "..name.." is designed for use with") | ||
| 157 | util.printerr(tostring(dep)..", but is configured to avoid upgrading it") | ||
| 158 | util.printerr("automatically. Please upgrade "..dep.name.." with") | ||
| 159 | util.printerr(" luarocks install "..dep.name) | ||
| 160 | util.printerr("or choose an older version of "..name.." with") | ||
| 161 | util.printerr(" luarocks search "..name) | ||
| 162 | return nil, "Failed matching dependencies" | ||
| 163 | end | ||
| 164 | |||
| 165 | local url, search_err = search.find_suitable_rock(dep) | ||
| 166 | if not url then | ||
| 167 | return nil, "Could not satisfy dependency "..tostring(dep)..": "..search_err | ||
| 168 | end | ||
| 169 | util.printout("Installing "..url) | ||
| 170 | local ok, install_err, errcode = install.command({deps_mode = deps_mode, namespace = dep.namespace}, url) | ||
| 171 | if not ok then | ||
| 172 | return nil, "Failed installing dependency: "..url.." - "..install_err, errcode | ||
| 173 | end | ||
| 174 | |||
| 175 | found, where = match_dep(dep, nil, deps_mode, rocks_provided) | ||
| 176 | assert(found) | ||
| 177 | return true, found, where | ||
| 178 | end | ||
| 179 | |||
| 129 | --- Check dependencies of a rock and attempt to install any missing ones. | 180 | --- Check dependencies of a rock and attempt to install any missing ones. |
| 130 | -- Packages are installed using the LuaRocks "install" command. | 181 | -- Packages are installed using the LuaRocks "install" command. |
| 131 | -- Aborts the program if a dependency could not be fulfilled. | 182 | -- Aborts the program if a dependency could not be fulfilled. |
| @@ -135,10 +186,6 @@ end | |||
| 135 | -- nil and an error message if any test failed, followed by an optional | 186 | -- nil and an error message if any test failed, followed by an optional |
| 136 | -- error code. | 187 | -- error code. |
| 137 | function deps.fulfill_dependencies(rockspec, depskey, deps_mode) | 188 | function deps.fulfill_dependencies(rockspec, depskey, deps_mode) |
| 138 | |||
| 139 | local search = require("luarocks.search") | ||
| 140 | local install = require("luarocks.cmd.install") | ||
| 141 | |||
| 142 | if rockspec.supported_platforms then | 189 | if rockspec.supported_platforms then |
| 143 | if not deps.platforms_set then | 190 | if not deps.platforms_set then |
| 144 | deps.platforms_set = values_set(cfg.platforms) | 191 | deps.platforms_set = values_set(cfg.platforms) |
| @@ -169,37 +216,11 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode) | |||
| 169 | 216 | ||
| 170 | deps.report_missing_dependencies(rockspec.name, rockspec.version, rockspec[depskey], deps_mode, rockspec.rocks_provided) | 217 | deps.report_missing_dependencies(rockspec.name, rockspec.version, rockspec[depskey], deps_mode, rockspec.rocks_provided) |
| 171 | 218 | ||
| 172 | local first_missing_dep = true | 219 | util.printout() |
| 173 | |||
| 174 | for _, dep in ipairs(rockspec[depskey]) do | 220 | for _, dep in ipairs(rockspec[depskey]) do |
| 175 | if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then | 221 | local ok, err = deps.fulfill_dependency(dep, deps_mode, rockspec.name, rockspec.version, rockspec.rocks_provided) |
| 176 | if first_missing_dep then | 222 | if not ok then |
| 177 | util.printout() | 223 | return nil, err |
| 178 | first_missing_dep = false | ||
| 179 | end | ||
| 180 | |||
| 181 | util.printout(("%s %s depends on %s (%s)"):format( | ||
| 182 | rockspec.name, rockspec.version, tostring(dep), rock_status(dep.name, deps_mode, rockspec.rocks_provided))) | ||
| 183 | |||
| 184 | if dep.constraints[1] and dep.constraints[1].no_upgrade then | ||
| 185 | util.printerr("This version of "..rockspec.name.." is designed for use with") | ||
| 186 | util.printerr(tostring(dep)..", but is configured to avoid upgrading it") | ||
| 187 | util.printerr("automatically. Please upgrade "..dep.name.." with") | ||
| 188 | util.printerr(" luarocks install "..dep.name) | ||
| 189 | util.printerr("or choose an older version of "..rockspec.name.." with") | ||
| 190 | util.printerr(" luarocks search "..rockspec.name) | ||
| 191 | return nil, "Failed matching dependencies" | ||
| 192 | end | ||
| 193 | |||
| 194 | local url, search_err = search.find_suitable_rock(dep) | ||
| 195 | if not url then | ||
| 196 | return nil, "Could not satisfy dependency "..tostring(dep)..": "..search_err | ||
| 197 | end | ||
| 198 | util.printout("Installing "..url) | ||
| 199 | local ok, install_err, errcode = install.command({deps_mode = deps_mode, namespace = dep.namespace}, url) | ||
| 200 | if not ok then | ||
| 201 | return nil, "Failed installing dependency: "..url.." - "..install_err, errcode | ||
| 202 | end | ||
| 203 | end | 224 | end |
| 204 | end | 225 | end |
| 205 | 226 | ||
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index a982c6f7..c6d0e168 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -242,7 +242,7 @@ end | |||
| 242 | -- (use the current tree and all trees below it on the list) | 242 | -- (use the current tree and all trees below it on the list) |
| 243 | -- or "all", to use all trees. | 243 | -- or "all", to use all trees. |
| 244 | -- @return table: An array of strings listing installed | 244 | -- @return table: An array of strings listing installed |
| 245 | -- versions of a package. | 245 | -- versions of a package, and a table indicating where they are found. |
| 246 | function manif.get_versions(dep, deps_mode) | 246 | function manif.get_versions(dep, deps_mode) |
| 247 | assert(type(dep) == "table") | 247 | assert(type(dep) == "table") |
| 248 | assert(type(deps_mode) == "string") | 248 | assert(type(deps_mode) == "string") |
| @@ -263,17 +263,17 @@ function manif.get_versions(dep, deps_mode) | |||
| 263 | local ns = fd:read("*a") | 263 | local ns = fd:read("*a") |
| 264 | fd:close() | 264 | fd:close() |
| 265 | if ns == namespace then | 265 | if ns == namespace then |
| 266 | version_set[version] = true | 266 | version_set[version] = tree |
| 267 | end | 267 | end |
| 268 | end | 268 | end |
| 269 | else | 269 | else |
| 270 | version_set[version] = true | 270 | version_set[version] = tree |
| 271 | end | 271 | end |
| 272 | end | 272 | end |
| 273 | end | 273 | end |
| 274 | end) | 274 | end) |
| 275 | 275 | ||
| 276 | return util.keys(version_set) | 276 | return util.keys(version_set), version_set |
| 277 | end | 277 | end |
| 278 | 278 | ||
| 279 | return manif | 279 | return manif |
