diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2016-05-27 17:14:29 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2016-05-27 17:14:29 -0300 |
| commit | 38119eca55728e1a1187b101a19d36886818a697 (patch) | |
| tree | 1bce4707ef72c099edfa467867ee2d940d56c928 /src | |
| parent | 4c12525d1f52bccc71c2a3054d3db328a0577179 (diff) | |
| parent | 22c8993ebe5f509ee55b8af6b7a8be147b3884e6 (diff) | |
| download | luarocks-38119eca55728e1a1187b101a19d36886818a697.tar.gz luarocks-38119eca55728e1a1187b101a19d36886818a697.tar.bz2 luarocks-38119eca55728e1a1187b101a19d36886818a697.zip | |
Merge pull request #563 from mpeterv/new-version-no-arg
luarocks new-version: make rockspec argument optional
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/make.lua | 59 | ||||
| -rw-r--r-- | src/luarocks/new_version.lua | 13 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 65 |
3 files changed, 78 insertions, 59 deletions
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 78c43d91..5058da79 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
| @@ -49,33 +49,6 @@ To install rocks, you'll normally want to use the "install" and | |||
| 49 | 49 | ||
| 50 | ]] | 50 | ]] |
| 51 | 51 | ||
| 52 | --- Collect rockspecs located in a subdirectory. | ||
| 53 | -- @param versions table: A table mapping rock names to newest rockspec versions. | ||
| 54 | -- @param paths table: A table mapping rock names to newest rockspec paths. | ||
| 55 | -- @param unnamed_paths table: An array of rockspec paths that don't contain rock | ||
| 56 | -- name and version in regular format. | ||
| 57 | -- @param subdir string: path to subdirectory. | ||
| 58 | local function collect_rockspecs(versions, paths, unnamed_paths, subdir) | ||
| 59 | if fs.is_dir(subdir) then | ||
| 60 | for file in fs.dir(subdir) do | ||
| 61 | file = dir.path(subdir, file) | ||
| 62 | |||
| 63 | if file:match("rockspec$") and fs.is_file(file) then | ||
| 64 | local rock, version = path.parse_name(file) | ||
| 65 | |||
| 66 | if rock then | ||
| 67 | if not versions[rock] or deps.compare_versions(version, versions[rock]) then | ||
| 68 | versions[rock] = version | ||
| 69 | paths[rock] = file | ||
| 70 | end | ||
| 71 | else | ||
| 72 | table.insert(unnamed_paths, file) | ||
| 73 | end | ||
| 74 | end | ||
| 75 | end | ||
| 76 | end | ||
| 77 | end | ||
| 78 | |||
| 79 | --- Driver function for "make" command. | 52 | --- Driver function for "make" command. |
| 80 | -- @param name string: A local rockspec. | 53 | -- @param name string: A local rockspec. |
| 81 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an | 54 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an |
| @@ -85,34 +58,10 @@ function make.run(...) | |||
| 85 | assert(type(rockspec) == "string" or not rockspec) | 58 | assert(type(rockspec) == "string" or not rockspec) |
| 86 | 59 | ||
| 87 | if not rockspec then | 60 | if not rockspec then |
| 88 | -- Try to infer default rockspec name. | 61 | local err |
| 89 | local versions, paths, unnamed_paths = {}, {}, {} | 62 | rockspec, err = util.get_default_rockspec() |
| 90 | -- Look for rockspecs in some common locations. | 63 | if not rockspec then |
| 91 | collect_rockspecs(versions, paths, unnamed_paths, ".") | 64 | return nil, err |
| 92 | collect_rockspecs(versions, paths, unnamed_paths, "rockspec") | ||
| 93 | collect_rockspecs(versions, paths, unnamed_paths, "rockspecs") | ||
| 94 | |||
| 95 | if #unnamed_paths > 0 then | ||
| 96 | -- There are rockspecs not following "name-version.rockspec" format. | ||
| 97 | -- More than one are ambiguous. | ||
| 98 | if #unnamed_paths > 1 then | ||
| 99 | return nil, "Please specify which rockspec file to use." | ||
| 100 | else | ||
| 101 | rockspec = unnamed_paths[1] | ||
| 102 | end | ||
| 103 | else | ||
| 104 | local rock = next(versions) | ||
| 105 | |||
| 106 | if rock then | ||
| 107 | -- If there are rockspecs for multiple rocks it's ambiguous. | ||
| 108 | if next(versions, rock) then | ||
| 109 | return nil, "Please specify which rockspec file to use." | ||
| 110 | else | ||
| 111 | rockspec = paths[rock] | ||
| 112 | end | ||
| 113 | else | ||
| 114 | return nil, "Argument missing: please specify a rockspec to use on current directory." | ||
| 115 | end | ||
| 116 | end | 65 | end |
| 117 | end | 66 | end |
| 118 | if not rockspec:match("rockspec$") then | 67 | if not rockspec:match("rockspec$") then |
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index 6969d4b2..3382b85c 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua | |||
| @@ -11,13 +11,14 @@ local fs = require("luarocks.fs") | |||
| 11 | local type_check = require("luarocks.type_check") | 11 | local type_check = require("luarocks.type_check") |
| 12 | 12 | ||
| 13 | new_version.help_summary = "Auto-write a rockspec for a new version of a rock." | 13 | new_version.help_summary = "Auto-write a rockspec for a new version of a rock." |
| 14 | new_version.help_arguments = "[--tag=<tag>] {<package>|<rockspec>} [<new_version>] [<new_url>]" | 14 | new_version.help_arguments = "[--tag=<tag>] [<package>|<rockspec>] [<new_version>] [<new_url>]" |
| 15 | new_version.help = [[ | 15 | new_version.help = [[ |
| 16 | This is a utility function that writes a new rockspec, updating data | 16 | This is a utility function that writes a new rockspec, updating data |
| 17 | from a previous one. | 17 | from a previous one. |
| 18 | 18 | ||
| 19 | If a package name is given, it downloads the latest rockspec from the | 19 | If a package name is given, it downloads the latest rockspec from the |
| 20 | default server. If a rockspec is given, it uses it instead. | 20 | default server. If a rockspec is given, it uses it instead. If no argument |
| 21 | is given, it looks for a rockspec same way 'luarocks make' does. | ||
| 21 | 22 | ||
| 22 | If the version number is not given and tag is passed using --tag, | 23 | If the version number is not given and tag is passed using --tag, |
| 23 | it is used as the version, with 'v' removed from beginning. | 24 | it is used as the version, with 'v' removed from beginning. |
| @@ -125,12 +126,16 @@ end | |||
| 125 | function new_version.run(...) | 126 | function new_version.run(...) |
| 126 | local flags, input, version, url = util.parse_flags(...) | 127 | local flags, input, version, url = util.parse_flags(...) |
| 127 | if not input then | 128 | if not input then |
| 128 | return nil, "Missing argument: expected package or rockspec. "..util.see_help("new_version") | 129 | local err |
| 130 | input, err = util.get_default_rockspec() | ||
| 131 | if not input then | ||
| 132 | return nil, err | ||
| 133 | end | ||
| 129 | end | 134 | end |
| 130 | assert(type(input) == "string") | 135 | assert(type(input) == "string") |
| 131 | 136 | ||
| 132 | local filename = input | 137 | local filename = input |
| 133 | if not input:match(".rockspec$") then | 138 | if not input:match("rockspec$") then |
| 134 | local err | 139 | local err |
| 135 | filename, err = download.download("rockspec", input) | 140 | filename, err = download.download("rockspec", input) |
| 136 | if not filename then | 141 | if not filename then |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 520625c0..2f419a3d 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -520,6 +520,71 @@ function util.announce_install(rockspec) | |||
| 520 | util.printout() | 520 | util.printout() |
| 521 | end | 521 | end |
| 522 | 522 | ||
| 523 | --- Collect rockspecs located in a subdirectory. | ||
| 524 | -- @param versions table: A table mapping rock names to newest rockspec versions. | ||
| 525 | -- @param paths table: A table mapping rock names to newest rockspec paths. | ||
| 526 | -- @param unnamed_paths table: An array of rockspec paths that don't contain rock | ||
| 527 | -- name and version in regular format. | ||
| 528 | -- @param subdir string: path to subdirectory. | ||
| 529 | local function collect_rockspecs(versions, paths, unnamed_paths, subdir) | ||
| 530 | local fs = require("luarocks.fs") | ||
| 531 | local dir = require("luarocks.dir") | ||
| 532 | local path = require("luarocks.path") | ||
| 533 | local deps = require("luarocks.deps") | ||
| 534 | |||
| 535 | if fs.is_dir(subdir) then | ||
| 536 | for file in fs.dir(subdir) do | ||
| 537 | file = dir.path(subdir, file) | ||
| 538 | |||
| 539 | if file:match("rockspec$") and fs.is_file(file) then | ||
| 540 | local rock, version = path.parse_name(file) | ||
| 541 | |||
| 542 | if rock then | ||
| 543 | if not versions[rock] or deps.compare_versions(version, versions[rock]) then | ||
| 544 | versions[rock] = version | ||
| 545 | paths[rock] = file | ||
| 546 | end | ||
| 547 | else | ||
| 548 | table.insert(unnamed_paths, file) | ||
| 549 | end | ||
| 550 | end | ||
| 551 | end | ||
| 552 | end | ||
| 553 | end | ||
| 554 | |||
| 555 | --- Get default rockspec name for commands that take optional rockspec name. | ||
| 556 | -- @return string or (nil, string): path to the rockspec or nil and error message. | ||
| 557 | function util.get_default_rockspec() | ||
| 558 | local versions, paths, unnamed_paths = {}, {}, {} | ||
| 559 | -- Look for rockspecs in some common locations. | ||
| 560 | collect_rockspecs(versions, paths, unnamed_paths, ".") | ||
| 561 | collect_rockspecs(versions, paths, unnamed_paths, "rockspec") | ||
| 562 | collect_rockspecs(versions, paths, unnamed_paths, "rockspecs") | ||
| 563 | |||
| 564 | if #unnamed_paths > 0 then | ||
| 565 | -- There are rockspecs not following "name-version.rockspec" format. | ||
| 566 | -- More than one are ambiguous. | ||
| 567 | if #unnamed_paths > 1 then | ||
| 568 | return nil, "Please specify which rockspec file to use." | ||
| 569 | else | ||
| 570 | return unnamed_paths[1] | ||
| 571 | end | ||
| 572 | else | ||
| 573 | local rock = next(versions) | ||
| 574 | |||
| 575 | if rock then | ||
| 576 | -- If there are rockspecs for multiple rocks it's ambiguous. | ||
| 577 | if next(versions, rock) then | ||
| 578 | return nil, "Please specify which rockspec file to use." | ||
| 579 | else | ||
| 580 | return paths[rock] | ||
| 581 | end | ||
| 582 | else | ||
| 583 | return nil, "Argument missing: please specify a rockspec to use on current directory." | ||
| 584 | end | ||
| 585 | end | ||
| 586 | end | ||
| 587 | |||
| 523 | -- from http://lua-users.org/wiki/SplitJoin | 588 | -- from http://lua-users.org/wiki/SplitJoin |
| 524 | -- by PhilippeLhoste | 589 | -- by PhilippeLhoste |
| 525 | function util.split_string(str, delim, maxNb) | 590 | function util.split_string(str, delim, maxNb) |
