aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2016-05-27 17:14:29 -0300
committerHisham Muhammad <hisham@gobolinux.org>2016-05-27 17:14:29 -0300
commit38119eca55728e1a1187b101a19d36886818a697 (patch)
tree1bce4707ef72c099edfa467867ee2d940d56c928
parent4c12525d1f52bccc71c2a3054d3db328a0577179 (diff)
parent22c8993ebe5f509ee55b8af6b7a8be147b3884e6 (diff)
downloadluarocks-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
-rw-r--r--src/luarocks/make.lua59
-rw-r--r--src/luarocks/new_version.lua13
-rw-r--r--src/luarocks/util.lua65
-rwxr-xr-xtest/testing.sh2
4 files changed, 79 insertions, 60 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.
58local 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
77end
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")
11local type_check = require("luarocks.type_check") 11local type_check = require("luarocks.type_check")
12 12
13new_version.help_summary = "Auto-write a rockspec for a new version of a rock." 13new_version.help_summary = "Auto-write a rockspec for a new version of a rock."
14new_version.help_arguments = "[--tag=<tag>] {<package>|<rockspec>} [<new_version>] [<new_url>]" 14new_version.help_arguments = "[--tag=<tag>] [<package>|<rockspec>] [<new_version>] [<new_url>]"
15new_version.help = [[ 15new_version.help = [[
16This is a utility function that writes a new rockspec, updating data 16This is a utility function that writes a new rockspec, updating data
17from a previous one. 17from a previous one.
18 18
19If a package name is given, it downloads the latest rockspec from the 19If a package name is given, it downloads the latest rockspec from the
20default server. If a rockspec is given, it uses it instead. 20default server. If a rockspec is given, it uses it instead. If no argument
21is given, it looks for a rockspec same way 'luarocks make' does.
21 22
22If the version number is not given and tag is passed using --tag, 23If the version number is not given and tag is passed using --tag,
23it is used as the version, with 'v' removed from beginning. 24it is used as the version, with 'v' removed from beginning.
@@ -125,12 +126,16 @@ end
125function new_version.run(...) 126function 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()
521end 521end
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.
529local 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
553end
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.
557function 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
586end
587
523-- from http://lua-users.org/wiki/SplitJoin 588-- from http://lua-users.org/wiki/SplitJoin
524-- by PhilippeLhoste 589-- by PhilippeLhoste
525function util.split_string(str, delim, maxNb) 590function util.split_string(str, delim, maxNb)
diff --git a/test/testing.sh b/test/testing.sh
index f56f2aa9..cb10441c 100755
--- a/test/testing.sh
+++ b/test/testing.sh
@@ -363,7 +363,6 @@ fail_unpack_noarg() { $luarocks unpack; }
363fail_upload_noarg() { $luarocks upload; } 363fail_upload_noarg() { $luarocks upload; }
364fail_remove_noarg() { $luarocks remove; } 364fail_remove_noarg() { $luarocks remove; }
365fail_doc_noarg() { $luarocks doc; } 365fail_doc_noarg() { $luarocks doc; }
366fail_new_version_noarg() { $luarocks new_version; }
367 366
368fail_build_invalid() { $luarocks build invalid; } 367fail_build_invalid() { $luarocks build invalid; }
369fail_download_invalid() { $luarocks download invalid; } 368fail_download_invalid() { $luarocks download invalid; }
@@ -446,6 +445,7 @@ test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks downlo
446test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } 445test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; }
447test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; } 446test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; }
448test_new_version_tag() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec --tag v0.3 && rm ./luacov-0.3-1.rockspec; } 447test_new_version_tag() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec --tag v0.3 && rm ./luacov-0.3-1.rockspec; }
448test_new_version_tag_without_arg() { rm -rf ./*rockspec && $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version --tag v0.3 && rm ./luacov-0.3-1.rockspec; }
449 449
450test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; } 450test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; }
451test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; } 451test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; }