diff options
-rw-r--r-- | src/luarocks/build.lua | 3 | ||||
-rw-r--r-- | src/luarocks/install.lua | 3 | ||||
-rw-r--r-- | src/luarocks/remove.lua | 3 | ||||
-rw-r--r-- | src/luarocks/util.lua | 20 | ||||
-rw-r--r-- | src/luarocks/write_rockspec.lua | 66 |
5 files changed, 78 insertions, 17 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index ec269023..72b5649e 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -31,7 +31,8 @@ or the name of a rock to be fetched from a repository. | |||
31 | rock after building a new one. This behavior can | 31 | rock after building a new one. This behavior can |
32 | be made permanent by setting keep_other_versions=true | 32 | be made permanent by setting keep_other_versions=true |
33 | in the configuration file. | 33 | in the configuration file. |
34 | ]] | 34 | |
35 | ]]..util.deps_mode_help() | ||
35 | 36 | ||
36 | --- Install files to a given location. | 37 | --- Install files to a given location. |
37 | -- Takes a table where the array part is a list of filenames to be copied. | 38 | -- Takes a table where the array part is a list of filenames to be copied. |
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index b28e6282..7458ec8e 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua | |||
@@ -25,7 +25,8 @@ or a filename of a locally available rock. | |||
25 | rock after installing a new one. This behavior can | 25 | rock after installing a new one. This behavior can |
26 | be made permanent by setting keep_other_versions=true | 26 | be made permanent by setting keep_other_versions=true |
27 | in the configuration file. | 27 | in the configuration file. |
28 | ]] | 28 | ]]..util.deps_mode_help() |
29 | |||
29 | 30 | ||
30 | --- Install a binary rock. | 31 | --- Install a binary rock. |
31 | -- @param rock_file string: local or remote filename of a rock. | 32 | -- @param rock_file string: local or remote filename of a rock. |
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index f2f6997b..8f751a93 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua | |||
@@ -22,7 +22,8 @@ Will only perform the removal if it does not break dependencies. | |||
22 | To override this check and force the removal, use --force. | 22 | To override this check and force the removal, use --force. |
23 | To perform a forced removal without reporting dependency issues, | 23 | To perform a forced removal without reporting dependency issues, |
24 | use --force=fast. | 24 | use --force=fast. |
25 | ]] | 25 | |
26 | ]]..util.deps_mode_help() | ||
26 | 27 | ||
27 | --- Obtain a list of packages that depend on the given set of packages | 28 | --- Obtain a list of packages that depend on the given set of packages |
28 | -- (where all packages of the set are versions of one program). | 29 | -- (where all packages of the set are versions of one program). |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 1a60fd9c..4b138516 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
@@ -8,6 +8,8 @@ local global_env = _G | |||
8 | 8 | ||
9 | module("luarocks.util", package.seeall) | 9 | module("luarocks.util", package.seeall) |
10 | 10 | ||
11 | local cfg = require("luarocks.cfg") | ||
12 | |||
11 | local scheduled_functions = {} | 13 | local scheduled_functions = {} |
12 | local debug = require("debug") | 14 | local debug = require("debug") |
13 | 15 | ||
@@ -371,6 +373,24 @@ function this_program(default) | |||
371 | return last:sub(2) | 373 | return last:sub(2) |
372 | end | 374 | end |
373 | 375 | ||
376 | function deps_mode_help(program) | ||
377 | return [[ | ||
378 | --deps-mode=<mode> How to handle dependencies. Four modes are supported: | ||
379 | * all - use all trees from the rocks_trees list | ||
380 | for finding dependencies | ||
381 | * one - use only the current tree (possibly set | ||
382 | with --tree) | ||
383 | * order - use trees based on order (use the current | ||
384 | tree and all trees below it on the rocks_trees list) | ||
385 | * none - ignore dependencies altogether. | ||
386 | The default mode may be set with the deps_mode entry | ||
387 | in the configuration file. | ||
388 | The current default is "]]..cfg.deps_mode..[[". | ||
389 | Type ']]..this_program(program or "luarocks")..[[' with no arguments to see | ||
390 | your list of rocks trees. | ||
391 | ]] | ||
392 | end | ||
393 | |||
374 | function see_help(command, program) | 394 | function see_help(command, program) |
375 | return "See '"..this_program(program or "luarocks")..' help '..command.."'." | 395 | return "See '"..this_program(program or "luarocks")..' help '..command.."'." |
376 | end | 396 | end |
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index f8035b8d..a27f0b63 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua | |||
@@ -31,10 +31,14 @@ rockspec, and is not guaranteed to be complete or correct. | |||
31 | --homepage=<url> Project homepage. | 31 | --homepage=<url> Project homepage. |
32 | --lua-version=<ver> Supported Lua versions. Accepted values are "5.1", "5.2" | 32 | --lua-version=<ver> Supported Lua versions. Accepted values are "5.1", "5.2" |
33 | or "5.1,5.2". | 33 | or "5.1,5.2". |
34 | --tag=<tag> Tag to use. Will attempt to extract version number from it. | ||
34 | --lib=<lib>[,<lib>] A comma-separated list of libraries that C files need to | 35 | --lib=<lib>[,<lib>] A comma-separated list of libraries that C files need to |
35 | link to. | 36 | link to. |
36 | ]] | 37 | ]] |
37 | 38 | ||
39 | local function open_file(name) | ||
40 | return io.open(dir.path(fs.current_dir(), name), "r") | ||
41 | end | ||
38 | 42 | ||
39 | local function get_url(rockspec) | 43 | local function get_url(rockspec) |
40 | local url = rockspec.source.url | 44 | local url = rockspec.source.url |
@@ -79,12 +83,11 @@ local function configure_lua_version(rockspec, luaver) | |||
79 | end | 83 | end |
80 | 84 | ||
81 | local function detect_description(rockspec) | 85 | local function detect_description(rockspec) |
82 | local fd = io.open("README.md", "r") | 86 | local fd = open_file("README.md") or open_file("README") |
83 | if not fd then fd = io.open("README", "r") end | ||
84 | if not fd then return end | 87 | if not fd then return end |
85 | local data = fd:read("*a") | 88 | local data = fd:read("*a") |
86 | fd:close() | 89 | fd:close() |
87 | local paragraph = data:match("\n\n(.-)\n\n") | 90 | local paragraph = data:match("\n\n([^%[].-)\n\n") |
88 | if not paragraph then paragraph = data:match("\n\n(.*)") end | 91 | if not paragraph then paragraph = data:match("\n\n(.*)") end |
89 | if paragraph then | 92 | if paragraph then |
90 | if #paragraph < 80 then | 93 | if #paragraph < 80 then |
@@ -100,19 +103,32 @@ local function detect_description(rockspec) | |||
100 | end | 103 | end |
101 | end | 104 | end |
102 | 105 | ||
106 | local function detect_mit_license(data) | ||
107 | local strip_copyright = (data:gsub("Copyright [^\n]*\n", "")) | ||
108 | local sum = 0 | ||
109 | for i = 1, #strip_copyright do | ||
110 | local num = string.byte(strip_copyright:sub(i,i)) | ||
111 | if num > 32 and num <= 128 then | ||
112 | sum = sum + num | ||
113 | end | ||
114 | end | ||
115 | return sum == 78656 | ||
116 | end | ||
117 | |||
103 | local function show_license(rockspec) | 118 | local function show_license(rockspec) |
104 | local fd = io.open("COPYING", "r") | 119 | local fd = open_file("COPYING") or open_file("LICENSE") or open_file("MIT-LICENSE.txt") |
105 | if not fd then fd = io.open("LICENSE", "r") end | 120 | if not fd then return nil end |
106 | if not fd then return end | ||
107 | local data = fd:read("*a") | 121 | local data = fd:read("*a") |
108 | fd:close() | 122 | fd:close() |
123 | local is_mit = detect_mit_license(data) | ||
109 | util.title("License for "..rockspec.package..":") | 124 | util.title("License for "..rockspec.package..":") |
110 | util.printout(data) | 125 | util.printout(data) |
111 | util.printout() | 126 | util.printout() |
127 | return is_mit | ||
112 | end | 128 | end |
113 | 129 | ||
114 | local function get_cmod_name(file) | 130 | local function get_cmod_name(file) |
115 | local fd = io.open(file, "r") | 131 | local fd = open_file(file) |
116 | if not fd then return nil end | 132 | if not fd then return nil end |
117 | local data = fd:read("*a") | 133 | local data = fd:read("*a") |
118 | fd:close() | 134 | fd:close() |
@@ -199,22 +215,35 @@ function run(...) | |||
199 | elseif not url_or_dir then | 215 | elseif not url_or_dir then |
200 | url_or_dir = version | 216 | url_or_dir = version |
201 | end | 217 | end |
218 | |||
219 | if flags["tag"] == true then | ||
220 | return nil, "Incorrect usage: --tag requires an argument. "..util.see_help("write_rockspec") | ||
221 | end | ||
222 | |||
223 | if flags["tag"] then | ||
224 | if not version then | ||
225 | version = flags["tag"]:gsub("^v", "") | ||
226 | end | ||
227 | end | ||
202 | 228 | ||
203 | local protocol, pathname = dir.split_url(url_or_dir) | 229 | local protocol, pathname = dir.split_url(url_or_dir) |
204 | if not fetch.is_basic_protocol(protocol) then | 230 | if not fetch.is_basic_protocol(protocol) then |
205 | version = "scm" | ||
206 | if not name then | 231 | if not name then |
207 | name = dir.base_name(url_or_dir):gsub("%.[^.]+$", "") | 232 | name = dir.base_name(url_or_dir):gsub("%.[^.]+$", "") |
208 | end | 233 | end |
234 | if not version then | ||
235 | version = "scm" | ||
236 | end | ||
209 | elseif protocol ~= "file" then | 237 | elseif protocol ~= "file" then |
210 | local filename = dir.base_name(url_or_dir) | 238 | local filename = dir.base_name(url_or_dir) |
211 | local newname, newversion = filename:match("(.*)-([^-]+)") | 239 | local newname, newversion = filename:match("(.*)-([^-]+)") |
212 | if not name then | 240 | if (not name) and newname then |
213 | name = newname | 241 | name = newname |
214 | end | 242 | end |
215 | if newversion then | 243 | if (not version) and newversion then |
216 | version = newversion:gsub(".[a-z]+$", ""):gsub(".tar$", "") | 244 | version = newversion:gsub(".[a-z]+$", ""):gsub(".tar$", "") |
217 | else | 245 | end |
246 | if not (name and version) then | ||
218 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") | 247 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") |
219 | end | 248 | end |
220 | elseif not version then | 249 | elseif not version then |
@@ -222,13 +251,18 @@ function run(...) | |||
222 | end | 251 | end |
223 | 252 | ||
224 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") | 253 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") |
254 | |||
255 | if not flags["homepage"] and url_or_dir:match("^git://github.com") then | ||
256 | flags["homepage"] = "http://"..url_or_dir:match("^[^:]+://(.*)") | ||
257 | end | ||
225 | 258 | ||
226 | local rockspec = { | 259 | local rockspec = { |
227 | package = name, | 260 | package = name, |
228 | name = name:lower(), | 261 | name = name:lower(), |
229 | version = version.."-1", | 262 | version = version.."-1", |
230 | source = { | 263 | source = { |
231 | url = "*** please add URL for source tarball, zip or repository here ***" | 264 | url = "*** please add URL for source tarball, zip or repository here ***", |
265 | tag = flags["tag"], | ||
232 | }, | 266 | }, |
233 | description = { | 267 | description = { |
234 | summary = flags["summary"] or "*** please specify description summary ***", | 268 | summary = flags["summary"] or "*** please specify description summary ***", |
@@ -252,7 +286,7 @@ function run(...) | |||
252 | rockspec.source.dir = "dummy" | 286 | rockspec.source.dir = "dummy" |
253 | if not fetch.is_basic_protocol(rockspec.source.protocol) then | 287 | if not fetch.is_basic_protocol(rockspec.source.protocol) then |
254 | if version ~= "scm" then | 288 | if version ~= "scm" then |
255 | rockspec.source.tag = "v" .. version | 289 | rockspec.source.tag = flags["tag"] or "v" .. version |
256 | end | 290 | end |
257 | end | 291 | end |
258 | rockspec.source.dir = nil | 292 | rockspec.source.dir = nil |
@@ -290,7 +324,11 @@ function run(...) | |||
290 | 324 | ||
291 | detect_description(rockspec) | 325 | detect_description(rockspec) |
292 | 326 | ||
293 | show_license(rockspec) | 327 | local is_mit = show_license(rockspec) |
328 | |||
329 | if is_mit and not flags["license"] then | ||
330 | rockspec.description.license = "MIT" | ||
331 | end | ||
294 | 332 | ||
295 | fill_as_builtin(rockspec, libs) | 333 | fill_as_builtin(rockspec, libs) |
296 | 334 | ||