diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2014-01-11 13:54:13 +0100 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2014-01-11 13:54:13 +0100 |
commit | 1e0af10c6d824bcebb15d4d61da712911c20f168 (patch) | |
tree | 1bf9f695a1372731700da342521fc993f0e64424 /src | |
parent | 60323b48f917e2c7495d3899a3c4bec87cd98750 (diff) | |
parent | 17f1c5d3600fa24c670d78bc9e9931502309bf36 (diff) | |
download | luarocks-1e0af10c6d824bcebb15d4d61da712911c20f168.tar.gz luarocks-1e0af10c6d824bcebb15d4d61da712911c20f168.tar.bz2 luarocks-1e0af10c6d824bcebb15d4d61da712911c20f168.zip |
Merge branch 'master' of https://github.com/keplerproject/luarocks
Diffstat (limited to 'src')
-rwxr-xr-x | src/bin/luarocks | 36 | ||||
-rwxr-xr-x | src/bin/luarocks-admin | 11 | ||||
-rw-r--r-- | src/luarocks/build.lua | 3 | ||||
-rw-r--r-- | src/luarocks/build/builtin.lua | 3 | ||||
-rw-r--r-- | src/luarocks/cfg.lua | 3 | ||||
-rw-r--r-- | src/luarocks/command_line.lua | 3 | ||||
-rw-r--r-- | src/luarocks/deps.lua | 2 | ||||
-rw-r--r-- | src/luarocks/dir.lua | 14 | ||||
-rw-r--r-- | src/luarocks/doc.lua | 128 | ||||
-rw-r--r-- | src/luarocks/fetch.lua | 18 | ||||
-rw-r--r-- | src/luarocks/fs/unix/tools.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 4 | ||||
-rw-r--r-- | src/luarocks/help.lua | 19 | ||||
-rw-r--r-- | src/luarocks/index.lua | 11 | ||||
-rw-r--r-- | src/luarocks/install.lua | 3 | ||||
-rw-r--r-- | src/luarocks/manif.lua | 87 | ||||
-rw-r--r-- | src/luarocks/remove.lua | 3 | ||||
-rw-r--r-- | src/luarocks/search.lua | 7 | ||||
-rw-r--r-- | src/luarocks/show.lua | 34 | ||||
-rw-r--r-- | src/luarocks/util.lua | 20 | ||||
-rw-r--r-- | src/luarocks/write_rockspec.lua | 66 |
21 files changed, 359 insertions, 120 deletions
diff --git a/src/bin/luarocks b/src/bin/luarocks index 6ab27fa3..e9cfc349 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks | |||
@@ -5,22 +5,24 @@ local command_line = require("luarocks.command_line") | |||
5 | 5 | ||
6 | program_description = "LuaRocks main command-line interface" | 6 | program_description = "LuaRocks main command-line interface" |
7 | 7 | ||
8 | commands = {} | 8 | commands = { |
9 | commands.help = require("luarocks.help") | 9 | help = "luarocks.help", |
10 | commands.pack = require("luarocks.pack") | 10 | pack = "luarocks.pack", |
11 | commands.unpack = require("luarocks.unpack") | 11 | unpack = "luarocks.unpack", |
12 | commands.build = require("luarocks.build") | 12 | build = "luarocks.build", |
13 | commands.install = require("luarocks.install") | 13 | install = "luarocks.install", |
14 | commands.search = require("luarocks.search") | 14 | search = "luarocks.search", |
15 | commands.list = require("luarocks.list") | 15 | list = "luarocks.list", |
16 | commands.remove = require("luarocks.remove") | 16 | remove = "luarocks.remove", |
17 | commands.make = require("luarocks.make") | 17 | make = "luarocks.make", |
18 | commands.download = require("luarocks.download") | 18 | download = "luarocks.download", |
19 | commands.path = require("luarocks.path") | 19 | path = "luarocks.path", |
20 | commands.show = require("luarocks.show") | 20 | show = "luarocks.show", |
21 | commands.new_version = require("luarocks.new_version") | 21 | new_version = "luarocks.new_version", |
22 | commands.lint = require("luarocks.lint") | 22 | lint = "luarocks.lint", |
23 | commands.write_rockspec = require("luarocks.write_rockspec") | 23 | write_rockspec = "luarocks.write_rockspec", |
24 | commands.purge = require("luarocks.purge") | 24 | purge = "luarocks.purge", |
25 | doc = "luarocks.doc", | ||
26 | } | ||
25 | 27 | ||
26 | command_line.run_command(...) | 28 | command_line.run_command(...) |
diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index 983dda87..e7f49c25 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin | |||
@@ -6,12 +6,11 @@ local command_line = require("luarocks.command_line") | |||
6 | program_description = "LuaRocks repository administration interface" | 6 | program_description = "LuaRocks repository administration interface" |
7 | 7 | ||
8 | commands = { | 8 | commands = { |
9 | help = "luarocks.help", | ||
10 | make_manifest = "luarocks.make_manifest", | ||
11 | add = "luarocks.add", | ||
12 | remove = "luarocks.admin_remove", | ||
13 | refresh_cache = "luarocks.refresh_cache", | ||
9 | } | 14 | } |
10 | 15 | ||
11 | commands.help = require("luarocks.help") | ||
12 | commands.make_manifest = require("luarocks.make_manifest") | ||
13 | commands.add = require("luarocks.add") | ||
14 | commands.remove = require("luarocks.admin_remove") | ||
15 | commands.refresh_cache = require("luarocks.refresh_cache") | ||
16 | |||
17 | command_line.run_command(...) | 16 | command_line.run_command(...) |
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/build/builtin.lua b/src/luarocks/build/builtin.lua index f9ef4c44..5c58265a 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua | |||
@@ -235,8 +235,9 @@ function run(rockspec) | |||
235 | table.insert(objects, object) | 235 | table.insert(objects, object) |
236 | end | 236 | end |
237 | if not ok then break end | 237 | if not ok then break end |
238 | local module_name = dir.path(moddir, name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension)):gsub("//", "/") | 238 | local module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension) |
239 | if moddir ~= "" then | 239 | if moddir ~= "" then |
240 | module_name = dir.path(moddir, module_name) | ||
240 | local ok, err = fs.make_dir(moddir) | 241 | local ok, err = fs.make_dir(moddir) |
241 | if not ok then return nil, err end | 242 | if not ok then return nil, err end |
242 | end | 243 | end |
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 87777b86..5e43535b 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
@@ -342,6 +342,7 @@ if detected.windows then | |||
342 | localappdata = os.getenv("USERPROFILE").."/Local Settings/Application Data" | 342 | localappdata = os.getenv("USERPROFILE").."/Local Settings/Application Data" |
343 | end | 343 | end |
344 | defaults.local_cache = localappdata.."/LuaRocks/Cache" | 344 | defaults.local_cache = localappdata.."/LuaRocks/Cache" |
345 | defaults.web_browser = "start" | ||
345 | end | 346 | end |
346 | 347 | ||
347 | if detected.mingw32 then | 348 | if detected.mingw32 then |
@@ -403,6 +404,7 @@ if detected.unix then | |||
403 | if not defaults.variables.CFLAGS:match("-fPIC") then | 404 | if not defaults.variables.CFLAGS:match("-fPIC") then |
404 | defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" | 405 | defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" |
405 | end | 406 | end |
407 | defaults.web_browser = "xdg-open" | ||
406 | end | 408 | end |
407 | 409 | ||
408 | if detected.cygwin then | 410 | if detected.cygwin then |
@@ -436,6 +438,7 @@ if detected.macosx then | |||
436 | end | 438 | end |
437 | defaults.variables.CC = "export MACOSX_DEPLOYMENT_TARGET=10."..version.."; gcc" | 439 | defaults.variables.CC = "export MACOSX_DEPLOYMENT_TARGET=10."..version.."; gcc" |
438 | defaults.variables.LD = "export MACOSX_DEPLOYMENT_TARGET=10."..version.."; gcc" | 440 | defaults.variables.LD = "export MACOSX_DEPLOYMENT_TARGET=10."..version.."; gcc" |
441 | defaults.web_browser = "open" | ||
439 | end | 442 | end |
440 | 443 | ||
441 | if detected.linux then | 444 | if detected.linux then |
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index e79b1442..19d04290 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
@@ -185,7 +185,8 @@ function run_command(...) | |||
185 | -- I'm not changing this now to avoid messing with the run() | 185 | -- I'm not changing this now to avoid messing with the run() |
186 | -- interface, which I know some people use (even though | 186 | -- interface, which I know some people use (even though |
187 | -- I never published it as a public API...) | 187 | -- I never published it as a public API...) |
188 | local xp, ok, err, exitcode = xpcall(function() return commands[command].run(unpack(args)) end, function(err) | 188 | local cmd = require(commands[command]) |
189 | local xp, ok, err, exitcode = xpcall(function() return cmd.run(unpack(args)) end, function(err) | ||
189 | die(debug.traceback("LuaRocks "..cfg.program_version | 190 | die(debug.traceback("LuaRocks "..cfg.program_version |
190 | .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" | 191 | .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" |
191 | ..err, 2)) | 192 | ..err, 2)) |
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 116b4bbb..0adb5834 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -689,7 +689,7 @@ function scan_deps(results, missing, manifest, name, version, deps_mode) | |||
689 | local deplist = dependencies_name[version] | 689 | local deplist = dependencies_name[version] |
690 | local rockspec, err | 690 | local rockspec, err |
691 | if not deplist then | 691 | if not deplist then |
692 | rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version)) | 692 | rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version), false) |
693 | if err then | 693 | if err then |
694 | missing[name.." "..version] = err | 694 | missing[name.." "..version] = err |
695 | return results, missing | 695 | return results, missing |
diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index e8cd746e..1f3b5c3d 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua | |||
@@ -35,17 +35,11 @@ end | |||
35 | -- @return string: a string with a platform-specific representation | 35 | -- @return string: a string with a platform-specific representation |
36 | -- of the path. | 36 | -- of the path. |
37 | function path(...) | 37 | function path(...) |
38 | local items = {...} | 38 | local t = {...} |
39 | local i = 1 | 39 | while t[1] == "" do |
40 | while items[i] do | 40 | table.remove(t, 1) |
41 | items[i] = items[i]:gsub("(.+)/+$", "%1") | ||
42 | if items[i] == "" then | ||
43 | table.remove(items, i) | ||
44 | else | ||
45 | i = i + 1 | ||
46 | end | ||
47 | end | 41 | end |
48 | return (table.concat(items, "/"):gsub("(.+)/+$", "%1")) | 42 | return (table.concat(t, "/"):gsub("([^:])/+", "%1/"):gsub("^/+", "/"):gsub("/*$", "")) |
49 | end | 43 | end |
50 | 44 | ||
51 | --- Split protocol and path from an URL or local pathname. | 45 | --- Split protocol and path from an URL or local pathname. |
diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua new file mode 100644 index 00000000..1a843f37 --- /dev/null +++ b/src/luarocks/doc.lua | |||
@@ -0,0 +1,128 @@ | |||
1 | |||
2 | --- Module implementing the LuaRocks "doc" command. | ||
3 | -- Shows documentation for an installed rock. | ||
4 | module("luarocks.doc", package.seeall) | ||
5 | |||
6 | local util = require("luarocks.util") | ||
7 | local show = require("luarocks.show") | ||
8 | local path = require("luarocks.path") | ||
9 | local dir = require("luarocks.dir") | ||
10 | local fetch = require("luarocks.fetch") | ||
11 | local fs = require("luarocks.fs") | ||
12 | |||
13 | help_summary = "Shows documentation for an installed rock." | ||
14 | |||
15 | help = [[ | ||
16 | <argument> is an existing package name. | ||
17 | Without any flags, tries to load the documentation | ||
18 | using a series of heuristics. | ||
19 | With these flags, return only the desired information: | ||
20 | |||
21 | --homepage Open the home page of project. | ||
22 | --list List documentation files only. | ||
23 | |||
24 | For more information about a rock, see the 'show' command. | ||
25 | ]] | ||
26 | |||
27 | --- Driver function for "doc" command. | ||
28 | -- @param name or nil: an existing package name. | ||
29 | -- @param version string or nil: a version may also be passed. | ||
30 | -- @return boolean: True if succeeded, nil on errors. | ||
31 | function run(...) | ||
32 | local flags, name, version = util.parse_flags(...) | ||
33 | if not name then | ||
34 | return nil, "Argument missing. "..util.see_help("doc") | ||
35 | end | ||
36 | |||
37 | local repo | ||
38 | name, version, repo = show.pick_installed_rock(name, version, flags["tree"]) | ||
39 | if not name then | ||
40 | return nil, version | ||
41 | end | ||
42 | |||
43 | local rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version, repo)) | ||
44 | if not rockspec then return nil,err end | ||
45 | local descript = rockspec.description or {} | ||
46 | |||
47 | if flags["homepage"] then | ||
48 | if not descript.homepage then | ||
49 | return nil, "No 'homepage' field in rockspec for "..name.." "..version | ||
50 | end | ||
51 | util.printout("Opening "..descript.homepage.." ...") | ||
52 | fs.browser(descript.homepage) | ||
53 | return true | ||
54 | end | ||
55 | |||
56 | local directory = path.install_dir(name,version,repo) | ||
57 | |||
58 | local docdir | ||
59 | local directories = { "doc", "docs" } | ||
60 | for _, d in ipairs(directories) do | ||
61 | local dirname = dir.path(directory, d) | ||
62 | if fs.is_dir(dirname) then | ||
63 | docdir = dirname | ||
64 | break | ||
65 | end | ||
66 | end | ||
67 | if not docdir then | ||
68 | if descript.homepage and not flags["list"] then | ||
69 | util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") | ||
70 | fs.browser(descript.homepage) | ||
71 | return true | ||
72 | end | ||
73 | return nil, "Documentation directory not found for "..name.." "..version | ||
74 | end | ||
75 | |||
76 | docdir = dir.normalize(docdir):gsub("/+", "/") | ||
77 | local files = fs.find(docdir) | ||
78 | local htmlpatt = "%.html?$" | ||
79 | local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" } | ||
80 | local basenames = { "index", "readme", "manual" } | ||
81 | |||
82 | local porcelain = flags["porcelain"] | ||
83 | if #files > 0 then | ||
84 | util.title("Documentation files for "..name.." "..version, porcelain) | ||
85 | if porcelain then | ||
86 | for _, file in ipairs(files) do | ||
87 | util.printout(docdir.."/"..file) | ||
88 | end | ||
89 | else | ||
90 | util.printout(docdir.."/") | ||
91 | for _, file in ipairs(files) do | ||
92 | util.printout("\t"..file) | ||
93 | end | ||
94 | end | ||
95 | end | ||
96 | |||
97 | if flags["list"] then | ||
98 | return true | ||
99 | end | ||
100 | |||
101 | for _, extension in ipairs(extensions) do | ||
102 | for _, basename in ipairs(basenames) do | ||
103 | local filename = basename..extension | ||
104 | local found | ||
105 | for _, file in ipairs(files) do | ||
106 | if file:lower():match(filename) and ((not found) or #file < #found) then | ||
107 | found = file | ||
108 | end | ||
109 | end | ||
110 | if found then | ||
111 | local pathname = dir.path(docdir, found) | ||
112 | util.printout() | ||
113 | util.printout("Opening "..pathname.." ...") | ||
114 | util.printout() | ||
115 | local ok = fs.browser(pathname) | ||
116 | if not ok and not pathname:match(htmlpatt) then | ||
117 | local fd = io.open(pathname, "r") | ||
118 | util.printout(fd:read("*a")) | ||
119 | fd:close() | ||
120 | end | ||
121 | return true | ||
122 | end | ||
123 | end | ||
124 | end | ||
125 | |||
126 | return true | ||
127 | end | ||
128 | |||
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 53c9d748..83ab6fa9 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
@@ -137,9 +137,11 @@ end | |||
137 | --- Back-end function that actually loads the local rockspec. | 137 | --- Back-end function that actually loads the local rockspec. |
138 | -- Performs some validation and postprocessing of the rockspec contents. | 138 | -- Performs some validation and postprocessing of the rockspec contents. |
139 | -- @param filename string: The local filename of the rockspec file. | 139 | -- @param filename string: The local filename of the rockspec file. |
140 | -- @param quick boolean: if true, skips some steps when loading | ||
141 | -- rockspec. | ||
140 | -- @return table or (nil, string): A table representing the rockspec | 142 | -- @return table or (nil, string): A table representing the rockspec |
141 | -- or nil followed by an error message. | 143 | -- or nil followed by an error message. |
142 | function load_local_rockspec(filename) | 144 | function load_local_rockspec(filename, quick) |
143 | assert(type(filename) == "string") | 145 | assert(type(filename) == "string") |
144 | filename = fs.absolute_name(filename) | 146 | filename = fs.absolute_name(filename) |
145 | local rockspec, err = persist.load_into_table(filename) | 147 | local rockspec, err = persist.load_into_table(filename) |
@@ -147,9 +149,12 @@ function load_local_rockspec(filename) | |||
147 | return nil, "Could not load rockspec file "..filename.." ("..err..")" | 149 | return nil, "Could not load rockspec file "..filename.." ("..err..")" |
148 | end | 150 | end |
149 | 151 | ||
150 | local ok, err = type_check.type_check_rockspec(rockspec) | 152 | local ok, err = true, nil |
151 | if not ok then | 153 | if not quick then |
152 | return nil, filename..": "..err | 154 | ok, err = type_check.type_check_rockspec(rockspec) |
155 | if not ok then | ||
156 | return nil, filename..": "..err | ||
157 | end | ||
153 | end | 158 | end |
154 | 159 | ||
155 | if rockspec.rockspec_format then | 160 | if rockspec.rockspec_format then |
@@ -207,9 +212,8 @@ function load_local_rockspec(filename) | |||
207 | else | 212 | else |
208 | rockspec.dependencies = {} | 213 | rockspec.dependencies = {} |
209 | end | 214 | end |
210 | local ok, err = path.configure_paths(rockspec) | 215 | if not quick then |
211 | if err then | 216 | path.configure_paths(rockspec) |
212 | return nil, "Error verifying paths: "..err | ||
213 | end | 217 | end |
214 | 218 | ||
215 | return rockspec | 219 | return rockspec |
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 5495760b..7535d679 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua | |||
@@ -341,3 +341,7 @@ function get_permissions(filename) | |||
341 | pipe:close() | 341 | pipe:close() |
342 | return ret | 342 | return ret |
343 | end | 343 | end |
344 | |||
345 | function browser(url) | ||
346 | return fs.execute(cfg.web_browser, url) | ||
347 | end | ||
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 345ec682..24197f47 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -362,3 +362,7 @@ function exists(file) | |||
362 | assert(file) | 362 | assert(file) |
363 | return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname") | 363 | return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname") |
364 | end | 364 | end |
365 | |||
366 | function browser(url) | ||
367 | return fs.execute(cfg.web_browser.." "..url) | ||
368 | end | ||
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 2774dc41..2136f5da 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
@@ -71,14 +71,10 @@ function run(...) | |||
71 | can be overriden with VAR=VALUE assignments.]]) | 71 | can be overriden with VAR=VALUE assignments.]]) |
72 | print_section("COMMANDS") | 72 | print_section("COMMANDS") |
73 | local names = {} | 73 | local names = {} |
74 | for name, command in pairs(commands) do | 74 | for name, command in util.sortedpairs(commands) do |
75 | table.insert(names, name) | 75 | local cmd = require(command) |
76 | end | ||
77 | table.sort(names) | ||
78 | for _, name in ipairs(names) do | ||
79 | local command = commands[name] | ||
80 | util.printout("", name) | 76 | util.printout("", name) |
81 | util.printout("\t", command.help_summary) | 77 | util.printout("\t", cmd.help_summary) |
82 | end | 78 | end |
83 | print_section("CONFIGURATION") | 79 | print_section("CONFIGURATION") |
84 | util.printout("\tLua version: " .. cfg.lua_version) | 80 | util.printout("\tLua version: " .. cfg.lua_version) |
@@ -100,15 +96,16 @@ function run(...) | |||
100 | end | 96 | end |
101 | else | 97 | else |
102 | command = command:gsub("-", "_") | 98 | command = command:gsub("-", "_") |
103 | if commands[command] then | 99 | local cmd = require(commands[command]) |
104 | local arguments = commands[command].help_arguments or "<argument>" | 100 | if cmd then |
101 | local arguments = cmd.help_arguments or "<argument>" | ||
105 | print_banner() | 102 | print_banner() |
106 | print_section("NAME") | 103 | print_section("NAME") |
107 | util.printout("\t"..program.." "..command.." - "..commands[command].help_summary) | 104 | util.printout("\t"..program.." "..command.." - "..cmd.help_summary) |
108 | print_section("SYNOPSIS") | 105 | print_section("SYNOPSIS") |
109 | util.printout("\t"..program.." "..command.." "..arguments) | 106 | util.printout("\t"..program.." "..command.." "..arguments) |
110 | print_section("DESCRIPTION") | 107 | print_section("DESCRIPTION") |
111 | util.printout("",(commands[command].help:gsub("\n","\n\t"):gsub("\n\t$",""))) | 108 | util.printout("",(cmd.help:gsub("\n","\n\t"):gsub("\n\t$",""))) |
112 | print_section("SEE ALSO") | 109 | print_section("SEE ALSO") |
113 | util.printout("","'"..program.." help' for general options and configuration.\n") | 110 | util.printout("","'"..program.." help' for general options and configuration.\n") |
114 | else | 111 | else |
diff --git a/src/luarocks/index.lua b/src/luarocks/index.lua index e0785d9c..1ce66f70 100644 --- a/src/luarocks/index.lua +++ b/src/luarocks/index.lua | |||
@@ -139,15 +139,14 @@ function make_index(repo) | |||
139 | output = output..version..': ' | 139 | output = output..version..': ' |
140 | table.sort(data, function(a,b) return a.arch < b.arch end) | 140 | table.sort(data, function(a,b) return a.arch < b.arch end) |
141 | for _, item in ipairs(data) do | 141 | for _, item in ipairs(data) do |
142 | local link = '<a href="$url">'..item.arch..'</a>' | 142 | local file |
143 | if item.arch == 'rockspec' then | 143 | if item.arch == 'rockspec' then |
144 | local rs = ("%s-%s.rockspec"):format(package, version) | 144 | file = ("%s-%s.rockspec"):format(package, version) |
145 | if not latest_rockspec then latest_rockspec = rs end | 145 | if not latest_rockspec then latest_rockspec = file end |
146 | link = link:gsub("$url", rs) | ||
147 | else | 146 | else |
148 | link = link:gsub("$url", ("%s-%s.%s.rock"):format(package, version, item.arch)) | 147 | file = ("%s-%s.%s.rock"):format(package, version, item.arch) |
149 | end | 148 | end |
150 | table.insert(versions, link) | 149 | table.insert(versions, '<a href="'..file..'">'..item.arch..'</a>') |
151 | end | 150 | end |
152 | output = output .. table.concat(versions, ', ') .. '<br/>' | 151 | output = output .. table.concat(versions, ', ') .. '<br/>' |
153 | end | 152 | end |
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/manif.lua b/src/luarocks/manif.lua index 238c4056..3fb3e4e3 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
@@ -141,12 +141,18 @@ function load_manifest(repo_url) | |||
141 | end | 141 | end |
142 | end | 142 | end |
143 | if pathname:match(".*%.zip$") then | 143 | if pathname:match(".*%.zip$") then |
144 | pathname = fs.absolute_name(pathname) | ||
144 | local dir = dir.dir_name(pathname) | 145 | local dir = dir.dir_name(pathname) |
145 | fs.change_dir(dir) | 146 | fs.change_dir(dir) |
146 | local nozip = pathname:match("(.*)%.zip$") | 147 | local nozip = pathname:match("(.*)%.zip$") |
147 | fs.delete(nozip) | 148 | fs.delete(nozip) |
148 | fs.unzip(pathname) | 149 | local ok = fs.unzip(pathname) |
149 | fs.pop_dir() | 150 | fs.pop_dir() |
151 | if not ok then | ||
152 | fs.delete(pathname) | ||
153 | fs.delete(pathname..".timestamp") | ||
154 | return nil, "Failed extracting manifest file" | ||
155 | end | ||
150 | pathname = nozip | 156 | pathname = nozip |
151 | end | 157 | end |
152 | return manif_core.manifest_loader(pathname, repo_url) | 158 | return manif_core.manifest_loader(pathname, repo_url) |
@@ -231,18 +237,11 @@ end | |||
231 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 237 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, |
232 | -- "all" for all trees, "order" for all trees with priority >= the current default, | 238 | -- "all" for all trees, "order" for all trees with priority >= the current default, |
233 | -- "none" for no trees. | 239 | -- "none" for no trees. |
234 | -- @param repodir string: directory of repository being scanned | 240 | local function update_dependencies(manifest, deps_mode) |
235 | -- @param filter_lua string or nil: filter by Lua version | ||
236 | -- @param cache table: temporary rockspec cache table | ||
237 | local function update_dependencies(manifest, deps_mode, repodir, filter_lua, cache) | ||
238 | assert(type(manifest) == "table") | 241 | assert(type(manifest) == "table") |
239 | assert(type(deps_mode) == "string") | 242 | assert(type(deps_mode) == "string") |
240 | 243 | ||
241 | cache = cache or {} | ||
242 | local lua_version = filter_lua and deps.parse_version(filter_lua) | ||
243 | |||
244 | for pkg, versions in pairs(manifest.repository) do | 244 | for pkg, versions in pairs(manifest.repository) do |
245 | local to_remove = {} | ||
246 | for version, repositories in pairs(versions) do | 245 | for version, repositories in pairs(versions) do |
247 | local current = pkg.." "..version | 246 | local current = pkg.." "..version |
248 | for _, repo in ipairs(repositories) do | 247 | for _, repo in ipairs(repositories) do |
@@ -259,11 +258,34 @@ local function update_dependencies(manifest, deps_mode, repodir, filter_lua, cac | |||
259 | end | 258 | end |
260 | end | 259 | end |
261 | end | 260 | end |
262 | elseif filter_lua and repo.arch == "rockspec" then | 261 | end |
262 | end | ||
263 | end | ||
264 | end | ||
265 | end | ||
266 | |||
267 | --- Filter manifest table by Lua version, removing rockspecs whose Lua version | ||
268 | -- does not match. | ||
269 | -- @param manifest table: a manifest table. | ||
270 | -- @param lua_version string or nil: filter by Lua version | ||
271 | -- @param repodir string: directory of repository being scanned | ||
272 | -- @param cache table: temporary rockspec cache table | ||
273 | local function filter_by_lua_version(manifest, lua_version, repodir, cache) | ||
274 | assert(type(manifest) == "table") | ||
275 | assert(type(repodir) == "string") | ||
276 | assert((not cache) or type(cache) == "table") | ||
277 | |||
278 | cache = cache or {} | ||
279 | lua_version = deps.parse_version(lua_version) | ||
280 | for pkg, versions in pairs(manifest.repository) do | ||
281 | local to_remove = {} | ||
282 | for version, repositories in pairs(versions) do | ||
283 | for _, repo in ipairs(repositories) do | ||
284 | if repo.arch == "rockspec" then | ||
263 | local pathname = dir.path(repodir, pkg.."-"..version..".rockspec") | 285 | local pathname = dir.path(repodir, pkg.."-"..version..".rockspec") |
264 | local rockspec, err = cache[pathname] | 286 | local rockspec, err = cache[pathname] |
265 | if not rockspec then | 287 | if not rockspec then |
266 | rockspec, err = fetch.load_local_rockspec(pathname) | 288 | rockspec, err = fetch.load_local_rockspec(pathname, true) |
267 | end | 289 | end |
268 | if rockspec then | 290 | if rockspec then |
269 | cache[pathname] = rockspec | 291 | cache[pathname] = rockspec |
@@ -283,9 +305,9 @@ local function update_dependencies(manifest, deps_mode, repodir, filter_lua, cac | |||
283 | end | 305 | end |
284 | if next(to_remove) then | 306 | if next(to_remove) then |
285 | for _, incompat in ipairs(to_remove) do | 307 | for _, incompat in ipairs(to_remove) do |
286 | manifest.repository[pkg][incompat] = nil | 308 | versions[incompat] = nil |
287 | end | 309 | end |
288 | if not next(manifest.repository[pkg]) then | 310 | if not next(versions) then |
289 | manifest.repository[pkg] = nil | 311 | manifest.repository[pkg] = nil |
290 | end | 312 | end |
291 | end | 313 | end |
@@ -296,17 +318,12 @@ end | |||
296 | -- @param results table: The search results as returned by search.disk_search. | 318 | -- @param results table: The search results as returned by search.disk_search. |
297 | -- @param manifest table: A manifest table (must contain repository, modules, commands tables). | 319 | -- @param manifest table: A manifest table (must contain repository, modules, commands tables). |
298 | -- It will be altered to include the search results. | 320 | -- It will be altered to include the search results. |
299 | -- @param deps_mode string: Dependency mode: "one" for the current default tree, | 321 | -- @param dep_handler: dependency handler function |
300 | -- "all" for all trees, "order" for all trees with priority >= the current default, | ||
301 | -- "none" for no trees. | ||
302 | -- @param repo string: directory of repository | ||
303 | -- @param filter_lua string or nil: filter by Lua version | ||
304 | -- @param cache table: temporary rockspec cache table | ||
305 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. | 322 | -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. |
306 | local function store_results(results, manifest, deps_mode, repo, filter_lua, cache) | 323 | local function store_results(results, manifest, dep_handler) |
307 | assert(type(results) == "table") | 324 | assert(type(results) == "table") |
308 | assert(type(manifest) == "table") | 325 | assert(type(manifest) == "table") |
309 | assert(type(deps_mode) == "string") | 326 | assert((not dep_handler) or type(dep_handler) == "function") |
310 | 327 | ||
311 | for name, versions in pairs(results) do | 328 | for name, versions in pairs(results) do |
312 | local pkgtable = manifest.repository[name] or {} | 329 | local pkgtable = manifest.repository[name] or {} |
@@ -329,7 +346,9 @@ local function store_results(results, manifest, deps_mode, repo, filter_lua, cac | |||
329 | end | 346 | end |
330 | manifest.repository[name] = pkgtable | 347 | manifest.repository[name] = pkgtable |
331 | end | 348 | end |
332 | update_dependencies(manifest, deps_mode, repo, filter_lua, cache) | 349 | if dep_handler then |
350 | dep_handler(manifest) | ||
351 | end | ||
333 | sort_package_matching_table(manifest.modules) | 352 | sort_package_matching_table(manifest.modules) |
334 | sort_package_matching_table(manifest.commands) | 353 | sort_package_matching_table(manifest.commands) |
335 | return true | 354 | return true |
@@ -345,7 +364,7 @@ end | |||
345 | -- @param versioned boolean: if versioned versions of the manifest should be created. | 364 | -- @param versioned boolean: if versioned versions of the manifest should be created. |
346 | -- @return boolean or (nil, string): True if manifest was generated, | 365 | -- @return boolean or (nil, string): True if manifest was generated, |
347 | -- or nil and an error message. | 366 | -- or nil and an error message. |
348 | function make_manifest(repo, deps_mode, versioned) | 367 | function make_manifest(repo, deps_mode, remote) |
349 | assert(type(repo) == "string") | 368 | assert(type(repo) == "string") |
350 | assert(type(deps_mode) == "string") | 369 | assert(type(deps_mode) == "string") |
351 | 370 | ||
@@ -363,14 +382,23 @@ function make_manifest(repo, deps_mode, versioned) | |||
363 | 382 | ||
364 | manif_core.manifest_cache[repo] = manifest | 383 | manif_core.manifest_cache[repo] = manifest |
365 | 384 | ||
366 | local cache = {} | 385 | local dep_handler = nil |
367 | local ok, err = store_results(results, manifest, deps_mode, repo, nil, cache) | 386 | if not remote then |
387 | dep_handler = function(manifest) | ||
388 | update_dependencies(manifest, deps_mode) | ||
389 | end | ||
390 | end | ||
391 | local ok, err = store_results(results, manifest, dep_handler) | ||
368 | if not ok then return nil, err end | 392 | if not ok then return nil, err end |
369 | 393 | ||
370 | if versioned then | 394 | if remote then |
395 | local cache = {} | ||
371 | for luaver in util.lua_versions() do | 396 | for luaver in util.lua_versions() do |
372 | local vmanifest = { repository = {}, modules = {}, commands = {} } | 397 | local vmanifest = { repository = {}, modules = {}, commands = {} } |
373 | local ok, err = store_results(results, vmanifest, deps_mode, repo, luaver, cache) | 398 | local dep_handler = function(manifest) |
399 | filter_by_lua_version(manifest, luaver, repo, cache) | ||
400 | end | ||
401 | local ok, err = store_results(results, vmanifest, dep_handler) | ||
374 | save_table(repo, "manifest-"..luaver, vmanifest) | 402 | save_table(repo, "manifest-"..luaver, vmanifest) |
375 | end | 403 | end |
376 | end | 404 | end |
@@ -416,7 +444,10 @@ function update_manifest(name, version, repo, deps_mode) | |||
416 | 444 | ||
417 | local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} | 445 | local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} |
418 | 446 | ||
419 | local ok, err = store_results(results, manifest, deps_mode, repo) | 447 | local dep_handler = function(manifest) |
448 | update_dependencies(manifest, deps_mode) | ||
449 | end | ||
450 | local ok, err = store_results(results, manifest, dep_handler) | ||
420 | if not ok then return nil, err end | 451 | if not ok then return nil, err end |
421 | 452 | ||
422 | return save_table(repo, "manifest", manifest) | 453 | return save_table(repo, "manifest", manifest) |
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/search.lua b/src/luarocks/search.lua index 76ea6815..ad205d6a 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -139,14 +139,15 @@ function disk_search(repo, query, results) | |||
139 | for _, name in pairs(fs.list_dir(repo)) do | 139 | for _, name in pairs(fs.list_dir(repo)) do |
140 | local pathname = dir.path(repo, name) | 140 | local pathname = dir.path(repo, name) |
141 | local rname, rversion, rarch = path.parse_name(name) | 141 | local rname, rversion, rarch = path.parse_name(name) |
142 | if fs.is_dir(pathname) then | 142 | |
143 | if rname and (pathname:match(".rockspec$") or pathname:match(".rock$")) then | ||
144 | store_if_match(results, repo, rname, rversion, rarch, query) | ||
145 | elseif fs.is_dir(pathname) then | ||
143 | for _, version in pairs(fs.list_dir(pathname)) do | 146 | for _, version in pairs(fs.list_dir(pathname)) do |
144 | if version:match("-%d+$") then | 147 | if version:match("-%d+$") then |
145 | store_if_match(results, repo, name, version, "installed", query) | 148 | store_if_match(results, repo, name, version, "installed", query) |
146 | end | 149 | end |
147 | end | 150 | end |
148 | elseif rname then | ||
149 | store_if_match(results, repo, rname, rversion, rarch, query) | ||
150 | end | 151 | end |
151 | end | 152 | end |
152 | return results | 153 | return results |
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 536085a7..2e039dd4 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua | |||
@@ -66,22 +66,14 @@ local function module_name(mod, filename, name, version, repo, manifest) | |||
66 | return dir.path(base_dir, filename) | 66 | return dir.path(base_dir, filename) |
67 | end | 67 | end |
68 | 68 | ||
69 | --- Driver function for "show" command. | 69 | function pick_installed_rock(name, version, tree) |
70 | -- @param name or nil: an existing package name. | ||
71 | -- @param version string or nil: a version may also be passed. | ||
72 | -- @return boolean: True if succeeded, nil on errors. | ||
73 | function run(...) | ||
74 | local flags, name, version = util.parse_flags(...) | ||
75 | if not name then | ||
76 | return nil, "Argument missing. "..util.see_help("show") | ||
77 | end | ||
78 | local results = {} | 70 | local results = {} |
79 | local query = search.make_query(name, version) | 71 | local query = search.make_query(name, version) |
80 | query.exact_name = true | 72 | query.exact_name = true |
81 | local tree_map = {} | 73 | local tree_map = {} |
82 | local trees = cfg.rocks_trees | 74 | local trees = cfg.rocks_trees |
83 | if flags["tree"] then | 75 | if tree then |
84 | trees = { flags["tree"] } | 76 | trees = { tree } |
85 | end | 77 | end |
86 | for _, tree in ipairs(trees) do | 78 | for _, tree in ipairs(trees) do |
87 | local rocks_dir = path.rocks_dir(tree) | 79 | local rocks_dir = path.rocks_dir(tree) |
@@ -103,8 +95,26 @@ function run(...) | |||
103 | for _, rp in ipairs(repositories) do repo_url = rp.repo end | 95 | for _, rp in ipairs(repositories) do repo_url = rp.repo end |
104 | end | 96 | end |
105 | 97 | ||
106 | |||
107 | local repo = tree_map[repo_url] | 98 | local repo = tree_map[repo_url] |
99 | return name, version, repo, repo_url | ||
100 | end | ||
101 | |||
102 | --- Driver function for "show" command. | ||
103 | -- @param name or nil: an existing package name. | ||
104 | -- @param version string or nil: a version may also be passed. | ||
105 | -- @return boolean: True if succeeded, nil on errors. | ||
106 | function run(...) | ||
107 | local flags, name, version = util.parse_flags(...) | ||
108 | if not name then | ||
109 | return nil, "Argument missing. "..util.see_help("show") | ||
110 | end | ||
111 | |||
112 | local repo, repo_url | ||
113 | name, version, repo, repo_url = pick_installed_rock(name, version, flags["tree"]) | ||
114 | if not name then | ||
115 | return nil, version | ||
116 | end | ||
117 | |||
108 | local directory = path.install_dir(name,version,repo) | 118 | local directory = path.install_dir(name,version,repo) |
109 | local rockspec_file = path.rockspec_file(name, version, repo) | 119 | local rockspec_file = path.rockspec_file(name, version, repo) |
110 | local rockspec, err = fetch.load_local_rockspec(rockspec_file) | 120 | local rockspec, err = fetch.load_local_rockspec(rockspec_file) |
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 | ||