diff options
author | mpeterv <mpeterval@gmail.com> | 2016-03-17 20:59:10 +0300 |
---|---|---|
committer | mpeterv <mpeterval@gmail.com> | 2016-03-17 20:59:10 +0300 |
commit | 6b749bf2300e2ebdea3ef5c3ed171c397e00c98e (patch) | |
tree | 70a73d7254a92059c49b49462a83347c05181122 /src | |
parent | c2d4f3f467f5220ccb45f1f7da4e170af31c869c (diff) | |
download | luarocks-6b749bf2300e2ebdea3ef5c3ed171c397e00c98e.tar.gz luarocks-6b749bf2300e2ebdea3ef5c3ed171c397e00c98e.tar.bz2 luarocks-6b749bf2300e2ebdea3ef5c3ed171c397e00c98e.zip |
Implement magical rockspec picking for "luarocks make"
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/make.lua | 67 |
1 files changed, 58 insertions, 9 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") |