aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2016-03-17 16:16:31 -0300
committerHisham Muhammad <hisham@gobolinux.org>2016-03-17 16:16:31 -0300
commit36a8d977dd2eb5d15aa4635d779b44d820f60790 (patch)
tree70a73d7254a92059c49b49462a83347c05181122
parentc2d4f3f467f5220ccb45f1f7da4e170af31c869c (diff)
parent6b749bf2300e2ebdea3ef5c3ed171c397e00c98e (diff)
downloadluarocks-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.lua67
-rwxr-xr-xtest/testing.sh6
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
10local build = require("luarocks.build") 10local build = require("luarocks.build")
11local fs = require("luarocks.fs") 11local fs = require("luarocks.fs")
12local dir = require("luarocks.dir")
13local path = require("luarocks.path")
12local util = require("luarocks.util") 14local util = require("luarocks.util")
13local cfg = require("luarocks.cfg") 15local cfg = require("luarocks.cfg")
14local fetch = require("luarocks.fetch") 16local fetch = require("luarocks.fetch")
@@ -22,8 +24,11 @@ make.help = [[
22Builds sources in the current directory, but unlike "build", 24Builds sources in the current directory, but unlike "build",
23it does not fetch sources, etc., assuming everything is 25it does not fetch sources, etc., assuming everything is
24available in the current directory. If no argument is given, 26available in the current directory. If no argument is given,
25look for a rockspec in the current directory. If more than one 27it looks for a rockspec in the current directory and in "rockspec/"
26is found, you must specify which to use, through the command-line. 28and "rockspecs/" subdirectories, picking the rockspec with newest version
29or without version name. If rockspecs for different rocks are found
30or there are several rockspecs without version, you must specify which to use,
31through the command-line.
27 32
28This command is useful as a tool for debugging rockspecs. 33This command is useful as a tool for debugging rockspecs.
29To install rocks, you'll normally want to use the "install" and 34To 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.
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
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; }
421test_list_porcelain() { $luarocks list --porcelain; } 421test_list_porcelain() { $luarocks list --porcelain; }
422 422
423test_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}; } 423test_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}; }
424test_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}; } 424test_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}; }
425test_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}; }
426fail_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}; }
427fail_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}; }
425test_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}; } 428test_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}; }
426fail_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
428test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } 430test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; }
429test_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-*; } 431test_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-*; }