diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2016-03-17 16:16:31 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2016-03-17 16:16:31 -0300 |
commit | 36a8d977dd2eb5d15aa4635d779b44d820f60790 (patch) | |
tree | 70a73d7254a92059c49b49462a83347c05181122 | |
parent | c2d4f3f467f5220ccb45f1f7da4e170af31c869c (diff) | |
parent | 6b749bf2300e2ebdea3ef5c3ed171c397e00c98e (diff) | |
download | luarocks-36a8d977dd2eb5d15aa4635d779b44d820f60790.tar.gz luarocks-36a8d977dd2eb5d15aa4635d779b44d820f60790.tar.bz2 luarocks-36a8d977dd2eb5d15aa4635d779b44d820f60790.zip |
Merge pull request #521 from mpeterv/make-magic
Implement magical rockspec picking for "luarocks make"
-rw-r--r-- | src/luarocks/make.lua | 67 | ||||
-rwxr-xr-x | test/testing.sh | 6 |
2 files changed, 62 insertions, 11 deletions
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 4f70bafe..94cf4414 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
@@ -9,6 +9,8 @@ package.loaded["luarocks.make"] = make | |||
9 | 9 | ||
10 | local build = require("luarocks.build") | 10 | local build = require("luarocks.build") |
11 | local fs = require("luarocks.fs") | 11 | local fs = require("luarocks.fs") |
12 | local dir = require("luarocks.dir") | ||
13 | local path = require("luarocks.path") | ||
12 | local util = require("luarocks.util") | 14 | local util = require("luarocks.util") |
13 | local cfg = require("luarocks.cfg") | 15 | local cfg = require("luarocks.cfg") |
14 | local fetch = require("luarocks.fetch") | 16 | local fetch = require("luarocks.fetch") |
@@ -22,8 +24,11 @@ make.help = [[ | |||
22 | Builds sources in the current directory, but unlike "build", | 24 | Builds sources in the current directory, but unlike "build", |
23 | it does not fetch sources, etc., assuming everything is | 25 | it does not fetch sources, etc., assuming everything is |
24 | available in the current directory. If no argument is given, | 26 | available in the current directory. If no argument is given, |
25 | look for a rockspec in the current directory. If more than one | 27 | it looks for a rockspec in the current directory and in "rockspec/" |
26 | is found, you must specify which to use, through the command-line. | 28 | and "rockspecs/" subdirectories, picking the rockspec with newest version |
29 | or without version name. If rockspecs for different rocks are found | ||
30 | or there are several rockspecs without version, you must specify which to use, | ||
31 | through the command-line. | ||
27 | 32 | ||
28 | This command is useful as a tool for debugging rockspecs. | 33 | This command is useful as a tool for debugging rockspecs. |
29 | To install rocks, you'll normally want to use the "install" and | 34 | To install rocks, you'll normally want to use the "install" and |
@@ -44,6 +49,33 @@ To install rocks, you'll normally want to use the "install" and | |||
44 | 49 | ||
45 | ]] | 50 | ]] |
46 | 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 | |||
47 | --- Driver function for "make" command. | 79 | --- Driver function for "make" command. |
48 | -- @param name string: A local rockspec. | 80 | -- @param name string: A local rockspec. |
49 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an | 81 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an |
@@ -53,18 +85,35 @@ function make.run(...) | |||
53 | assert(type(rockspec) == "string" or not rockspec) | 85 | assert(type(rockspec) == "string" or not rockspec) |
54 | 86 | ||
55 | if not rockspec then | 87 | if not rockspec then |
56 | for file in fs.dir() do | 88 | -- Try to infer default rockspec name. |
57 | if file:match("rockspec$") and fs.is_file(file) then | 89 | local versions, paths, unnamed_paths = {}, {}, {} |
58 | if rockspec then | 90 | -- Look for rockspecs in some common locations. |
91 | collect_rockspecs(versions, paths, unnamed_paths, ".") | ||
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 | ||
59 | return nil, "Please specify which rockspec file to use." | 109 | return nil, "Please specify which rockspec file to use." |
60 | else | 110 | else |
61 | rockspec = file | 111 | rockspec = paths[rock] |
62 | end | 112 | end |
113 | else | ||
114 | return nil, "Argument missing: please specify a rockspec to use on current directory." | ||
63 | end | 115 | end |
64 | end | 116 | end |
65 | if not rockspec then | ||
66 | return nil, "Argument missing: please specify a rockspec to use on current directory." | ||
67 | end | ||
68 | end | 117 | end |
69 | if not rockspec:match("rockspec$") then | 118 | if not rockspec:match("rockspec$") then |
70 | return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make") | 119 | return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make") |
diff --git a/test/testing.sh b/test/testing.sh index 74b39b8f..4be71fa6 100755 --- a/test/testing.sh +++ b/test/testing.sh | |||
@@ -421,9 +421,11 @@ test_list() { $luarocks list; } | |||
421 | test_list_porcelain() { $luarocks list --porcelain; } | 421 | test_list_porcelain() { $luarocks list --porcelain; } |
422 | 422 | ||
423 | test_make_with_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make luasocket-${verrev_luasocket}.rockspec && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; } | 423 | test_make_with_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make luasocket-${verrev_luasocket}.rockspec && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; } |
424 | test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | 424 | test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks new_version lxsh-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } |
425 | test_make_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | ||
426 | fail_make_ambiguous_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec lxsh2-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | ||
427 | fail_make_ambiguous_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && mv lxsh-${verrev_lxsh}.rockspec 1_rockspec && cp 1_rockspec 2_rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | ||
425 | test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --deps-mode=none --pack-binary-rock && [ -e ./lxsh-${verrev_lxsh}.all.rock ] && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } | 428 | test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --deps-mode=none --pack-binary-rock && [ -e ./lxsh-${verrev_lxsh}.all.rock ] && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } |
426 | fail_make_which_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; } | ||
427 | 429 | ||
428 | test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } | 430 | test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } |
429 | test_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-*; } | 431 | test_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-*; } |