aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-19 00:24:30 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-19 00:24:30 +0300
commit18e288d091709957e34de8177179a86fd8d0d96a (patch)
tree247e8fd465452448eca9730047cadb0539910524
parentedfe8c0e5ea6b77a22a406df1a91102d70623041 (diff)
downloadluarocks-18e288d091709957e34de8177179a86fd8d0d96a.tar.gz
luarocks-18e288d091709957e34de8177179a86fd8d0d96a.tar.bz2
luarocks-18e288d091709957e34de8177179a86fd8d0d96a.zip
cmd
-rw-r--r--src/luarocks/cmd/doc-original.lua153
-rw-r--r--src/luarocks/cmd/doc.lua63
-rw-r--r--src/luarocks/cmd/download-original.lua56
-rw-r--r--src/luarocks/cmd/download.lua39
-rw-r--r--src/luarocks/cmd/init-original.lua219
-rw-r--r--src/luarocks/cmd/init.lua41
-rw-r--r--src/luarocks/cmd/install.d.tl4
-rw-r--r--src/luarocks/cmd/list-original.lua96
-rw-r--r--src/luarocks/cmd/list.lua55
-rw-r--r--src/luarocks/cmd/pack-original.lua36
-rw-r--r--src/luarocks/cmd/pack.lua27
-rw-r--r--src/luarocks/cmd/path-original.lua83
-rw-r--r--src/luarocks/cmd/path.lua41
-rw-r--r--src/luarocks/cmd/purge-original.lua72
-rw-r--r--src/luarocks/cmd/purge.lua45
-rw-r--r--src/luarocks/cmd/remove-original.lua71
-rw-r--r--src/luarocks/cmd/remove.lua38
-rw-r--r--src/luarocks/cmd/search-original.lua84
-rw-r--r--src/luarocks/cmd/search.lua62
-rw-r--r--src/luarocks/cmd/test-original.lua48
-rw-r--r--src/luarocks/cmd/test.lua29
-rw-r--r--src/luarocks/cmd/unpack-original.lua169
-rw-r--r--src/luarocks/cmd/unpack.lua105
-rw-r--r--src/luarocks/cmd/write_rockspec-original.lua408
-rw-r--r--src/luarocks/cmd/write_rockspec.lua139
25 files changed, 1897 insertions, 286 deletions
diff --git a/src/luarocks/cmd/doc-original.lua b/src/luarocks/cmd/doc-original.lua
new file mode 100644
index 00000000..cae929cb
--- /dev/null
+++ b/src/luarocks/cmd/doc-original.lua
@@ -0,0 +1,153 @@
1
2--- Module implementing the LuaRocks "doc" command.
3-- Shows documentation for an installed rock.
4local doc = {}
5
6local util = require("luarocks.util")
7local queries = require("luarocks.queries")
8local search = require("luarocks.search")
9local path = require("luarocks.path")
10local dir = require("luarocks.dir")
11local fetch = require("luarocks.fetch")
12local fs = require("luarocks.fs")
13local download = require("luarocks.download")
14
15function doc.add_to_parser(parser)
16 local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n"..
17 "Without any flags, tries to load the documentation using a series of heuristics.\n"..
18 "With flags, return only the desired information.", util.see_also([[
19 For more information about a rock, see the 'show' command.
20]]))
21 :summary("Show documentation for an installed rock.")
22
23 cmd:argument("rock", "Name of the rock.")
24 :action(util.namespaced_name_action)
25 cmd:argument("version", "Version of the rock.")
26 :args("?")
27
28 cmd:flag("--home", "Open the home page of project.")
29 cmd:flag("--list", "List documentation files only.")
30 cmd:flag("--porcelain", "Produce machine-friendly output.")
31end
32
33local function show_homepage(homepage, name, namespace, version)
34 if not homepage then
35 return nil, "No 'homepage' field in rockspec for "..util.format_rock_name(name, namespace, version)
36 end
37 util.printout("Opening "..homepage.." ...")
38 fs.browser(homepage)
39 return true
40end
41
42local function try_to_open_homepage(name, namespace, version)
43 local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or ""))
44 if not temp_dir then
45 return nil, "Failed creating temporary directory: "..err
46 end
47 util.schedule_function(fs.delete, temp_dir)
48 local ok, err = fs.change_dir(temp_dir)
49 if not ok then return nil, err end
50 local filename, err = download.download_file("rockspec", name, namespace, version)
51 if not filename then return nil, err end
52 local rockspec, err = fetch.load_local_rockspec(filename)
53 if not rockspec then return nil, err end
54 fs.pop_dir()
55 local descript = rockspec.description or {}
56 return show_homepage(descript.homepage, name, namespace, version)
57end
58
59--- Driver function for "doc" command.
60-- @return boolean: True if succeeded, nil on errors.
61function doc.command(args)
62 local query = queries.new(args.rock, args.namespace, args.version)
63 local iname, iversion, repo = search.pick_installed_rock(query, args.tree)
64 if not iname then
65 local rock = util.format_rock_name(args.rock, args.namespace, args.version)
66 util.printout(rock.." is not installed. Looking for it in the rocks servers...")
67 return try_to_open_homepage(args.rock, args.namespace, args.version)
68 end
69 local name, version = iname, iversion
70
71 local rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version, repo))
72 if not rockspec then return nil,err end
73 local descript = rockspec.description or {}
74
75 if args.home then
76 return show_homepage(descript.homepage, name, args.namespace, version)
77 end
78
79 local directory = path.install_dir(name, version, repo)
80
81 local docdir
82 local directories = { "doc", "docs" }
83 for _, d in ipairs(directories) do
84 local dirname = dir.path(directory, d)
85 if fs.is_dir(dirname) then
86 docdir = dirname
87 break
88 end
89 end
90 if not docdir then
91 if descript.homepage and not args.list then
92 util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...")
93 fs.browser(descript.homepage)
94 return true
95 end
96 return nil, "Documentation directory not found for "..name.." "..version
97 end
98
99 docdir = dir.normalize(docdir)
100 local files = fs.find(docdir)
101 local htmlpatt = "%.html?$"
102 local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" }
103 local basenames = { "index", "readme", "manual" }
104
105 local porcelain = args.porcelain
106 if #files > 0 then
107 util.title("Documentation files for "..name.." "..version, porcelain)
108 if porcelain then
109 for _, file in ipairs(files) do
110 util.printout(docdir.."/"..file)
111 end
112 else
113 util.printout(docdir.."/")
114 for _, file in ipairs(files) do
115 util.printout("\t"..file)
116 end
117 end
118 end
119
120 if args.list then
121 return true
122 end
123
124 for _, extension in ipairs(extensions) do
125 for _, basename in ipairs(basenames) do
126 local filename = basename..extension
127 local found
128 for _, file in ipairs(files) do
129 if file:lower():match(filename) and ((not found) or #file < #found) then
130 found = file
131 end
132 end
133 if found then
134 local pathname = dir.path(docdir, found)
135 util.printout()
136 util.printout("Opening "..pathname.." ...")
137 util.printout()
138 local ok = fs.browser(pathname)
139 if not ok and not pathname:match(htmlpatt) then
140 local fd = io.open(pathname, "r")
141 util.printout(fd:read("*a"))
142 fd:close()
143 end
144 return true
145 end
146 end
147 end
148
149 return true
150end
151
152
153return doc
diff --git a/src/luarocks/cmd/doc.lua b/src/luarocks/cmd/doc.lua
index cae929cb..52846337 100644
--- a/src/luarocks/cmd/doc.lua
+++ b/src/luarocks/cmd/doc.lua
@@ -1,8 +1,9 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs
2
1 3
2--- Module implementing the LuaRocks "doc" command.
3-- Shows documentation for an installed rock.
4local doc = {} 4local doc = {}
5 5
6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local queries = require("luarocks.queries") 8local queries = require("luarocks.queries")
8local search = require("luarocks.search") 9local search = require("luarocks.search")
@@ -12,18 +13,24 @@ local fetch = require("luarocks.fetch")
12local fs = require("luarocks.fs") 13local fs = require("luarocks.fs")
13local download = require("luarocks.download") 14local download = require("luarocks.download")
14 15
16local argparse = require("luarocks.vendor.argparse")
17
18
19
20
21
15function doc.add_to_parser(parser) 22function doc.add_to_parser(parser)
16 local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n".. 23 local cmd = parser:command("doc", "Show documentation for an installed rock.\n\n" ..
17 "Without any flags, tries to load the documentation using a series of heuristics.\n".. 24 "Without any flags, tries to load the documentation using a series of heuristics.\n" ..
18 "With flags, return only the desired information.", util.see_also([[ 25 "With flags, return only the desired information.", util.see_also([[
19 For more information about a rock, see the 'show' command. 26 For more information about a rock, see the 'show' command.
20]])) 27]])):
21 :summary("Show documentation for an installed rock.") 28 summary("Show documentation for an installed rock.")
22 29
23 cmd:argument("rock", "Name of the rock.") 30 cmd:argument("rock", "Name of the rock."):
24 :action(util.namespaced_name_action) 31 action(util.namespaced_name_action)
25 cmd:argument("version", "Version of the rock.") 32 cmd:argument("version", "Version of the rock."):
26 :args("?") 33 args("?")
27 34
28 cmd:flag("--home", "Open the home page of project.") 35 cmd:flag("--home", "Open the home page of project.")
29 cmd:flag("--list", "List documentation files only.") 36 cmd:flag("--list", "List documentation files only.")
@@ -32,17 +39,17 @@ end
32 39
33local function show_homepage(homepage, name, namespace, version) 40local function show_homepage(homepage, name, namespace, version)
34 if not homepage then 41 if not homepage then
35 return nil, "No 'homepage' field in rockspec for "..util.format_rock_name(name, namespace, version) 42 return nil, "No 'homepage' field in rockspec for " .. util.format_rock_name(name, namespace, version)
36 end 43 end
37 util.printout("Opening "..homepage.." ...") 44 util.printout("Opening " .. homepage .. " ...")
38 fs.browser(homepage) 45 fs.browser(homepage)
39 return true 46 return true
40end 47end
41 48
42local function try_to_open_homepage(name, namespace, version) 49local function try_to_open_homepage(name, namespace, version)
43 local temp_dir, err = fs.make_temp_dir("doc-"..name.."-"..(version or "")) 50 local temp_dir, err = fs.make_temp_dir("doc-" .. name .. "-" .. (version or ""))
44 if not temp_dir then 51 if not temp_dir then
45 return nil, "Failed creating temporary directory: "..err 52 return nil, "Failed creating temporary directory: " .. err
46 end 53 end
47 util.schedule_function(fs.delete, temp_dir) 54 util.schedule_function(fs.delete, temp_dir)
48 local ok, err = fs.change_dir(temp_dir) 55 local ok, err = fs.change_dir(temp_dir)
@@ -56,20 +63,20 @@ local function try_to_open_homepage(name, namespace, version)
56 return show_homepage(descript.homepage, name, namespace, version) 63 return show_homepage(descript.homepage, name, namespace, version)
57end 64end
58 65
59--- Driver function for "doc" command. 66
60-- @return boolean: True if succeeded, nil on errors. 67
61function doc.command(args) 68function doc.command(args)
62 local query = queries.new(args.rock, args.namespace, args.version) 69 local query = queries.new(args.rock, args.namespace, args.version)
63 local iname, iversion, repo = search.pick_installed_rock(query, args.tree) 70 local iname, iversion, repo = search.pick_installed_rock(query, args.tree)
64 if not iname then 71 if not iname then
65 local rock = util.format_rock_name(args.rock, args.namespace, args.version) 72 local rock = util.format_rock_name(args.rock, args.namespace, args.version)
66 util.printout(rock.." is not installed. Looking for it in the rocks servers...") 73 util.printout(rock .. " is not installed. Looking for it in the rocks servers...")
67 return try_to_open_homepage(args.rock, args.namespace, args.version) 74 return try_to_open_homepage(args.rock, args.namespace, args.version)
68 end 75 end
69 local name, version = iname, iversion 76 local name, version = iname, iversion
70 77
71 local rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version, repo)) 78 local rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version, repo))
72 if not rockspec then return nil,err end 79 if not rockspec then return nil, err end
73 local descript = rockspec.description or {} 80 local descript = rockspec.description or {}
74 81
75 if args.home then 82 if args.home then
@@ -89,30 +96,30 @@ function doc.command(args)
89 end 96 end
90 if not docdir then 97 if not docdir then
91 if descript.homepage and not args.list then 98 if descript.homepage and not args.list then
92 util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") 99 util.printout("Local documentation directory not found -- opening " .. descript.homepage .. " ...")
93 fs.browser(descript.homepage) 100 fs.browser(descript.homepage)
94 return true 101 return true
95 end 102 end
96 return nil, "Documentation directory not found for "..name.." "..version 103 return nil, "Documentation directory not found for " .. name .. " " .. version
97 end 104 end
98 105
99 docdir = dir.normalize(docdir) 106 docdir = dir.normalize(docdir)
100 local files = fs.find(docdir) 107 local files = fs.find(docdir)
101 local htmlpatt = "%.html?$" 108 local htmlpatt = "%.html?$"
102 local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" } 109 local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" }
103 local basenames = { "index", "readme", "manual" } 110 local basenames = { "index", "readme", "manual" }
104 111
105 local porcelain = args.porcelain 112 local porcelain = args.porcelain
106 if #files > 0 then 113 if #files > 0 then
107 util.title("Documentation files for "..name.." "..version, porcelain) 114 util.title("Documentation files for " .. name .. " " .. version, porcelain)
108 if porcelain then 115 if porcelain then
109 for _, file in ipairs(files) do 116 for _, file in ipairs(files) do
110 util.printout(docdir.."/"..file) 117 util.printout(docdir .. "/" .. file)
111 end 118 end
112 else 119 else
113 util.printout(docdir.."/") 120 util.printout(docdir .. "/")
114 for _, file in ipairs(files) do 121 for _, file in ipairs(files) do
115 util.printout("\t"..file) 122 util.printout("\t" .. file)
116 end 123 end
117 end 124 end
118 end 125 end
@@ -123,7 +130,7 @@ function doc.command(args)
123 130
124 for _, extension in ipairs(extensions) do 131 for _, extension in ipairs(extensions) do
125 for _, basename in ipairs(basenames) do 132 for _, basename in ipairs(basenames) do
126 local filename = basename..extension 133 local filename = basename .. extension
127 local found 134 local found
128 for _, file in ipairs(files) do 135 for _, file in ipairs(files) do
129 if file:lower():match(filename) and ((not found) or #file < #found) then 136 if file:lower():match(filename) and ((not found) or #file < #found) then
@@ -133,7 +140,7 @@ function doc.command(args)
133 if found then 140 if found then
134 local pathname = dir.path(docdir, found) 141 local pathname = dir.path(docdir, found)
135 util.printout() 142 util.printout()
136 util.printout("Opening "..pathname.." ...") 143 util.printout("Opening " .. pathname .. " ...")
137 util.printout() 144 util.printout()
138 local ok = fs.browser(pathname) 145 local ok = fs.browser(pathname)
139 if not ok and not pathname:match(htmlpatt) then 146 if not ok and not pathname:match(htmlpatt) then
diff --git a/src/luarocks/cmd/download-original.lua b/src/luarocks/cmd/download-original.lua
new file mode 100644
index 00000000..23433d30
--- /dev/null
+++ b/src/luarocks/cmd/download-original.lua
@@ -0,0 +1,56 @@
1
2--- Module implementing the luarocks "download" command.
3-- Download a rock from the repository.
4local cmd_download = {}
5
6local util = require("luarocks.util")
7local download = require("luarocks.download")
8
9function cmd_download.add_to_parser(parser)
10 local cmd = parser:command("download", "Download a specific rock file from a rocks server.", util.see_also())
11
12 cmd:argument("name", "Name of the rock.")
13 :args("?")
14 :action(util.namespaced_name_action)
15 cmd:argument("version", "Version of the rock.")
16 :args("?")
17
18 cmd:flag("--all", "Download all files if there are multiple matches.")
19 cmd:mutex(
20 cmd:flag("--source", "Download .src.rock if available."),
21 cmd:flag("--rockspec", "Download .rockspec if available."),
22 cmd:option("--arch", "Download rock for a specific architecture."))
23 cmd:flag("--check-lua-versions", "If the rock can't be found, check repository "..
24 "and report if it is available for another Lua version.")
25end
26
27--- Driver function for the "download" command.
28-- @return boolean or (nil, string): true if successful or nil followed
29-- by an error message.
30function cmd_download.command(args)
31 if not args.name and not args.all then
32 return nil, "Argument missing. "..util.see_help("download")
33 end
34
35 args.name = args.name or ""
36
37 local arch
38
39 if args.source then
40 arch = "src"
41 elseif args.rockspec then
42 arch = "rockspec"
43 elseif args.arch then
44 arch = args.arch
45 end
46
47 if args.all then
48 local ok, err = download.download_all(arch, args.name, args.namespace, args.version)
49 return ok, err
50 else
51 local dl, err = download.download_file(arch, args.name, args.namespace, args.version, args.check_lua_versions)
52 return dl and true, err
53 end
54end
55
56return cmd_download
diff --git a/src/luarocks/cmd/download.lua b/src/luarocks/cmd/download.lua
index 23433d30..9ae2fa27 100644
--- a/src/luarocks/cmd/download.lua
+++ b/src/luarocks/cmd/download.lua
@@ -1,35 +1,42 @@
1 1
2--- Module implementing the luarocks "download" command. 2
3-- Download a rock from the repository. 3
4local cmd_download = {} 4local cmd_download = {}
5 5
6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local download = require("luarocks.download") 8local download = require("luarocks.download")
8 9
10local argparse = require("luarocks.vendor.argparse")
11
12
13
14
15
9function cmd_download.add_to_parser(parser) 16function cmd_download.add_to_parser(parser)
10 local cmd = parser:command("download", "Download a specific rock file from a rocks server.", util.see_also()) 17 local cmd = parser:command("download", "Download a specific rock file from a rocks server.", util.see_also())
11 18
12 cmd:argument("name", "Name of the rock.") 19 cmd:argument("name", "Name of the rock."):
13 :args("?") 20 args("?"):
14 :action(util.namespaced_name_action) 21 action(util.namespaced_name_action)
15 cmd:argument("version", "Version of the rock.") 22 cmd:argument("version", "Version of the rock."):
16 :args("?") 23 args("?")
17 24
18 cmd:flag("--all", "Download all files if there are multiple matches.") 25 cmd:flag("--all", "Download all files if there are multiple matches.")
19 cmd:mutex( 26 cmd:mutex(
20 cmd:flag("--source", "Download .src.rock if available."), 27 cmd:flag("--source", "Download .src.rock if available."),
21 cmd:flag("--rockspec", "Download .rockspec if available."), 28 cmd:flag("--rockspec", "Download .rockspec if available."),
22 cmd:option("--arch", "Download rock for a specific architecture.")) 29 cmd:option("--arch", "Download rock for a specific architecture."))
23 cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. 30 cmd:flag("--check-lua-versions", "If the rock can't be found, check repository " ..
24 "and report if it is available for another Lua version.") 31 "and report if it is available for another Lua version.")
25end 32end
26 33
27--- Driver function for the "download" command. 34
28-- @return boolean or (nil, string): true if successful or nil followed 35
29-- by an error message. 36
30function cmd_download.command(args) 37function cmd_download.command(args)
31 if not args.name and not args.all then 38 if not args.name and not args.all then
32 return nil, "Argument missing. "..util.see_help("download") 39 return nil, "Argument missing. " .. util.see_help("download")
33 end 40 end
34 41
35 args.name = args.name or "" 42 args.name = args.name or ""
diff --git a/src/luarocks/cmd/init-original.lua b/src/luarocks/cmd/init-original.lua
new file mode 100644
index 00000000..b5359c96
--- /dev/null
+++ b/src/luarocks/cmd/init-original.lua
@@ -0,0 +1,219 @@
1
2local init = {}
3
4local cfg = require("luarocks.core.cfg")
5local fs = require("luarocks.fs")
6local path = require("luarocks.path")
7local deps = require("luarocks.deps")
8local dir = require("luarocks.dir")
9local util = require("luarocks.util")
10local persist = require("luarocks.persist")
11local write_rockspec = require("luarocks.cmd.write_rockspec")
12
13function init.add_to_parser(parser)
14 local cmd = parser:command("init", "Initialize a directory for a Lua project using LuaRocks.", util.see_also())
15
16 cmd:argument("name", "The project name.")
17 :args("?")
18 cmd:argument("version", "An optional project version.")
19 :args("?")
20 cmd:option("--wrapper-dir", "Location where the 'lua' and 'luarocks' wrapper scripts " ..
21 "should be generated; if not given, the current directory is used as a default.")
22 cmd:flag("--reset", "Delete any .luarocks/config-5.x.lua and ./lua and generate new ones.")
23 cmd:flag("--no-wrapper-scripts", "Do not generate wrapper ./lua and ./luarocks launcher scripts.")
24 cmd:flag("--no-gitignore", "Do not generate a .gitignore file.")
25
26 cmd:group("Options for specifying rockspec data", write_rockspec.cmd_options(cmd))
27end
28
29local function gitignore_path(pwd, wrapper_dir, filename)
30 local norm_cur = fs.absolute_name(pwd)
31 local norm_file = fs.absolute_name(dir.path(wrapper_dir, filename))
32 if norm_file:sub(1, #norm_cur) == norm_cur then
33 return norm_file:sub(#norm_cur + 2)
34 else
35 return filename
36 end
37end
38
39local function write_gitignore(entries)
40 local gitignore = ""
41 local fd = io.open(".gitignore", "r")
42 if fd then
43 gitignore = fd:read("*a")
44 fd:close()
45 gitignore = "\n" .. gitignore .. "\n"
46 end
47
48 fd = io.open(".gitignore", gitignore and "a" or "w")
49 if fd then
50 for _, entry in ipairs(entries) do
51 entry = "/" .. entry
52 if not gitignore:find("\n"..entry.."\n", 1, true) then
53 fd:write(entry.."\n")
54 end
55 end
56 fd:close()
57 end
58end
59
60local function inject_tree(tree)
61 path.use_tree(tree)
62 local tree_set = false
63 for _, t in ipairs(cfg.rocks_trees) do
64 if type(t) == "table" then
65 if t.name == "project" then
66 t.root = tree
67 tree_set = true
68 end
69 end
70 end
71 if not tree_set then
72 table.insert(cfg.rocks_trees, 1, { name = "project", root = tree })
73 end
74end
75
76local function write_wrapper_scripts(wrapper_dir, luarocks_wrapper, lua_wrapper)
77 local tree = dir.path(fs.current_dir(), "lua_modules")
78
79 fs.make_dir(wrapper_dir)
80
81 luarocks_wrapper = dir.path(wrapper_dir, luarocks_wrapper)
82 if not fs.exists(luarocks_wrapper) then
83 util.printout("Preparing " .. luarocks_wrapper .. " ...")
84 fs.wrap_script(arg[0], luarocks_wrapper, "none", nil, nil, "--project-tree", tree)
85 else
86 util.printout(luarocks_wrapper .. " already exists. Not overwriting it!")
87 end
88
89 lua_wrapper = dir.path(wrapper_dir, lua_wrapper)
90 local write_lua_wrapper = true
91 if fs.exists(lua_wrapper) then
92 if not util.lua_is_wrapper(lua_wrapper) then
93 util.printout(lua_wrapper .. " already exists and does not look like a wrapper script. Not overwriting.")
94 write_lua_wrapper = false
95 end
96 end
97
98 if write_lua_wrapper then
99 if util.check_lua_version(cfg.variables.LUA, cfg.lua_version) then
100 util.printout("Preparing " .. lua_wrapper .. " for version " .. cfg.lua_version .. "...")
101
102 -- Inject tree so it shows up as a lookup path in the wrappers
103 inject_tree(tree)
104
105 fs.wrap_script(nil, lua_wrapper, "all")
106 else
107 util.warning("No Lua interpreter detected for version " .. cfg.lua_version .. ". Not creating " .. lua_wrapper)
108 end
109 end
110end
111
112--- Driver function for "init" command.
113-- @return boolean: True if succeeded, nil on errors.
114function init.command(args)
115 local do_gitignore = not args.no_gitignore
116 local do_wrapper_scripts = not args.no_wrapper_scripts
117 local wrapper_dir = args.wrapper_dir or "."
118
119 local pwd = fs.current_dir()
120
121 if not args.name then
122 args.name = dir.base_name(pwd)
123 if args.name == "/" then
124 return nil, "When running from the root directory, please specify the <name> argument"
125 end
126 end
127
128 util.title("Initializing project '" .. args.name .. "' for Lua " .. cfg.lua_version .. " ...")
129
130 local ok, err = deps.check_lua_incdir(cfg.variables)
131 if not ok then
132 return nil, err
133 end
134
135 local has_rockspec = false
136 for file in fs.dir() do
137 if file:match("%.rockspec$") then
138 has_rockspec = true
139 break
140 end
141 end
142
143 if not has_rockspec then
144 args.version = args.version or "dev"
145 args.location = pwd
146 local ok, err = write_rockspec.command(args)
147 if not ok then
148 util.printerr(err)
149 end
150 end
151
152 local ext = cfg.wrapper_suffix
153 local luarocks_wrapper = "luarocks" .. ext
154 local lua_wrapper = "lua" .. ext
155
156 if do_gitignore then
157 util.printout("Adding entries to .gitignore ...")
158 local ignores = { "lua_modules", ".luarocks" }
159 if do_wrapper_scripts then
160 table.insert(ignores, 1, gitignore_path(pwd, wrapper_dir, luarocks_wrapper))
161 table.insert(ignores, 2, gitignore_path(pwd, wrapper_dir, lua_wrapper))
162 end
163 write_gitignore(ignores)
164 end
165
166 util.printout("Preparing ./.luarocks/ ...")
167 fs.make_dir(".luarocks")
168 local config_file = ".luarocks/config-" .. cfg.lua_version .. ".lua"
169
170 if args.reset then
171 if do_wrapper_scripts then
172 fs.delete(fs.absolute_name(dir.path(wrapper_dir, lua_wrapper)))
173 end
174 fs.delete(fs.absolute_name(config_file))
175 end
176
177 local config_tbl, err = persist.load_config_file_if_basic(config_file, cfg)
178 if config_tbl then
179 local varnames = {
180 "LUA_DIR",
181 "LUA_INCDIR",
182 "LUA_LIBDIR",
183 "LUA_BINDIR",
184 "LUA",
185 }
186 for _, varname in ipairs(varnames) do
187 if cfg.variables[varname] then
188 config_tbl.variables = config_tbl.variables or {}
189 config_tbl.variables[varname] = cfg.variables[varname]
190 end
191 end
192 local ok, err = persist.save_from_table(config_file, config_tbl)
193 if ok then
194 util.printout("Wrote " .. config_file)
195 else
196 util.printout("Failed writing " .. config_file .. ": " .. err)
197 end
198 else
199 util.printout("Will not attempt to overwrite " .. config_file)
200 end
201
202 ok, err = persist.save_default_lua_version(".luarocks", cfg.lua_version)
203 if not ok then
204 util.printout("Failed setting default Lua version: " .. err)
205 end
206
207 util.printout("Preparing ./lua_modules/ ...")
208 fs.make_dir("lua_modules/lib/luarocks/rocks-" .. cfg.lua_version)
209
210 if do_wrapper_scripts then
211 write_wrapper_scripts(wrapper_dir, luarocks_wrapper, lua_wrapper)
212 end
213
214 return true
215end
216
217init.needs_lock = function() return true end
218
219return init
diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua
index b5359c96..af29a06f 100644
--- a/src/luarocks/cmd/init.lua
+++ b/src/luarocks/cmd/init.lua
@@ -1,6 +1,8 @@
1 1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table
2local init = {} 2local init = {}
3 3
4
5
4local cfg = require("luarocks.core.cfg") 6local cfg = require("luarocks.core.cfg")
5local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
6local path = require("luarocks.path") 8local path = require("luarocks.path")
@@ -10,15 +12,28 @@ local util = require("luarocks.util")
10local persist = require("luarocks.persist") 12local persist = require("luarocks.persist")
11local write_rockspec = require("luarocks.cmd.write_rockspec") 13local write_rockspec = require("luarocks.cmd.write_rockspec")
12 14
15local argparse = require("luarocks.vendor.argparse")
16
17
18
19
20
21
22
23
24
25local t = require("luarocks.core.types.tree")
26
27
13function init.add_to_parser(parser) 28function init.add_to_parser(parser)
14 local cmd = parser:command("init", "Initialize a directory for a Lua project using LuaRocks.", util.see_also()) 29 local cmd = parser:command("init", "Initialize a directory for a Lua project using LuaRocks.", util.see_also())
15 30
16 cmd:argument("name", "The project name.") 31 cmd:argument("name", "The project name."):
17 :args("?") 32 args("?")
18 cmd:argument("version", "An optional project version.") 33 cmd:argument("version", "An optional project version."):
19 :args("?") 34 args("?")
20 cmd:option("--wrapper-dir", "Location where the 'lua' and 'luarocks' wrapper scripts " .. 35 cmd:option("--wrapper-dir", "Location where the 'lua' and 'luarocks' wrapper scripts " ..
21 "should be generated; if not given, the current directory is used as a default.") 36 "should be generated; if not given, the current directory is used as a default.")
22 cmd:flag("--reset", "Delete any .luarocks/config-5.x.lua and ./lua and generate new ones.") 37 cmd:flag("--reset", "Delete any .luarocks/config-5.x.lua and ./lua and generate new ones.")
23 cmd:flag("--no-wrapper-scripts", "Do not generate wrapper ./lua and ./luarocks launcher scripts.") 38 cmd:flag("--no-wrapper-scripts", "Do not generate wrapper ./lua and ./luarocks launcher scripts.")
24 cmd:flag("--no-gitignore", "Do not generate a .gitignore file.") 39 cmd:flag("--no-gitignore", "Do not generate a .gitignore file.")
@@ -49,8 +64,8 @@ local function write_gitignore(entries)
49 if fd then 64 if fd then
50 for _, entry in ipairs(entries) do 65 for _, entry in ipairs(entries) do
51 entry = "/" .. entry 66 entry = "/" .. entry
52 if not gitignore:find("\n"..entry.."\n", 1, true) then 67 if not gitignore:find("\n" .. entry .. "\n", 1, true) then
53 fd:write(entry.."\n") 68 fd:write(entry .. "\n")
54 end 69 end
55 end 70 end
56 fd:close() 71 fd:close()
@@ -99,7 +114,7 @@ local function write_wrapper_scripts(wrapper_dir, luarocks_wrapper, lua_wrapper)
99 if util.check_lua_version(cfg.variables.LUA, cfg.lua_version) then 114 if util.check_lua_version(cfg.variables.LUA, cfg.lua_version) then
100 util.printout("Preparing " .. lua_wrapper .. " for version " .. cfg.lua_version .. "...") 115 util.printout("Preparing " .. lua_wrapper .. " for version " .. cfg.lua_version .. "...")
101 116
102 -- Inject tree so it shows up as a lookup path in the wrappers 117
103 inject_tree(tree) 118 inject_tree(tree)
104 119
105 fs.wrap_script(nil, lua_wrapper, "all") 120 fs.wrap_script(nil, lua_wrapper, "all")
@@ -109,8 +124,8 @@ local function write_wrapper_scripts(wrapper_dir, luarocks_wrapper, lua_wrapper)
109 end 124 end
110end 125end
111 126
112--- Driver function for "init" command. 127
113-- @return boolean: True if succeeded, nil on errors. 128
114function init.command(args) 129function init.command(args)
115 local do_gitignore = not args.no_gitignore 130 local do_gitignore = not args.no_gitignore
116 local do_wrapper_scripts = not args.no_wrapper_scripts 131 local do_wrapper_scripts = not args.no_wrapper_scripts
@@ -185,8 +200,8 @@ function init.command(args)
185 } 200 }
186 for _, varname in ipairs(varnames) do 201 for _, varname in ipairs(varnames) do
187 if cfg.variables[varname] then 202 if cfg.variables[varname] then
188 config_tbl.variables = config_tbl.variables or {} 203 config_tbl.variables = config_tbl.variables or {};
189 config_tbl.variables[varname] = cfg.variables[varname] 204 (config_tbl.variables)[varname] = cfg.variables[varname]
190 end 205 end
191 end 206 end
192 local ok, err = persist.save_from_table(config_file, config_tbl) 207 local ok, err = persist.save_from_table(config_file, config_tbl)
diff --git a/src/luarocks/cmd/install.d.tl b/src/luarocks/cmd/install.d.tl
deleted file mode 100644
index 46ceb734..00000000
--- a/src/luarocks/cmd/install.d.tl
+++ /dev/null
@@ -1,4 +0,0 @@
1local record install
2 command: function(any): boolean, string, string
3end
4return install \ No newline at end of file
diff --git a/src/luarocks/cmd/list-original.lua b/src/luarocks/cmd/list-original.lua
new file mode 100644
index 00000000..7b2682f6
--- /dev/null
+++ b/src/luarocks/cmd/list-original.lua
@@ -0,0 +1,96 @@
1
2--- Module implementing the LuaRocks "list" command.
3-- Lists currently installed rocks.
4local list = {}
5
6local search = require("luarocks.search")
7local queries = require("luarocks.queries")
8local vers = require("luarocks.core.vers")
9local cfg = require("luarocks.core.cfg")
10local util = require("luarocks.util")
11local path = require("luarocks.path")
12
13function list.add_to_parser(parser)
14 local cmd = parser:command("list", "List currently installed rocks.", util.see_also())
15
16 cmd:argument("filter", "A substring of a rock name to filter by.")
17 :args("?")
18 cmd:argument("version", "Rock version to filter by.")
19 :args("?")
20
21 cmd:flag("--outdated", "List only rocks for which there is a higher "..
22 "version available in the rocks server.")
23 cmd:flag("--porcelain", "Produce machine-friendly output.")
24end
25
26local function check_outdated(trees, query)
27 local results_installed = {}
28 for _, tree in ipairs(trees) do
29 search.local_manifest_search(results_installed, path.rocks_dir(tree), query)
30 end
31 local outdated = {}
32 for name, versions in util.sortedpairs(results_installed) do
33 versions = util.keys(versions)
34 table.sort(versions, vers.compare_versions)
35 local latest_installed = versions[1]
36
37 local query_available = queries.new(name:lower())
38 local results_available, err = search.search_repos(query_available)
39
40 if results_available[name] then
41 local available_versions = util.keys(results_available[name])
42 table.sort(available_versions, vers.compare_versions)
43 local latest_available = available_versions[1]
44 local latest_available_repo = results_available[name][latest_available][1].repo
45
46 if vers.compare_versions(latest_available, latest_installed) then
47 table.insert(outdated, { name = name, installed = latest_installed, available = latest_available, repo = latest_available_repo })
48 end
49 end
50 end
51 return outdated
52end
53
54local function list_outdated(trees, query, porcelain)
55 util.title("Outdated rocks:", porcelain)
56 local outdated = check_outdated(trees, query)
57 for _, item in ipairs(outdated) do
58 if porcelain then
59 util.printout(item.name, item.installed, item.available, item.repo)
60 else
61 util.printout(item.name)
62 util.printout(" "..item.installed.." < "..item.available.." at "..item.repo)
63 util.printout()
64 end
65 end
66 return true
67end
68
69--- Driver function for "list" command.
70-- @return boolean: True if succeeded, nil on errors.
71function list.command(args)
72 local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true)
73 local trees = cfg.rocks_trees
74 local title = "Rocks installed for Lua "..cfg.lua_version
75 if args.tree then
76 trees = { args.tree }
77 title = title .. " in " .. args.tree
78 end
79
80 if args.outdated then
81 return list_outdated(trees, query, args.porcelain)
82 end
83
84 local results = {}
85 for _, tree in ipairs(trees) do
86 local ok, err, errcode = search.local_manifest_search(results, path.rocks_dir(tree), query)
87 if not ok and errcode ~= "open" then
88 util.warning(err)
89 end
90 end
91 util.title(title, args.porcelain)
92 search.print_result_tree(results, args.porcelain)
93 return true
94end
95
96return list
diff --git a/src/luarocks/cmd/list.lua b/src/luarocks/cmd/list.lua
index 7b2682f6..96a95bc3 100644
--- a/src/luarocks/cmd/list.lua
+++ b/src/luarocks/cmd/list.lua
@@ -1,7 +1,14 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table
2
3
4local list = {Outdated = {}, }
5
6
7
8
9
10
1 11
2--- Module implementing the LuaRocks "list" command.
3-- Lists currently installed rocks.
4local list = {}
5 12
6local search = require("luarocks.search") 13local search = require("luarocks.search")
7local queries = require("luarocks.queries") 14local queries = require("luarocks.queries")
@@ -10,16 +17,30 @@ local cfg = require("luarocks.core.cfg")
10local util = require("luarocks.util") 17local util = require("luarocks.util")
11local path = require("luarocks.path") 18local path = require("luarocks.path")
12 19
20
21
22local argparse = require("luarocks.vendor.argparse")
23
24
25
26
27
28
29
30
31
32
33
13function list.add_to_parser(parser) 34function list.add_to_parser(parser)
14 local cmd = parser:command("list", "List currently installed rocks.", util.see_also()) 35 local cmd = parser:command("list", "List currently installed rocks.", util.see_also())
15 36
16 cmd:argument("filter", "A substring of a rock name to filter by.") 37 cmd:argument("filter", "A substring of a rock name to filter by."):
17 :args("?") 38 args("?")
18 cmd:argument("version", "Rock version to filter by.") 39 cmd:argument("version", "Rock version to filter by."):
19 :args("?") 40 args("?")
20 41
21 cmd:flag("--outdated", "List only rocks for which there is a higher ".. 42 cmd:flag("--outdated", "List only rocks for which there is a higher " ..
22 "version available in the rocks server.") 43 "version available in the rocks server.")
23 cmd:flag("--porcelain", "Produce machine-friendly output.") 44 cmd:flag("--porcelain", "Produce machine-friendly output.")
24end 45end
25 46
@@ -30,12 +51,12 @@ local function check_outdated(trees, query)
30 end 51 end
31 local outdated = {} 52 local outdated = {}
32 for name, versions in util.sortedpairs(results_installed) do 53 for name, versions in util.sortedpairs(results_installed) do
33 versions = util.keys(versions) 54 local versionsk = util.keys(versions)
34 table.sort(versions, vers.compare_versions) 55 table.sort(versionsk, vers.compare_versions)
35 local latest_installed = versions[1] 56 local latest_installed = versionsk[1]
36 57
37 local query_available = queries.new(name:lower()) 58 local query_available = queries.new(name:lower())
38 local results_available, err = search.search_repos(query_available) 59 local results_available = search.search_repos(query_available)
39 60
40 if results_available[name] then 61 if results_available[name] then
41 local available_versions = util.keys(results_available[name]) 62 local available_versions = util.keys(results_available[name])
@@ -59,19 +80,19 @@ local function list_outdated(trees, query, porcelain)
59 util.printout(item.name, item.installed, item.available, item.repo) 80 util.printout(item.name, item.installed, item.available, item.repo)
60 else 81 else
61 util.printout(item.name) 82 util.printout(item.name)
62 util.printout(" "..item.installed.." < "..item.available.." at "..item.repo) 83 util.printout(" " .. item.installed .. " < " .. item.available .. " at " .. item.repo)
63 util.printout() 84 util.printout()
64 end 85 end
65 end 86 end
66 return true 87 return true
67end 88end
68 89
69--- Driver function for "list" command. 90
70-- @return boolean: True if succeeded, nil on errors. 91
71function list.command(args) 92function list.command(args)
72 local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true) 93 local query = queries.new(args.filter and args.filter:lower() or "", args.namespace, args.version, true)
73 local trees = cfg.rocks_trees 94 local trees = cfg.rocks_trees
74 local title = "Rocks installed for Lua "..cfg.lua_version 95 local title = "Rocks installed for Lua " .. cfg.lua_version
75 if args.tree then 96 if args.tree then
76 trees = { args.tree } 97 trees = { args.tree }
77 title = title .. " in " .. args.tree 98 title = title .. " in " .. args.tree
diff --git a/src/luarocks/cmd/pack-original.lua b/src/luarocks/cmd/pack-original.lua
new file mode 100644
index 00000000..29a43e7b
--- /dev/null
+++ b/src/luarocks/cmd/pack-original.lua
@@ -0,0 +1,36 @@
1
2--- Module implementing the LuaRocks "pack" command.
3-- Creates a rock, packing sources or binaries.
4local cmd_pack = {}
5
6local util = require("luarocks.util")
7local pack = require("luarocks.pack")
8local queries = require("luarocks.queries")
9
10function cmd_pack.add_to_parser(parser)
11 local cmd = parser:command("pack", "Create a rock, packing sources or binaries.", util.see_also())
12
13 cmd:argument("rock", "A rockspec file, for creating a source rock, or the "..
14 "name of an installed package, for creating a binary rock.")
15 :action(util.namespaced_name_action)
16 cmd:argument("version", "A version may be given if the first argument is a rock name.")
17 :args("?")
18
19 cmd:flag("--sign", "Produce a signature file as well.")
20end
21
22--- Driver function for the "pack" command.
23-- @return boolean or (nil, string): true if successful or nil followed
24-- by an error message.
25function cmd_pack.command(args)
26 local file, err
27 if args.rock:match(".*%.rockspec") then
28 file, err = pack.pack_source_rock(args.rock)
29 else
30 local query = queries.new(args.rock, args.namespace, args.version)
31 file, err = pack.pack_installed_rock(query, args.tree)
32 end
33 return pack.report_and_sign_local_file(file, err, args.sign)
34end
35
36return cmd_pack
diff --git a/src/luarocks/cmd/pack.lua b/src/luarocks/cmd/pack.lua
index 29a43e7b..88268a0a 100644
--- a/src/luarocks/cmd/pack.lua
+++ b/src/luarocks/cmd/pack.lua
@@ -1,27 +1,34 @@
1 1
2--- Module implementing the LuaRocks "pack" command. 2
3-- Creates a rock, packing sources or binaries. 3
4local cmd_pack = {} 4local cmd_pack = {}
5 5
6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local pack = require("luarocks.pack") 8local pack = require("luarocks.pack")
8local queries = require("luarocks.queries") 9local queries = require("luarocks.queries")
9 10
11local argparse = require("luarocks.vendor.argparse")
12
13
14
15
16
10function cmd_pack.add_to_parser(parser) 17function cmd_pack.add_to_parser(parser)
11 local cmd = parser:command("pack", "Create a rock, packing sources or binaries.", util.see_also()) 18 local cmd = parser:command("pack", "Create a rock, packing sources or binaries.", util.see_also())
12 19
13 cmd:argument("rock", "A rockspec file, for creating a source rock, or the ".. 20 cmd:argument("rock", "A rockspec file, for creating a source rock, or the " ..
14 "name of an installed package, for creating a binary rock.") 21 "name of an installed package, for creating a binary rock."):
15 :action(util.namespaced_name_action) 22 action(util.namespaced_name_action)
16 cmd:argument("version", "A version may be given if the first argument is a rock name.") 23 cmd:argument("version", "A version may be given if the first argument is a rock name."):
17 :args("?") 24 args("?")
18 25
19 cmd:flag("--sign", "Produce a signature file as well.") 26 cmd:flag("--sign", "Produce a signature file as well.")
20end 27end
21 28
22--- Driver function for the "pack" command. 29
23-- @return boolean or (nil, string): true if successful or nil followed 30
24-- by an error message. 31
25function cmd_pack.command(args) 32function cmd_pack.command(args)
26 local file, err 33 local file, err
27 if args.rock:match(".*%.rockspec") then 34 if args.rock:match(".*%.rockspec") then
diff --git a/src/luarocks/cmd/path-original.lua b/src/luarocks/cmd/path-original.lua
new file mode 100644
index 00000000..ba346550
--- /dev/null
+++ b/src/luarocks/cmd/path-original.lua
@@ -0,0 +1,83 @@
1
2--- @module luarocks.path_cmd
3-- Driver for the `luarocks path` command.
4local path_cmd = {}
5
6local util = require("luarocks.util")
7local cfg = require("luarocks.core.cfg")
8local fs = require("luarocks.fs")
9
10function path_cmd.add_to_parser(parser)
11 local cmd = parser:command("path", [[
12Returns the package path currently configured for this installation
13of LuaRocks, formatted as shell commands to update LUA_PATH and LUA_CPATH.
14
15On Unix systems, you may run:
16 eval `luarocks path`
17And on Windows:
18 luarocks path > "%temp%\_lrp.bat"
19 call "%temp%\_lrp.bat" && del "%temp%\_lrp.bat"]],
20 util.see_also())
21 :summary("Return the currently configured package path.")
22
23 cmd:flag("--no-bin", "Do not export the PATH variable.")
24 cmd:flag("--append", "Appends the paths to the existing paths. Default is "..
25 "to prefix the LR paths to the existing paths.")
26 cmd:flag("--lr-path", "Prints Lua path components defined by the configured rocks trees " ..
27 "(not formatted as a shell command)")
28 cmd:flag("--lr-cpath", "Prints Lua cpath components defined by the configured rocks trees " ..
29 "(not formatted as a shell command)")
30 cmd:flag("--full", "By default, --lr-path and --lr-cpath only include the paths " ..
31 "derived by the LuaRocks rocks_trees. Using --full includes any other components " ..
32 "defined in your system's package.(c)path, either via the running interpreter's " ..
33 "default paths or via LUA_(C)PATH(_5_x) environment variables (in short, using " ..
34 "--full produces the same lists as shown in the shell outputs of 'luarocks path').")
35 cmd:flag("--lr-bin", "Exports the system path (not formatted as shell command).")
36 cmd:flag("--bin"):hidden(true)
37end
38
39--- Driver function for "path" command.
40-- @return boolean This function always succeeds.
41function path_cmd.command(args)
42 local lr_path, lr_cpath, lr_bin = cfg.package_paths(args.tree)
43 local path_sep = cfg.export_path_separator
44
45 local full_list = ((not args.lr_path) and (not args.lr_cpath) and (not args.lr_bin))
46 or args.full
47
48 local clean_path = util.cleanup_path(os.getenv("PATH") or "", path_sep, nil, true)
49
50 if full_list then
51 if args.append then
52 lr_path = package.path .. ";" .. lr_path
53 lr_cpath = package.cpath .. ";" .. lr_cpath
54 lr_bin = clean_path .. path_sep .. lr_bin
55 else
56 lr_path = lr_path.. ";" .. package.path
57 lr_cpath = lr_cpath .. ";" .. package.cpath
58 lr_bin = lr_bin .. path_sep .. clean_path
59 end
60 end
61
62 if args.lr_path then
63 util.printout(util.cleanup_path(lr_path, ';', cfg.lua_version, true))
64 return true
65 elseif args.lr_cpath then
66 util.printout(util.cleanup_path(lr_cpath, ';', cfg.lua_version, true))
67 return true
68 elseif args.lr_bin then
69 util.printout(util.cleanup_path(lr_bin, path_sep, nil, true))
70 return true
71 end
72
73 local lpath_var, lcpath_var = util.lua_path_variables()
74
75 util.printout(fs.export_cmd(lpath_var, util.cleanup_path(lr_path, ';', cfg.lua_version, args.append)))
76 util.printout(fs.export_cmd(lcpath_var, util.cleanup_path(lr_cpath, ';', cfg.lua_version, args.append)))
77 if not args.no_bin then
78 util.printout(fs.export_cmd("PATH", util.cleanup_path(lr_bin, path_sep, nil, args.append)))
79 end
80 return true
81end
82
83return path_cmd
diff --git a/src/luarocks/cmd/path.lua b/src/luarocks/cmd/path.lua
index ba346550..78c1a1ec 100644
--- a/src/luarocks/cmd/path.lua
+++ b/src/luarocks/cmd/path.lua
@@ -1,12 +1,19 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local os = _tl_compat and _tl_compat.os or os; local package = _tl_compat and _tl_compat.package or package
2
1 3
2--- @module luarocks.path_cmd
3-- Driver for the `luarocks path` command.
4local path_cmd = {} 4local path_cmd = {}
5 5
6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local cfg = require("luarocks.core.cfg") 8local cfg = require("luarocks.core.cfg")
8local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
9 10
11local argparse = require("luarocks.vendor.argparse")
12
13
14
15
16
10function path_cmd.add_to_parser(parser) 17function path_cmd.add_to_parser(parser)
11 local cmd = parser:command("path", [[ 18 local cmd = parser:command("path", [[
12Returns the package path currently configured for this installation 19Returns the package path currently configured for this installation
@@ -17,33 +24,33 @@ On Unix systems, you may run:
17And on Windows: 24And on Windows:
18 luarocks path > "%temp%\_lrp.bat" 25 luarocks path > "%temp%\_lrp.bat"
19 call "%temp%\_lrp.bat" && del "%temp%\_lrp.bat"]], 26 call "%temp%\_lrp.bat" && del "%temp%\_lrp.bat"]],
20 util.see_also()) 27 util.see_also()):
21 :summary("Return the currently configured package path.") 28 summary("Return the currently configured package path.")
22 29
23 cmd:flag("--no-bin", "Do not export the PATH variable.") 30 cmd:flag("--no-bin", "Do not export the PATH variable.")
24 cmd:flag("--append", "Appends the paths to the existing paths. Default is ".. 31 cmd:flag("--append", "Appends the paths to the existing paths. Default is " ..
25 "to prefix the LR paths to the existing paths.") 32 "to prefix the LR paths to the existing paths.")
26 cmd:flag("--lr-path", "Prints Lua path components defined by the configured rocks trees " .. 33 cmd:flag("--lr-path", "Prints Lua path components defined by the configured rocks trees " ..
27 "(not formatted as a shell command)") 34 "(not formatted as a shell command)")
28 cmd:flag("--lr-cpath", "Prints Lua cpath components defined by the configured rocks trees " .. 35 cmd:flag("--lr-cpath", "Prints Lua cpath components defined by the configured rocks trees " ..
29 "(not formatted as a shell command)") 36 "(not formatted as a shell command)")
30 cmd:flag("--full", "By default, --lr-path and --lr-cpath only include the paths " .. 37 cmd:flag("--full", "By default, --lr-path and --lr-cpath only include the paths " ..
31 "derived by the LuaRocks rocks_trees. Using --full includes any other components " .. 38 "derived by the LuaRocks rocks_trees. Using --full includes any other components " ..
32 "defined in your system's package.(c)path, either via the running interpreter's " .. 39 "defined in your system's package.(c)path, either via the running interpreter's " ..
33 "default paths or via LUA_(C)PATH(_5_x) environment variables (in short, using " .. 40 "default paths or via LUA_(C)PATH(_5_x) environment variables (in short, using " ..
34 "--full produces the same lists as shown in the shell outputs of 'luarocks path').") 41 "--full produces the same lists as shown in the shell outputs of 'luarocks path').")
35 cmd:flag("--lr-bin", "Exports the system path (not formatted as shell command).") 42 cmd:flag("--lr-bin", "Exports the system path (not formatted as shell command).")
36 cmd:flag("--bin"):hidden(true) 43 cmd:flag("--bin"):hidden(true)
37end 44end
38 45
39--- Driver function for "path" command. 46
40-- @return boolean This function always succeeds. 47
41function path_cmd.command(args) 48function path_cmd.command(args)
42 local lr_path, lr_cpath, lr_bin = cfg.package_paths(args.tree) 49 local lr_path, lr_cpath, lr_bin = cfg.package_paths(args.tree)
43 local path_sep = cfg.export_path_separator 50 local path_sep = cfg.export_path_separator
44 51
45 local full_list = ((not args.lr_path) and (not args.lr_cpath) and (not args.lr_bin)) 52 local full_list = ((not args.lr_path) and (not args.lr_cpath) and (not args.lr_bin)) or
46 or args.full 53 args.full
47 54
48 local clean_path = util.cleanup_path(os.getenv("PATH") or "", path_sep, nil, true) 55 local clean_path = util.cleanup_path(os.getenv("PATH") or "", path_sep, nil, true)
49 56
@@ -53,7 +60,7 @@ function path_cmd.command(args)
53 lr_cpath = package.cpath .. ";" .. lr_cpath 60 lr_cpath = package.cpath .. ";" .. lr_cpath
54 lr_bin = clean_path .. path_sep .. lr_bin 61 lr_bin = clean_path .. path_sep .. lr_bin
55 else 62 else
56 lr_path = lr_path.. ";" .. package.path 63 lr_path = lr_path .. ";" .. package.path
57 lr_cpath = lr_cpath .. ";" .. package.cpath 64 lr_cpath = lr_cpath .. ";" .. package.cpath
58 lr_bin = lr_bin .. path_sep .. clean_path 65 lr_bin = lr_bin .. path_sep .. clean_path
59 end 66 end
diff --git a/src/luarocks/cmd/purge-original.lua b/src/luarocks/cmd/purge-original.lua
new file mode 100644
index 00000000..fda8ab88
--- /dev/null
+++ b/src/luarocks/cmd/purge-original.lua
@@ -0,0 +1,72 @@
1
2--- Module implementing the LuaRocks "purge" command.
3-- Remove all rocks from a given tree.
4local purge = {}
5
6local util = require("luarocks.util")
7local path = require("luarocks.path")
8local search = require("luarocks.search")
9local vers = require("luarocks.core.vers")
10local repo_writer = require("luarocks.repo_writer")
11local cfg = require("luarocks.core.cfg")
12local remove = require("luarocks.remove")
13local queries = require("luarocks.queries")
14
15function purge.add_to_parser(parser)
16 -- luacheck: push ignore 431
17 local cmd = parser:command("purge", [[
18This command removes rocks en masse from a given tree.
19By default, it removes all rocks from a tree.
20
21The --tree option is mandatory: luarocks purge does not assume a default tree.]],
22 util.see_also())
23 :summary("Remove all installed rocks from a tree.")
24 -- luacheck: pop
25
26 cmd:flag("--old-versions", "Keep the highest-numbered version of each "..
27 "rock and remove the other ones. By default it only removes old "..
28 "versions if they are not needed as dependencies. This can be "..
29 "overridden with the flag --force.")
30 cmd:flag("--force", "If --old-versions is specified, force removal of "..
31 "previously installed versions if it would break dependencies.")
32 cmd:flag("--force-fast", "Like --force, but performs a forced removal "..
33 "without reporting dependency issues.")
34end
35
36function purge.command(args)
37 local tree = args.tree
38
39 local results = {}
40 search.local_manifest_search(results, path.rocks_dir(tree), queries.all())
41
42 local sort = function(a,b) return vers.compare_versions(b,a) end
43 if args.old_versions then
44 sort = vers.compare_versions
45 end
46
47 for package, versions in util.sortedpairs(results) do
48 for version, _ in util.sortedpairs(versions, sort) do
49 if args.old_versions then
50 util.printout("Keeping "..package.." "..version.."...")
51 local ok, err, warn = remove.remove_other_versions(package, version, args.force, args.force_fast)
52 if not ok then
53 util.printerr(err)
54 elseif warn then
55 util.printerr(err)
56 end
57 break
58 else
59 util.printout("Removing "..package.." "..version.."...")
60 local ok, err = repo_writer.delete_version(package, version, "none", true)
61 if not ok then
62 util.printerr(err)
63 end
64 end
65 end
66 end
67 return repo_writer.refresh_manifest(cfg.rocks_dir)
68end
69
70purge.needs_lock = function() return true end
71
72return purge
diff --git a/src/luarocks/cmd/purge.lua b/src/luarocks/cmd/purge.lua
index fda8ab88..167587f0 100644
--- a/src/luarocks/cmd/purge.lua
+++ b/src/luarocks/cmd/purge.lua
@@ -1,8 +1,10 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local package = _tl_compat and _tl_compat.package or package
2
1 3
2--- Module implementing the LuaRocks "purge" command.
3-- Remove all rocks from a given tree.
4local purge = {} 4local purge = {}
5 5
6
7
6local util = require("luarocks.util") 8local util = require("luarocks.util")
7local path = require("luarocks.path") 9local path = require("luarocks.path")
8local search = require("luarocks.search") 10local search = require("luarocks.search")
@@ -12,25 +14,32 @@ local cfg = require("luarocks.core.cfg")
12local remove = require("luarocks.remove") 14local remove = require("luarocks.remove")
13local queries = require("luarocks.queries") 15local queries = require("luarocks.queries")
14 16
17local argparse = require("luarocks.vendor.argparse")
18
19
20
21
22
23
15function purge.add_to_parser(parser) 24function purge.add_to_parser(parser)
16 -- luacheck: push ignore 431 25
17 local cmd = parser:command("purge", [[ 26 local cmd = parser:command("purge", [[
18This command removes rocks en masse from a given tree. 27This command removes rocks en masse from a given tree.
19By default, it removes all rocks from a tree. 28By default, it removes all rocks from a tree.
20 29
21The --tree option is mandatory: luarocks purge does not assume a default tree.]], 30The --tree option is mandatory: luarocks purge does not assume a default tree.]],
22 util.see_also()) 31 util.see_also()):
23 :summary("Remove all installed rocks from a tree.") 32 summary("Remove all installed rocks from a tree.")
24 -- luacheck: pop 33
25 34
26 cmd:flag("--old-versions", "Keep the highest-numbered version of each ".. 35 cmd:flag("--old-versions", "Keep the highest-numbered version of each " ..
27 "rock and remove the other ones. By default it only removes old ".. 36 "rock and remove the other ones. By default it only removes old " ..
28 "versions if they are not needed as dependencies. This can be ".. 37 "versions if they are not needed as dependencies. This can be " ..
29 "overridden with the flag --force.") 38 "overridden with the flag --force.")
30 cmd:flag("--force", "If --old-versions is specified, force removal of ".. 39 cmd:flag("--force", "If --old-versions is specified, force removal of " ..
31 "previously installed versions if it would break dependencies.") 40 "previously installed versions if it would break dependencies.")
32 cmd:flag("--force-fast", "Like --force, but performs a forced removal ".. 41 cmd:flag("--force-fast", "Like --force, but performs a forced removal " ..
33 "without reporting dependency issues.") 42 "without reporting dependency issues.")
34end 43end
35 44
36function purge.command(args) 45function purge.command(args)
@@ -39,7 +48,7 @@ function purge.command(args)
39 local results = {} 48 local results = {}
40 search.local_manifest_search(results, path.rocks_dir(tree), queries.all()) 49 search.local_manifest_search(results, path.rocks_dir(tree), queries.all())
41 50
42 local sort = function(a,b) return vers.compare_versions(b,a) end 51 local sort = function(a, b) return vers.compare_versions(b, a) end
43 if args.old_versions then 52 if args.old_versions then
44 sort = vers.compare_versions 53 sort = vers.compare_versions
45 end 54 end
@@ -47,7 +56,7 @@ function purge.command(args)
47 for package, versions in util.sortedpairs(results) do 56 for package, versions in util.sortedpairs(results) do
48 for version, _ in util.sortedpairs(versions, sort) do 57 for version, _ in util.sortedpairs(versions, sort) do
49 if args.old_versions then 58 if args.old_versions then
50 util.printout("Keeping "..package.." "..version.."...") 59 util.printout("Keeping " .. package .. " " .. version .. "...")
51 local ok, err, warn = remove.remove_other_versions(package, version, args.force, args.force_fast) 60 local ok, err, warn = remove.remove_other_versions(package, version, args.force, args.force_fast)
52 if not ok then 61 if not ok then
53 util.printerr(err) 62 util.printerr(err)
@@ -56,7 +65,7 @@ function purge.command(args)
56 end 65 end
57 break 66 break
58 else 67 else
59 util.printout("Removing "..package.." "..version.."...") 68 util.printout("Removing " .. package .. " " .. version .. "...")
60 local ok, err = repo_writer.delete_version(package, version, "none", true) 69 local ok, err = repo_writer.delete_version(package, version, "none", true)
61 if not ok then 70 if not ok then
62 util.printerr(err) 71 util.printerr(err)
diff --git a/src/luarocks/cmd/remove-original.lua b/src/luarocks/cmd/remove-original.lua
new file mode 100644
index 00000000..630303ca
--- /dev/null
+++ b/src/luarocks/cmd/remove-original.lua
@@ -0,0 +1,71 @@
1
2--- Module implementing the LuaRocks "remove" command.
3-- Uninstalls rocks.
4local cmd_remove = {}
5
6local remove = require("luarocks.remove")
7local util = require("luarocks.util")
8local cfg = require("luarocks.core.cfg")
9local search = require("luarocks.search")
10local path = require("luarocks.path")
11local deps = require("luarocks.deps")
12local queries = require("luarocks.queries")
13
14function cmd_remove.add_to_parser(parser)
15 -- luacheck: push ignore 431
16 local cmd = parser:command("remove", [[
17Uninstall a rock.
18
19If a version is not given, try to remove all versions at once.
20Will only perform the removal if it does not break dependencies.
21To override this check and force the removal, use --force or --force-fast.]],
22 util.see_also())
23 :summary("Uninstall a rock.")
24 -- luacheck: pop
25
26 cmd:argument("rock", "Name of the rock to be uninstalled.")
27 :action(util.namespaced_name_action)
28 cmd:argument("version", "Version of the rock to uninstall.")
29 :args("?")
30
31 cmd:flag("--force", "Force removal if it would break dependencies.")
32 cmd:flag("--force-fast", "Perform a forced removal without reporting dependency issues.")
33 util.deps_mode_option(cmd)
34end
35
36--- Driver function for the "remove" command.
37-- @return boolean or (nil, string, exitcode): True if removal was
38-- successful, nil and an error message otherwise. exitcode is optionally returned.
39function cmd_remove.command(args)
40 local name = args.rock
41 local deps_mode = deps.get_deps_mode(args)
42
43 local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$")
44 local version = args.version
45 local filename = name
46 if rock_type then
47 name, version = path.parse_name(filename)
48 if not name then return nil, "Invalid "..rock_type.." filename: "..filename end
49 end
50
51 name = name:lower()
52
53 local results = {}
54 search.local_manifest_search(results, cfg.rocks_dir, queries.new(name, args.namespace, version))
55 if not results[name] then
56 local rock = util.format_rock_name(name, args.namespace, version)
57 return nil, "Could not find rock '"..rock.."' in "..path.rocks_tree_to_string(cfg.root_dir)
58 end
59
60 local ok, err = remove.remove_search_results(results, name, deps_mode, args.force, args.force_fast)
61 if not ok then
62 return nil, err
63 end
64
65 deps.check_dependencies(nil, deps.get_deps_mode(args))
66 return true
67end
68
69cmd_remove.needs_lock = function() return true end
70
71return cmd_remove
diff --git a/src/luarocks/cmd/remove.lua b/src/luarocks/cmd/remove.lua
index 630303ca..c62610d4 100644
--- a/src/luarocks/cmd/remove.lua
+++ b/src/luarocks/cmd/remove.lua
@@ -1,8 +1,10 @@
1 1
2--- Module implementing the LuaRocks "remove" command. 2
3-- Uninstalls rocks. 3
4local cmd_remove = {} 4local cmd_remove = {}
5 5
6
7
6local remove = require("luarocks.remove") 8local remove = require("luarocks.remove")
7local util = require("luarocks.util") 9local util = require("luarocks.util")
8local cfg = require("luarocks.core.cfg") 10local cfg = require("luarocks.core.cfg")
@@ -11,31 +13,37 @@ local path = require("luarocks.path")
11local deps = require("luarocks.deps") 13local deps = require("luarocks.deps")
12local queries = require("luarocks.queries") 14local queries = require("luarocks.queries")
13 15
16local argparse = require("luarocks.vendor.argparse")
17
18
19
20
21
14function cmd_remove.add_to_parser(parser) 22function cmd_remove.add_to_parser(parser)
15 -- luacheck: push ignore 431 23
16 local cmd = parser:command("remove", [[ 24 local cmd = parser:command("remove", [[
17Uninstall a rock. 25Uninstall a rock.
18 26
19If a version is not given, try to remove all versions at once. 27If a version is not given, try to remove all versions at once.
20Will only perform the removal if it does not break dependencies. 28Will only perform the removal if it does not break dependencies.
21To override this check and force the removal, use --force or --force-fast.]], 29To override this check and force the removal, use --force or --force-fast.]],
22 util.see_also()) 30 util.see_also()):
23 :summary("Uninstall a rock.") 31 summary("Uninstall a rock.")
24 -- luacheck: pop 32
25 33
26 cmd:argument("rock", "Name of the rock to be uninstalled.") 34 cmd:argument("rock", "Name of the rock to be uninstalled."):
27 :action(util.namespaced_name_action) 35 action(util.namespaced_name_action)
28 cmd:argument("version", "Version of the rock to uninstall.") 36 cmd:argument("version", "Version of the rock to uninstall."):
29 :args("?") 37 args("?")
30 38
31 cmd:flag("--force", "Force removal if it would break dependencies.") 39 cmd:flag("--force", "Force removal if it would break dependencies.")
32 cmd:flag("--force-fast", "Perform a forced removal without reporting dependency issues.") 40 cmd:flag("--force-fast", "Perform a forced removal without reporting dependency issues.")
33 util.deps_mode_option(cmd) 41 util.deps_mode_option(cmd)
34end 42end
35 43
36--- Driver function for the "remove" command. 44
37-- @return boolean or (nil, string, exitcode): True if removal was 45
38-- successful, nil and an error message otherwise. exitcode is optionally returned. 46
39function cmd_remove.command(args) 47function cmd_remove.command(args)
40 local name = args.rock 48 local name = args.rock
41 local deps_mode = deps.get_deps_mode(args) 49 local deps_mode = deps.get_deps_mode(args)
@@ -45,7 +53,7 @@ function cmd_remove.command(args)
45 local filename = name 53 local filename = name
46 if rock_type then 54 if rock_type then
47 name, version = path.parse_name(filename) 55 name, version = path.parse_name(filename)
48 if not name then return nil, "Invalid "..rock_type.." filename: "..filename end 56 if not name then return nil, "Invalid " .. rock_type .. " filename: " .. filename end
49 end 57 end
50 58
51 name = name:lower() 59 name = name:lower()
@@ -54,7 +62,7 @@ function cmd_remove.command(args)
54 search.local_manifest_search(results, cfg.rocks_dir, queries.new(name, args.namespace, version)) 62 search.local_manifest_search(results, cfg.rocks_dir, queries.new(name, args.namespace, version))
55 if not results[name] then 63 if not results[name] then
56 local rock = util.format_rock_name(name, args.namespace, version) 64 local rock = util.format_rock_name(name, args.namespace, version)
57 return nil, "Could not find rock '"..rock.."' in "..path.rocks_tree_to_string(cfg.root_dir) 65 return nil, "Could not find rock '" .. rock .. "' in " .. path.rocks_tree_to_string(cfg.root_dir)
58 end 66 end
59 67
60 local ok, err = remove.remove_search_results(results, name, deps_mode, args.force, args.force_fast) 68 local ok, err = remove.remove_search_results(results, name, deps_mode, args.force, args.force_fast)
diff --git a/src/luarocks/cmd/search-original.lua b/src/luarocks/cmd/search-original.lua
new file mode 100644
index 00000000..6cab6d80
--- /dev/null
+++ b/src/luarocks/cmd/search-original.lua
@@ -0,0 +1,84 @@
1
2--- Module implementing the LuaRocks "search" command.
3-- Queries LuaRocks servers.
4local cmd_search = {}
5
6local cfg = require("luarocks.core.cfg")
7local util = require("luarocks.util")
8local search = require("luarocks.search")
9local queries = require("luarocks.queries")
10local results = require("luarocks.results")
11
12function cmd_search.add_to_parser(parser)
13 local cmd = parser:command("search", "Query the LuaRocks servers.", util.see_also())
14
15 cmd:argument("name", "Name of the rock to search for.")
16 :args("?")
17 :action(util.namespaced_name_action)
18 cmd:argument("version", "Rock version to search for.")
19 :args("?")
20
21 cmd:flag("--source", "Return only rockspecs and source rocks, to be used "..
22 'with the "build" command.')
23 cmd:flag("--binary", "Return only pure Lua and binary rocks (rocks that "..
24 'can be used with the "install" command without requiring a C toolchain).')
25 cmd:flag("--all", "List all contents of the server that are suitable to "..
26 "this platform, do not filter by name.")
27 cmd:flag("--porcelain", "Return a machine readable format.")
28end
29
30--- Splits a list of search results into two lists, one for "source" results
31-- to be used with the "build" command, and one for "binary" results to be
32-- used with the "install" command.
33-- @param result_tree table: A search results table.
34-- @return (table, table): Two tables, one for source and one for binary
35-- results.
36local function split_source_and_binary_results(result_tree)
37 local sources, binaries = {}, {}
38 for name, versions in pairs(result_tree) do
39 for version, repositories in pairs(versions) do
40 for _, repo in ipairs(repositories) do
41 local where = sources
42 if repo.arch == "all" or repo.arch == cfg.arch then
43 where = binaries
44 end
45 local entry = results.new(name, version, repo.repo, repo.arch)
46 search.store_result(where, entry)
47 end
48 end
49 end
50 return sources, binaries
51end
52
53--- Driver function for "search" command.
54-- @return boolean or (nil, string): True if build was successful; nil and an
55-- error message otherwise.
56function cmd_search.command(args)
57 local name = args.name
58
59 if args.all then
60 name, args.version = "", nil
61 end
62
63 if not args.name and not args.all then
64 return nil, "Enter name and version or use --all. "..util.see_help("search")
65 end
66
67 local query = queries.new(name, args.namespace, args.version, true)
68 local result_tree, err = search.search_repos(query)
69 local porcelain = args.porcelain
70 local full_name = util.format_rock_name(name, args.namespace, args.version)
71 util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=")
72 local sources, binaries = split_source_and_binary_results(result_tree)
73 if next(sources) and not args.binary then
74 util.title("Rockspecs and source rocks:", porcelain)
75 search.print_result_tree(sources, porcelain)
76 end
77 if next(binaries) and not args.source then
78 util.title("Binary and pure-Lua rocks:", porcelain)
79 search.print_result_tree(binaries, porcelain)
80 end
81 return true
82end
83
84return cmd_search
diff --git a/src/luarocks/cmd/search.lua b/src/luarocks/cmd/search.lua
index 6cab6d80..a7569c27 100644
--- a/src/luarocks/cmd/search.lua
+++ b/src/luarocks/cmd/search.lua
@@ -1,38 +1,48 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs
2
1 3
2--- Module implementing the LuaRocks "search" command.
3-- Queries LuaRocks servers.
4local cmd_search = {} 4local cmd_search = {}
5 5
6
6local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
7local util = require("luarocks.util") 8local util = require("luarocks.util")
8local search = require("luarocks.search") 9local search = require("luarocks.search")
9local queries = require("luarocks.queries") 10local queries = require("luarocks.queries")
10local results = require("luarocks.results") 11local results = require("luarocks.results")
11 12
13local argparse = require("luarocks.vendor.argparse")
14
15
16
17
18
19
20
21
12function cmd_search.add_to_parser(parser) 22function cmd_search.add_to_parser(parser)
13 local cmd = parser:command("search", "Query the LuaRocks servers.", util.see_also()) 23 local cmd = parser:command("search", "Query the LuaRocks servers.", util.see_also())
14 24
15 cmd:argument("name", "Name of the rock to search for.") 25 cmd:argument("name", "Name of the rock to search for."):
16 :args("?") 26 args("?"):
17 :action(util.namespaced_name_action) 27 action(util.namespaced_name_action)
18 cmd:argument("version", "Rock version to search for.") 28 cmd:argument("version", "Rock version to search for."):
19 :args("?") 29 args("?")
20 30
21 cmd:flag("--source", "Return only rockspecs and source rocks, to be used ".. 31 cmd:flag("--source", "Return only rockspecs and source rocks, to be used " ..
22 'with the "build" command.') 32 'with the "build" command.')
23 cmd:flag("--binary", "Return only pure Lua and binary rocks (rocks that ".. 33 cmd:flag("--binary", "Return only pure Lua and binary rocks (rocks that " ..
24 'can be used with the "install" command without requiring a C toolchain).') 34 'can be used with the "install" command without requiring a C toolchain).')
25 cmd:flag("--all", "List all contents of the server that are suitable to ".. 35 cmd:flag("--all", "List all contents of the server that are suitable to " ..
26 "this platform, do not filter by name.") 36 "this platform, do not filter by name.")
27 cmd:flag("--porcelain", "Return a machine readable format.") 37 cmd:flag("--porcelain", "Return a machine readable format.")
28end 38end
29 39
30--- Splits a list of search results into two lists, one for "source" results 40
31-- to be used with the "build" command, and one for "binary" results to be 41
32-- used with the "install" command. 42
33-- @param result_tree table: A search results table. 43
34-- @return (table, table): Two tables, one for source and one for binary 44
35-- results. 45
36local function split_source_and_binary_results(result_tree) 46local function split_source_and_binary_results(result_tree)
37 local sources, binaries = {}, {} 47 local sources, binaries = {}, {}
38 for name, versions in pairs(result_tree) do 48 for name, versions in pairs(result_tree) do
@@ -50,9 +60,9 @@ local function split_source_and_binary_results(result_tree)
50 return sources, binaries 60 return sources, binaries
51end 61end
52 62
53--- Driver function for "search" command. 63
54-- @return boolean or (nil, string): True if build was successful; nil and an 64
55-- error message otherwise. 65
56function cmd_search.command(args) 66function cmd_search.command(args)
57 local name = args.name 67 local name = args.name
58 68
@@ -61,14 +71,14 @@ function cmd_search.command(args)
61 end 71 end
62 72
63 if not args.name and not args.all then 73 if not args.name and not args.all then
64 return nil, "Enter name and version or use --all. "..util.see_help("search") 74 return nil, "Enter name and version or use --all. " .. util.see_help("search")
65 end 75 end
66 76
67 local query = queries.new(name, args.namespace, args.version, true) 77 local query = queries.new(name, args.namespace, args.version, true)
68 local result_tree, err = search.search_repos(query) 78 local result_tree = search.search_repos(query)
69 local porcelain = args.porcelain 79 local porcelain = args.porcelain
70 local full_name = util.format_rock_name(name, args.namespace, args.version) 80 local full_name = util.format_rock_name(name, args.namespace, args.version)
71 util.title(full_name .. " - Search results for Lua "..cfg.lua_version..":", porcelain, "=") 81 util.title(full_name .. " - Search results for Lua " .. cfg.lua_version .. ":", porcelain, "=")
72 local sources, binaries = split_source_and_binary_results(result_tree) 82 local sources, binaries = split_source_and_binary_results(result_tree)
73 if next(sources) and not args.binary then 83 if next(sources) and not args.binary then
74 util.title("Rockspecs and source rocks:", porcelain) 84 util.title("Rockspecs and source rocks:", porcelain)
diff --git a/src/luarocks/cmd/test-original.lua b/src/luarocks/cmd/test-original.lua
new file mode 100644
index 00000000..b353bd80
--- /dev/null
+++ b/src/luarocks/cmd/test-original.lua
@@ -0,0 +1,48 @@
1
2--- Module implementing the LuaRocks "test" command.
3-- Tests a rock, compiling its C parts if any.
4local cmd_test = {}
5
6local util = require("luarocks.util")
7local test = require("luarocks.test")
8
9function cmd_test.add_to_parser(parser)
10 local cmd = parser:command("test", [[
11Run the test suite for the Lua project in the current directory.
12
13If the first argument is a rockspec, it will use it to determine the parameters
14for running tests; otherwise, it will attempt to detect the rockspec.
15
16Any additional arguments are forwarded to the test suite.
17To make sure that test suite flags are not interpreted as LuaRocks flags, use --
18to separate LuaRocks arguments from test suite arguments.]],
19 util.see_also())
20 :summary("Run the test suite in the current directory.")
21
22 cmd:argument("rockspec", "Project rockspec.")
23 :args("?")
24 cmd:argument("args", "Test suite arguments.")
25 :args("*")
26 cmd:flag("--prepare", "Only install dependencies needed for testing only, but do not run the test")
27
28 cmd:option("--test-type", "Specify the test suite type manually if it was "..
29 "not specified in the rockspec and it could not be auto-detected.")
30 :argname("<type>")
31end
32
33function cmd_test.command(args)
34 if args.rockspec and args.rockspec:match("rockspec$") then
35 return test.run_test_suite(args.rockspec, args.test_type, args.args, args.prepare)
36 end
37
38 table.insert(args.args, 1, args.rockspec)
39
40 local rockspec, err = util.get_default_rockspec()
41 if not rockspec then
42 return nil, err
43 end
44
45 return test.run_test_suite(rockspec, args.test_type, args.args, args.prepare)
46end
47
48return cmd_test
diff --git a/src/luarocks/cmd/test.lua b/src/luarocks/cmd/test.lua
index b353bd80..22e91366 100644
--- a/src/luarocks/cmd/test.lua
+++ b/src/luarocks/cmd/test.lua
@@ -1,11 +1,18 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local table = _tl_compat and _tl_compat.table or table
2
1 3
2--- Module implementing the LuaRocks "test" command.
3-- Tests a rock, compiling its C parts if any.
4local cmd_test = {} 4local cmd_test = {}
5 5
6
6local util = require("luarocks.util") 7local util = require("luarocks.util")
7local test = require("luarocks.test") 8local test = require("luarocks.test")
8 9
10local argparse = require("luarocks.vendor.argparse")
11
12
13
14
15
9function cmd_test.add_to_parser(parser) 16function cmd_test.add_to_parser(parser)
10 local cmd = parser:command("test", [[ 17 local cmd = parser:command("test", [[
11Run the test suite for the Lua project in the current directory. 18Run the test suite for the Lua project in the current directory.
@@ -16,18 +23,18 @@ for running tests; otherwise, it will attempt to detect the rockspec.
16Any additional arguments are forwarded to the test suite. 23Any additional arguments are forwarded to the test suite.
17To make sure that test suite flags are not interpreted as LuaRocks flags, use -- 24To make sure that test suite flags are not interpreted as LuaRocks flags, use --
18to separate LuaRocks arguments from test suite arguments.]], 25to separate LuaRocks arguments from test suite arguments.]],
19 util.see_also()) 26 util.see_also()):
20 :summary("Run the test suite in the current directory.") 27 summary("Run the test suite in the current directory.")
21 28
22 cmd:argument("rockspec", "Project rockspec.") 29 cmd:argument("rockspec", "Project rockspec."):
23 :args("?") 30 args("?")
24 cmd:argument("args", "Test suite arguments.") 31 cmd:argument("args", "Test suite arguments."):
25 :args("*") 32 args("*")
26 cmd:flag("--prepare", "Only install dependencies needed for testing only, but do not run the test") 33 cmd:flag("--prepare", "Only install dependencies needed for testing only, but do not run the test")
27 34
28 cmd:option("--test-type", "Specify the test suite type manually if it was ".. 35 cmd:option("--test-type", "Specify the test suite type manually if it was " ..
29 "not specified in the rockspec and it could not be auto-detected.") 36 "not specified in the rockspec and it could not be auto-detected."):
30 :argname("<type>") 37 argname("<type>")
31end 38end
32 39
33function cmd_test.command(args) 40function cmd_test.command(args)
diff --git a/src/luarocks/cmd/unpack-original.lua b/src/luarocks/cmd/unpack-original.lua
new file mode 100644
index 00000000..a0ade4f3
--- /dev/null
+++ b/src/luarocks/cmd/unpack-original.lua
@@ -0,0 +1,169 @@
1
2--- Module implementing the LuaRocks "unpack" command.
3-- Unpack the contents of a rock.
4local unpack = {}
5
6local fetch = require("luarocks.fetch")
7local fs = require("luarocks.fs")
8local util = require("luarocks.util")
9local build = require("luarocks.build")
10local dir = require("luarocks.dir")
11local search = require("luarocks.search")
12
13function unpack.add_to_parser(parser)
14 local cmd = parser:command("unpack", [[
15Unpacks the contents of a rock in a newly created directory.
16Argument may be a rock file, or the name of a rock in a rocks server.
17In the latter case, the rock version may be given as a second argument.]],
18 util.see_also())
19 :summary("Unpack the contents of a rock.")
20
21 cmd:argument("rock", "A rock file or the name of a rock.")
22 :action(util.namespaced_name_action)
23 cmd:argument("version", "Rock version.")
24 :args("?")
25
26 cmd:flag("--force", "Unpack files even if the output directory already exists.")
27 cmd:flag("--check-lua-versions", "If the rock can't be found, check repository "..
28 "and report if it is available for another Lua version.")
29end
30
31--- Load a rockspec file to the given directory, fetches the source
32-- files specified in the rockspec, and unpack them inside the directory.
33-- @param rockspec_file string: The URL for a rockspec file.
34-- @param dir_name string: The directory where to store and unpack files.
35-- @return table or (nil, string): the loaded rockspec table or
36-- nil and an error message.
37local function unpack_rockspec(rockspec_file, dir_name)
38 assert(type(rockspec_file) == "string")
39 assert(type(dir_name) == "string")
40
41 local rockspec, err = fetch.load_rockspec(rockspec_file)
42 if not rockspec then
43 return nil, "Failed loading rockspec "..rockspec_file..": "..err
44 end
45 local ok, err = fs.change_dir(dir_name)
46 if not ok then return nil, err end
47 local ok, sources_dir = fetch.fetch_sources(rockspec, true, ".")
48 if not ok then
49 return nil, sources_dir
50 end
51 ok, err = fs.change_dir(sources_dir)
52 if not ok then return nil, err end
53 ok, err = build.apply_patches(rockspec)
54 fs.pop_dir()
55 if not ok then return nil, err end
56 return rockspec
57end
58
59--- Load a .rock file to the given directory and unpack it inside it.
60-- @param rock_file string: The URL for a .rock file.
61-- @param dir_name string: The directory where to unpack.
62-- @param kind string: the kind of rock file, as in the second-level
63-- extension in the rock filename (eg. "src", "all", "linux-x86")
64-- @return table or (nil, string): the loaded rockspec table or
65-- nil and an error message.
66local function unpack_rock(rock_file, dir_name, kind)
67 assert(type(rock_file) == "string")
68 assert(type(dir_name) == "string")
69
70 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name)
71 if not ok then
72 return nil, err, errcode
73 end
74 ok, err = fs.change_dir(dir_name)
75 if not ok then return nil, err end
76 local rockspec_file = dir_name..".rockspec"
77 local rockspec, err = fetch.load_rockspec(rockspec_file)
78 if not rockspec then
79 return nil, "Failed loading rockspec "..rockspec_file..": "..err
80 end
81 if kind == "src" then
82 if rockspec.source.file then
83 local ok, err = fs.unpack_archive(rockspec.source.file)
84 if not ok then return nil, err end
85 ok, err = fetch.find_rockspec_source_dir(rockspec, ".")
86 if not ok then return nil, err end
87 ok, err = fs.change_dir(rockspec.source.dir)
88 if not ok then return nil, err end
89 ok, err = build.apply_patches(rockspec)
90 fs.pop_dir()
91 if not ok then return nil, err end
92 end
93 end
94 return rockspec
95end
96
97--- Create a directory and perform the necessary actions so that
98-- the sources for the rock and its rockspec are unpacked inside it,
99-- laid out properly so that the 'make' command is able to build the module.
100-- @param file string: A rockspec or .rock URL.
101-- @return boolean or (nil, string): true if successful or nil followed
102-- by an error message.
103local function run_unpacker(file, force)
104 assert(type(file) == "string")
105
106 local base_name = dir.base_name(file)
107 local dir_name, kind, extension = base_name:match("(.*)%.([^.]+)%.(rock)$")
108 if not extension then
109 dir_name, extension = base_name:match("(.*)%.(rockspec)$")
110 kind = "rockspec"
111 end
112 if not extension then
113 return nil, file.." does not seem to be a valid filename."
114 end
115
116 local exists = fs.exists(dir_name)
117 if exists and not force then
118 return nil, "Directory "..dir_name.." already exists."
119 end
120 if not exists then
121 local ok, err = fs.make_dir(dir_name)
122 if not ok then return nil, err end
123 end
124 local rollback = util.schedule_function(fs.delete, fs.absolute_name(dir_name))
125
126 local rockspec, err
127 if extension == "rock" then
128 rockspec, err = unpack_rock(file, dir_name, kind)
129 elseif extension == "rockspec" then
130 rockspec, err = unpack_rockspec(file, dir_name)
131 end
132 if not rockspec then
133 return nil, err
134 end
135 if kind == "src" or kind == "rockspec" then
136 fetch.find_rockspec_source_dir(rockspec, ".")
137 if rockspec.source.dir ~= "." then
138 local ok = fs.copy(rockspec.local_abs_filename, rockspec.source.dir, "read")
139 if not ok then
140 return nil, "Failed copying unpacked rockspec into unpacked source directory."
141 end
142 end
143 util.printout()
144 util.printout("Done. You may now enter directory ")
145 util.printout(dir.path(dir_name, rockspec.source.dir))
146 util.printout("and type 'luarocks make' to build.")
147 end
148 util.remove_scheduled_function(rollback)
149 return true
150end
151
152--- Driver function for the "unpack" command.
153-- @return boolean or (nil, string): true if successful or nil followed
154-- by an error message.
155function unpack.command(args)
156 local url, err
157 if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then
158 url = args.rock
159 else
160 url, err = search.find_src_or_rockspec(args.rock, args.namespace, args.version, args.check_lua_versions)
161 if not url then
162 return nil, err
163 end
164 end
165
166 return run_unpacker(url, args.force)
167end
168
169return unpack
diff --git a/src/luarocks/cmd/unpack.lua b/src/luarocks/cmd/unpack.lua
index a0ade4f3..1ed9a2f5 100644
--- a/src/luarocks/cmd/unpack.lua
+++ b/src/luarocks/cmd/unpack.lua
@@ -1,8 +1,9 @@
1 1
2--- Module implementing the LuaRocks "unpack" command. 2
3-- Unpack the contents of a rock. 3
4local unpack = {} 4local unpack = {}
5 5
6
6local fetch = require("luarocks.fetch") 7local fetch = require("luarocks.fetch")
7local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
8local util = require("luarocks.util") 9local util = require("luarocks.util")
@@ -10,42 +11,49 @@ local build = require("luarocks.build")
10local dir = require("luarocks.dir") 11local dir = require("luarocks.dir")
11local search = require("luarocks.search") 12local search = require("luarocks.search")
12 13
14local argparse = require("luarocks.vendor.argparse")
15
16
17
18
19
20
21
22
13function unpack.add_to_parser(parser) 23function unpack.add_to_parser(parser)
14 local cmd = parser:command("unpack", [[ 24 local cmd = parser:command("unpack", [[
15Unpacks the contents of a rock in a newly created directory. 25Unpacks the contents of a rock in a newly created directory.
16Argument may be a rock file, or the name of a rock in a rocks server. 26Argument may be a rock file, or the name of a rock in a rocks server.
17In the latter case, the rock version may be given as a second argument.]], 27In the latter case, the rock version may be given as a second argument.]],
18 util.see_also()) 28 util.see_also()):
19 :summary("Unpack the contents of a rock.") 29 summary("Unpack the contents of a rock.")
20 30
21 cmd:argument("rock", "A rock file or the name of a rock.") 31 cmd:argument("rock", "A rock file or the name of a rock."):
22 :action(util.namespaced_name_action) 32 action(util.namespaced_name_action)
23 cmd:argument("version", "Rock version.") 33 cmd:argument("version", "Rock version."):
24 :args("?") 34 args("?")
25 35
26 cmd:flag("--force", "Unpack files even if the output directory already exists.") 36 cmd:flag("--force", "Unpack files even if the output directory already exists.")
27 cmd:flag("--check-lua-versions", "If the rock can't be found, check repository ".. 37 cmd:flag("--check-lua-versions", "If the rock can't be found, check repository " ..
28 "and report if it is available for another Lua version.") 38 "and report if it is available for another Lua version.")
29end 39end
30 40
31--- Load a rockspec file to the given directory, fetches the source 41
32-- files specified in the rockspec, and unpack them inside the directory. 42
33-- @param rockspec_file string: The URL for a rockspec file. 43
34-- @param dir_name string: The directory where to store and unpack files. 44
35-- @return table or (nil, string): the loaded rockspec table or 45
36-- nil and an error message. 46
37local function unpack_rockspec(rockspec_file, dir_name) 47local function unpack_rockspec(rockspec_file, dir_name)
38 assert(type(rockspec_file) == "string")
39 assert(type(dir_name) == "string")
40 48
41 local rockspec, err = fetch.load_rockspec(rockspec_file) 49 local rockspec, err = fetch.load_rockspec(rockspec_file)
42 if not rockspec then 50 if not rockspec then
43 return nil, "Failed loading rockspec "..rockspec_file..": "..err 51 return nil, "Failed loading rockspec " .. rockspec_file .. ": " .. err
44 end 52 end
45 local ok, err = fs.change_dir(dir_name) 53 local ok, err = fs.change_dir(dir_name)
46 if not ok then return nil, err end 54 if not ok then return nil, err end
47 local ok, sources_dir = fetch.fetch_sources(rockspec, true, ".") 55 local oks, sources_dir = fetch.fetch_sources(rockspec, true, ".")
48 if not ok then 56 if not oks then
49 return nil, sources_dir 57 return nil, sources_dir
50 end 58 end
51 ok, err = fs.change_dir(sources_dir) 59 ok, err = fs.change_dir(sources_dir)
@@ -56,37 +64,35 @@ local function unpack_rockspec(rockspec_file, dir_name)
56 return rockspec 64 return rockspec
57end 65end
58 66
59--- Load a .rock file to the given directory and unpack it inside it. 67
60-- @param rock_file string: The URL for a .rock file. 68
61-- @param dir_name string: The directory where to unpack. 69
62-- @param kind string: the kind of rock file, as in the second-level 70
63-- extension in the rock filename (eg. "src", "all", "linux-x86") 71
64-- @return table or (nil, string): the loaded rockspec table or 72
65-- nil and an error message. 73
66local function unpack_rock(rock_file, dir_name, kind) 74local function unpack_rock(rock_file, dir_name, kind)
67 assert(type(rock_file) == "string")
68 assert(type(dir_name) == "string")
69 75
70 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name) 76 local ok, err, errcode = fetch.fetch_and_unpack_rock(rock_file, dir_name)
71 if not ok then 77 if not ok then
72 return nil, err, errcode 78 return nil, err, errcode
73 end 79 end
74 ok, err = fs.change_dir(dir_name) 80 local oks, errs = fs.change_dir(dir_name)
75 if not ok then return nil, err end 81 if not oks then return nil, errs end
76 local rockspec_file = dir_name..".rockspec" 82 local rockspec_file = dir_name .. ".rockspec"
77 local rockspec, err = fetch.load_rockspec(rockspec_file) 83 local rockspec, err = fetch.load_rockspec(rockspec_file)
78 if not rockspec then 84 if not rockspec then
79 return nil, "Failed loading rockspec "..rockspec_file..": "..err 85 return nil, "Failed loading rockspec " .. rockspec_file .. ": " .. err
80 end 86 end
81 if kind == "src" then 87 if kind == "src" then
82 if rockspec.source.file then 88 if rockspec.source.file then
83 local ok, err = fs.unpack_archive(rockspec.source.file) 89 oks, err = fs.unpack_archive(rockspec.source.file)
84 if not ok then return nil, err end 90 if not ok then return nil, err end
85 ok, err = fetch.find_rockspec_source_dir(rockspec, ".") 91 oks, err = fetch.find_rockspec_source_dir(rockspec, ".")
86 if not ok then return nil, err end 92 if not ok then return nil, err end
87 ok, err = fs.change_dir(rockspec.source.dir) 93 oks, err = fs.change_dir(rockspec.source.dir)
88 if not ok then return nil, err end 94 if not ok then return nil, err end
89 ok, err = build.apply_patches(rockspec) 95 oks, err = build.apply_patches(rockspec)
90 fs.pop_dir() 96 fs.pop_dir()
91 if not ok then return nil, err end 97 if not ok then return nil, err end
92 end 98 end
@@ -94,14 +100,13 @@ local function unpack_rock(rock_file, dir_name, kind)
94 return rockspec 100 return rockspec
95end 101end
96 102
97--- Create a directory and perform the necessary actions so that 103
98-- the sources for the rock and its rockspec are unpacked inside it, 104
99-- laid out properly so that the 'make' command is able to build the module. 105
100-- @param file string: A rockspec or .rock URL. 106
101-- @return boolean or (nil, string): true if successful or nil followed 107
102-- by an error message. 108
103local function run_unpacker(file, force) 109local function run_unpacker(file, force)
104 assert(type(file) == "string")
105 110
106 local base_name = dir.base_name(file) 111 local base_name = dir.base_name(file)
107 local dir_name, kind, extension = base_name:match("(.*)%.([^.]+)%.(rock)$") 112 local dir_name, kind, extension = base_name:match("(.*)%.([^.]+)%.(rock)$")
@@ -110,12 +115,12 @@ local function run_unpacker(file, force)
110 kind = "rockspec" 115 kind = "rockspec"
111 end 116 end
112 if not extension then 117 if not extension then
113 return nil, file.." does not seem to be a valid filename." 118 return nil, file .. " does not seem to be a valid filename."
114 end 119 end
115 120
116 local exists = fs.exists(dir_name) 121 local exists = fs.exists(dir_name)
117 if exists and not force then 122 if exists and not force then
118 return nil, "Directory "..dir_name.." already exists." 123 return nil, "Directory " .. dir_name .. " already exists."
119 end 124 end
120 if not exists then 125 if not exists then
121 local ok, err = fs.make_dir(dir_name) 126 local ok, err = fs.make_dir(dir_name)
@@ -149,9 +154,9 @@ local function run_unpacker(file, force)
149 return true 154 return true
150end 155end
151 156
152--- Driver function for the "unpack" command. 157
153-- @return boolean or (nil, string): true if successful or nil followed 158
154-- by an error message. 159
155function unpack.command(args) 160function unpack.command(args)
156 local url, err 161 local url, err
157 if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then 162 if args.rock:match(".*%.rock") or args.rock:match(".*%.rockspec") then
diff --git a/src/luarocks/cmd/write_rockspec-original.lua b/src/luarocks/cmd/write_rockspec-original.lua
new file mode 100644
index 00000000..871cdd44
--- /dev/null
+++ b/src/luarocks/cmd/write_rockspec-original.lua
@@ -0,0 +1,408 @@
1
2local write_rockspec = {}
3
4local builtin = require("luarocks.build.builtin")
5local cfg = require("luarocks.core.cfg")
6local dir = require("luarocks.dir")
7local fetch = require("luarocks.fetch")
8local fs = require("luarocks.fs")
9local persist = require("luarocks.persist")
10local rockspecs = require("luarocks.rockspecs")
11local type_rockspec = require("luarocks.type.rockspec")
12local util = require("luarocks.util")
13
14local lua_versions = {
15 "5.1",
16 "5.2",
17 "5.3",
18 "5.4",
19 "5.1,5.2",
20 "5.2,5.3",
21 "5.3,5.4",
22 "5.1,5.2,5.3",
23 "5.2,5.3,5.4",
24 "5.1,5.2,5.3,5.4"
25}
26
27function write_rockspec.cmd_options(parser)
28 return parser:option("--output", "Write the rockspec with the given filename.\n"..
29 "If not given, a file is written in the current directory with a "..
30 "filename based on given name and version.")
31 :argname("<file>"),
32 parser:option("--license", 'A license string, such as "MIT/X11" or "GNU GPL v3".')
33 :argname("<string>"),
34 parser:option("--summary", "A short one-line description summary.")
35 :argname("<txt>"),
36 parser:option("--detailed", "A longer description string.")
37 :argname("<txt>"),
38 parser:option("--homepage", "Project homepage.")
39 :argname("<txt>"),
40 parser:option("--lua-versions", 'Supported Lua versions. Accepted values are: "'..
41 table.concat(lua_versions, '", "')..'".')
42 :argname("<ver>")
43 :choices(lua_versions),
44 parser:option("--rockspec-format", 'Rockspec format version, such as "1.0" or "1.1".')
45 :argname("<ver>"),
46 parser:option("--tag", "Tag to use. Will attempt to extract version number from it."),
47 parser:option("--lib", "A comma-separated list of libraries that C files need to link to.")
48 :argname("<libs>")
49end
50
51function write_rockspec.add_to_parser(parser)
52 local cmd = parser:command("write_rockspec", [[
53This command writes an initial version of a rockspec file,
54based on a name, a version, and a location (an URL or a local path).
55If only two arguments are given, the first one is considered the name and the
56second one is the location.
57If only one argument is given, it must be the location.
58If no arguments are given, current directory is used as the location.
59LuaRocks will attempt to infer name and version if not given,
60using 'dev' as a fallback default version.
61
62Note that the generated file is a _starting point_ for writing a
63rockspec, and is not guaranteed to be complete or correct. ]], util.see_also())
64 :summary("Write a template for a rockspec file.")
65
66 cmd:argument("name", "Name of the rock.")
67 :args("?")
68 cmd:argument("version", "Rock version.")
69 :args("?")
70 cmd:argument("location", "URL or path to the rock sources.")
71 :args("?")
72
73 write_rockspec.cmd_options(cmd)
74end
75
76local function open_file(name)
77 return io.open(dir.path(fs.current_dir(), name), "r")
78end
79
80local function fetch_url(rockspec)
81 local file, temp_dir, err_code, err_file, err_temp_dir = fetch.fetch_sources(rockspec, false)
82 if err_code == "source.dir" then
83 file, temp_dir = err_file, err_temp_dir
84 elseif not file then
85 util.warning("Could not fetch sources - "..temp_dir)
86 return false
87 end
88 util.printout("File successfully downloaded. Making checksum and checking base dir...")
89 if dir.is_basic_protocol(rockspec.source.protocol) then
90 rockspec.source.md5 = fs.get_md5(file)
91 end
92 local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, rockspec.source.url)
93 return true, found_dir or inferred_dir, temp_dir
94end
95
96local lua_version_dep = {
97 ["5.1"] = "lua ~> 5.1",
98 ["5.2"] = "lua ~> 5.2",
99 ["5.3"] = "lua ~> 5.3",
100 ["5.4"] = "lua ~> 5.4",
101 ["5.1,5.2"] = "lua >= 5.1, < 5.3",
102 ["5.2,5.3"] = "lua >= 5.2, < 5.4",
103 ["5.3,5.4"] = "lua >= 5.3, < 5.5",
104 ["5.1,5.2,5.3"] = "lua >= 5.1, < 5.4",
105 ["5.2,5.3,5.4"] = "lua >= 5.2, < 5.5",
106 ["5.1,5.2,5.3,5.4"] = "lua >= 5.1, < 5.5",
107}
108
109local simple_scm_protocols = {
110 git = true,
111 ["git+http"] = true,
112 ["git+https"] = true,
113 ["git+ssh"] = true,
114 hg = true,
115 ["hg+http"] = true,
116 ["hg+https"] = true,
117 ["hg+ssh"] = true,
118}
119
120local detect_url
121do
122 local function detect_url_from_command(program, args, directory)
123 local command = fs.Q(cfg.variables[program:upper()]).. " "..args
124 local pipe = io.popen(fs.command_at(directory, fs.quiet_stderr(command)))
125 if not pipe then return nil end
126 local url = pipe:read("*a"):match("^([^\r\n]+)")
127 pipe:close()
128 if not url then return nil end
129 if url:match("^[^@:/]+@[^@:/]+:.*$") then
130 local u, h, p = url:match("^([^@]+)@([^:]+):(.*)$")
131 url = program.."+ssh://"..u.."@"..h.."/"..p
132 elseif not util.starts_with(url, program.."://") then
133 url = program.."+"..url
134 end
135
136 if simple_scm_protocols[dir.split_url(url)] then
137 return url
138 end
139 end
140
141 local function detect_scm_url(directory)
142 return detect_url_from_command("git", "config --get remote.origin.url", directory) or
143 detect_url_from_command("hg", "paths default", directory)
144 end
145
146 detect_url = function(url_or_dir)
147 if url_or_dir:match("://") then
148 return url_or_dir
149 else
150 return detect_scm_url(url_or_dir) or "*** please add URL for source tarball, zip or repository here ***"
151 end
152 end
153end
154
155local function detect_homepage(url, homepage)
156 if homepage then
157 return homepage
158 end
159 local url_protocol, url_path = dir.split_url(url)
160
161 if simple_scm_protocols[url_protocol] then
162 for _, domain in ipairs({"github.com", "bitbucket.org", "gitlab.com"}) do
163 if util.starts_with(url_path, domain) then
164 return "https://"..url_path:gsub("%.git$", "")
165 end
166 end
167 end
168
169 return "*** please enter a project homepage ***"
170end
171
172local function detect_description()
173 local fd = open_file("README.md") or open_file("README")
174 if not fd then return end
175 local data = fd:read("*a")
176 fd:close()
177 local paragraph = data:match("\n\n([^%[].-)\n\n")
178 if not paragraph then paragraph = data:match("\n\n(.*)") end
179 local summary, detailed
180 if paragraph then
181 detailed = paragraph
182
183 if #paragraph < 80 then
184 summary = paragraph:gsub("\n", "")
185 else
186 summary = paragraph:gsub("\n", " "):match("([^.]*%.) ")
187 end
188 end
189 return summary, detailed
190end
191
192local licenses = {
193 [78656] = "MIT",
194 [49311] = "ISC",
195}
196
197local function detect_license(data)
198 local strip_copyright = (data:gsub("^Copyright [^\n]*\n", ""))
199 local sum = 0
200 for i = 1, #strip_copyright do
201 local num = string.byte(strip_copyright:sub(i,i))
202 if num > 32 and num <= 128 then
203 sum = sum + num
204 end
205 end
206 return licenses[sum]
207end
208
209local function check_license()
210 local fd = open_file("COPYING") or open_file("LICENSE") or open_file("MIT-LICENSE.txt")
211 if not fd then return nil end
212 local data = fd:read("*a")
213 fd:close()
214 local license = detect_license(data)
215 if license then
216 return license, data
217 end
218 return nil, data
219end
220
221local function fill_as_builtin(rockspec, libs)
222 rockspec.build.type = "builtin"
223
224 local incdirs, libdirs
225 if libs then
226 incdirs, libdirs = {}, {}
227 for _, lib in ipairs(libs) do
228 local upper = lib:upper()
229 incdirs[#incdirs+1] = "$("..upper.."_INCDIR)"
230 libdirs[#libdirs+1] = "$("..upper.."_LIBDIR)"
231 end
232 end
233
234 rockspec.build.modules, rockspec.build.install, rockspec.build.copy_directories = builtin.autodetect_modules(libs, incdirs, libdirs)
235end
236
237local function rockspec_cleanup(rockspec)
238 rockspec.source.file = nil
239 rockspec.source.protocol = nil
240 rockspec.source.identifier = nil
241 rockspec.source.dir = nil
242 rockspec.source.dir_set = nil
243 rockspec.source.pathname = nil
244 rockspec.variables = nil
245 rockspec.name = nil
246 rockspec.format_is_at_least = nil
247 rockspec.local_abs_filename = nil
248 rockspec.rocks_provided = nil
249 for _, list in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do
250 if rockspec[list] and not next(rockspec[list]) then
251 rockspec[list] = nil
252 end
253 end
254 for _, list in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do
255 if rockspec[list] then
256 for i, entry in ipairs(rockspec[list]) do
257 rockspec[list][i] = tostring(entry)
258 end
259 end
260 end
261end
262
263function write_rockspec.command(args)
264 local name, version = args.name, args.version
265 local location = args.location
266
267 if not name then
268 location = "."
269 elseif not version then
270 location = name
271 name = nil
272 elseif not location then
273 location = version
274 version = nil
275 end
276
277 if args.tag then
278 if not version then
279 version = args.tag:gsub("^v", "")
280 end
281 end
282
283 local protocol, pathname = dir.split_url(location)
284 if protocol == "file" then
285 if pathname == "." then
286 name = name or dir.base_name(fs.current_dir())
287 end
288 elseif dir.is_basic_protocol(protocol) then
289 local filename = dir.base_name(location)
290 local newname, newversion = filename:match("(.*)-([^-]+)")
291 if newname then
292 name = name or newname
293 version = version or newversion:gsub("%.[a-z]+$", ""):gsub("%.tar$", "")
294 end
295 else
296 name = name or dir.base_name(location):gsub("%.[^.]+$", "")
297 end
298
299 if not name then
300 return nil, "Could not infer rock name. "..util.see_help("write_rockspec")
301 end
302 version = version or "dev"
303
304 local filename = args.output or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec")
305
306 local url = detect_url(location)
307 local homepage = detect_homepage(url, args.homepage)
308
309 local rockspec, err = rockspecs.from_persisted_table(filename, {
310 rockspec_format = args.rockspec_format,
311 package = name,
312 version = version.."-1",
313 source = {
314 url = url,
315 tag = args.tag,
316 },
317 description = {
318 summary = args.summary or "*** please specify description summary ***",
319 detailed = args.detailed or "*** please enter a detailed description ***",
320 homepage = homepage,
321 license = args.license or "*** please specify a license ***",
322 },
323 dependencies = {
324 lua_version_dep[args.lua_versions],
325 },
326 build = {},
327 })
328 assert(not err, err)
329 rockspec.source.protocol = protocol
330
331 if not next(rockspec.dependencies) then
332 util.warning("Please specify supported Lua versions with --lua-versions=<ver>. "..util.see_help("write_rockspec"))
333 end
334
335 local local_dir = location
336
337 if location:match("://") then
338 rockspec.source.file = dir.base_name(location)
339 if not dir.is_basic_protocol(rockspec.source.protocol) then
340 if version ~= "dev" then
341 rockspec.source.tag = args.tag or "v" .. version
342 end
343 end
344 rockspec.source.dir = nil
345 local ok, base_dir, temp_dir = fetch_url(rockspec)
346 if ok then
347 if base_dir ~= dir.base_name(location) then
348 rockspec.source.dir = base_dir
349 end
350 end
351 if base_dir then
352 local_dir = dir.path(temp_dir, base_dir)
353 else
354 local_dir = nil
355 end
356 end
357
358 if not local_dir then
359 local_dir = "."
360 end
361
362 local libs = nil
363 if args.lib then
364 libs = {}
365 rockspec.external_dependencies = {}
366 for lib in args.lib:gmatch("([^,]+)") do
367 table.insert(libs, lib)
368 rockspec.external_dependencies[lib:upper()] = {
369 library = lib
370 }
371 end
372 end
373
374 local ok, err = fs.change_dir(local_dir)
375 if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end
376
377 if not (args.summary and args.detailed) then
378 local summary, detailed = detect_description()
379 rockspec.description.summary = args.summary or summary
380 rockspec.description.detailed = args.detailed or detailed
381 end
382
383 if not args.license then
384 local license, fulltext = check_license()
385 if license then
386 rockspec.description.license = license
387 elseif license then
388 util.title("Could not auto-detect type for project license:")
389 util.printout(fulltext)
390 util.printout()
391 util.title("Please fill in the source.license field manually or use --license.")
392 end
393 end
394
395 fill_as_builtin(rockspec, libs)
396
397 rockspec_cleanup(rockspec)
398
399 persist.save_from_table(filename, rockspec, type_rockspec.order)
400
401 util.printout()
402 util.printout("Wrote template at "..filename.." -- you should now edit and finish it.")
403 util.printout()
404
405 return true
406end
407
408return write_rockspec
diff --git a/src/luarocks/cmd/write_rockspec.lua b/src/luarocks/cmd/write_rockspec.lua
index 871cdd44..41777307 100644
--- a/src/luarocks/cmd/write_rockspec.lua
+++ b/src/luarocks/cmd/write_rockspec.lua
@@ -1,6 +1,7 @@
1 1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table
2local write_rockspec = {} 2local write_rockspec = {}
3 3
4
4local builtin = require("luarocks.build.builtin") 5local builtin = require("luarocks.build.builtin")
5local cfg = require("luarocks.core.cfg") 6local cfg = require("luarocks.core.cfg")
6local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
@@ -11,6 +12,23 @@ local rockspecs = require("luarocks.rockspecs")
11local type_rockspec = require("luarocks.type.rockspec") 12local type_rockspec = require("luarocks.type.rockspec")
12local util = require("luarocks.util") 13local util = require("luarocks.util")
13 14
15local argparse = require("luarocks.vendor.argparse")
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
14local lua_versions = { 32local lua_versions = {
15 "5.1", 33 "5.1",
16 "5.2", 34 "5.2",
@@ -21,31 +39,31 @@ local lua_versions = {
21 "5.3,5.4", 39 "5.3,5.4",
22 "5.1,5.2,5.3", 40 "5.1,5.2,5.3",
23 "5.2,5.3,5.4", 41 "5.2,5.3,5.4",
24 "5.1,5.2,5.3,5.4" 42 "5.1,5.2,5.3,5.4",
25} 43}
26 44
27function write_rockspec.cmd_options(parser) 45function write_rockspec.cmd_options(parser)
28 return parser:option("--output", "Write the rockspec with the given filename.\n".. 46 return parser:option("--output", "Write the rockspec with the given filename.\n" ..
29 "If not given, a file is written in the current directory with a ".. 47 "If not given, a file is written in the current directory with a " ..
30 "filename based on given name and version.") 48 "filename based on given name and version."):
31 :argname("<file>"), 49 argname("<file>"),
32 parser:option("--license", 'A license string, such as "MIT/X11" or "GNU GPL v3".') 50 parser:option("--license", 'A license string, such as "MIT/X11" or "GNU GPL v3".'):
33 :argname("<string>"), 51 argname("<string>"),
34 parser:option("--summary", "A short one-line description summary.") 52 parser:option("--summary", "A short one-line description summary."):
35 :argname("<txt>"), 53 argname("<txt>"),
36 parser:option("--detailed", "A longer description string.") 54 parser:option("--detailed", "A longer description string."):
37 :argname("<txt>"), 55 argname("<txt>"),
38 parser:option("--homepage", "Project homepage.") 56 parser:option("--homepage", "Project homepage."):
39 :argname("<txt>"), 57 argname("<txt>"),
40 parser:option("--lua-versions", 'Supported Lua versions. Accepted values are: "'.. 58 parser:option("--lua-versions", 'Supported Lua versions. Accepted values are: "' ..
41 table.concat(lua_versions, '", "')..'".') 59 table.concat(lua_versions, '", "') .. '".'):
42 :argname("<ver>") 60 argname("<ver>"):
43 :choices(lua_versions), 61 choices(lua_versions),
44 parser:option("--rockspec-format", 'Rockspec format version, such as "1.0" or "1.1".') 62 parser:option("--rockspec-format", 'Rockspec format version, such as "1.0" or "1.1".'):
45 :argname("<ver>"), 63 argname("<ver>"),
46 parser:option("--tag", "Tag to use. Will attempt to extract version number from it."), 64 parser:option("--tag", "Tag to use. Will attempt to extract version number from it."),
47 parser:option("--lib", "A comma-separated list of libraries that C files need to link to.") 65 parser:option("--lib", "A comma-separated list of libraries that C files need to link to."):
48 :argname("<libs>") 66 argname("<libs>")
49end 67end
50 68
51function write_rockspec.add_to_parser(parser) 69function write_rockspec.add_to_parser(parser)
@@ -60,15 +78,15 @@ LuaRocks will attempt to infer name and version if not given,
60using 'dev' as a fallback default version. 78using 'dev' as a fallback default version.
61 79
62Note that the generated file is a _starting point_ for writing a 80Note that the generated file is a _starting point_ for writing a
63rockspec, and is not guaranteed to be complete or correct. ]], util.see_also()) 81rockspec, and is not guaranteed to be complete or correct. ]], util.see_also()):
64 :summary("Write a template for a rockspec file.") 82 summary("Write a template for a rockspec file.")
65 83
66 cmd:argument("name", "Name of the rock.") 84 cmd:argument("name", "Name of the rock."):
67 :args("?") 85 args("?")
68 cmd:argument("version", "Rock version.") 86 cmd:argument("version", "Rock version."):
69 :args("?") 87 args("?")
70 cmd:argument("location", "URL or path to the rock sources.") 88 cmd:argument("location", "URL or path to the rock sources."):
71 :args("?") 89 args("?")
72 90
73 write_rockspec.cmd_options(cmd) 91 write_rockspec.cmd_options(cmd)
74end 92end
@@ -82,7 +100,7 @@ local function fetch_url(rockspec)
82 if err_code == "source.dir" then 100 if err_code == "source.dir" then
83 file, temp_dir = err_file, err_temp_dir 101 file, temp_dir = err_file, err_temp_dir
84 elseif not file then 102 elseif not file then
85 util.warning("Could not fetch sources - "..temp_dir) 103 util.warning("Could not fetch sources - " .. temp_dir)
86 return false 104 return false
87 end 105 end
88 util.printout("File successfully downloaded. Making checksum and checking base dir...") 106 util.printout("File successfully downloaded. Making checksum and checking base dir...")
@@ -120,7 +138,7 @@ local simple_scm_protocols = {
120local detect_url 138local detect_url
121do 139do
122 local function detect_url_from_command(program, args, directory) 140 local function detect_url_from_command(program, args, directory)
123 local command = fs.Q(cfg.variables[program:upper()]).. " "..args 141 local command = fs.Q(cfg.variables[program:upper()]) .. " " .. args
124 local pipe = io.popen(fs.command_at(directory, fs.quiet_stderr(command))) 142 local pipe = io.popen(fs.command_at(directory, fs.quiet_stderr(command)))
125 if not pipe then return nil end 143 if not pipe then return nil end
126 local url = pipe:read("*a"):match("^([^\r\n]+)") 144 local url = pipe:read("*a"):match("^([^\r\n]+)")
@@ -128,19 +146,19 @@ do
128 if not url then return nil end 146 if not url then return nil end
129 if url:match("^[^@:/]+@[^@:/]+:.*$") then 147 if url:match("^[^@:/]+@[^@:/]+:.*$") then
130 local u, h, p = url:match("^([^@]+)@([^:]+):(.*)$") 148 local u, h, p = url:match("^([^@]+)@([^:]+):(.*)$")
131 url = program.."+ssh://"..u.."@"..h.."/"..p 149 url = program .. "+ssh://" .. u .. "@" .. h .. "/" .. p
132 elseif not util.starts_with(url, program.."://") then 150 elseif not util.starts_with(url, program .. "://") then
133 url = program.."+"..url 151 url = program .. "+" .. url
134 end 152 end
135 153
136 if simple_scm_protocols[dir.split_url(url)] then 154 if (simple_scm_protocols)[dir.split_url(url)] then
137 return url 155 return url
138 end 156 end
139 end 157 end
140 158
141 local function detect_scm_url(directory) 159 local function detect_scm_url(directory)
142 return detect_url_from_command("git", "config --get remote.origin.url", directory) or 160 return detect_url_from_command("git", "config --get remote.origin.url", directory) or
143 detect_url_from_command("hg", "paths default", directory) 161 detect_url_from_command("hg", "paths default", directory)
144 end 162 end
145 163
146 detect_url = function(url_or_dir) 164 detect_url = function(url_or_dir)
@@ -158,10 +176,10 @@ local function detect_homepage(url, homepage)
158 end 176 end
159 local url_protocol, url_path = dir.split_url(url) 177 local url_protocol, url_path = dir.split_url(url)
160 178
161 if simple_scm_protocols[url_protocol] then 179 if (simple_scm_protocols)[url_protocol] then
162 for _, domain in ipairs({"github.com", "bitbucket.org", "gitlab.com"}) do 180 for _, domain in ipairs({ "github.com", "bitbucket.org", "gitlab.com" }) do
163 if util.starts_with(url_path, domain) then 181 if util.starts_with(url_path, domain) then
164 return "https://"..url_path:gsub("%.git$", "") 182 return "https://" .. url_path:gsub("%.git$", "")
165 end 183 end
166 end 184 end
167 end 185 end
@@ -198,7 +216,7 @@ local function detect_license(data)
198 local strip_copyright = (data:gsub("^Copyright [^\n]*\n", "")) 216 local strip_copyright = (data:gsub("^Copyright [^\n]*\n", ""))
199 local sum = 0 217 local sum = 0
200 for i = 1, #strip_copyright do 218 for i = 1, #strip_copyright do
201 local num = string.byte(strip_copyright:sub(i,i)) 219 local num = string.byte(strip_copyright:sub(i, i))
202 if num > 32 and num <= 128 then 220 if num > 32 and num <= 128 then
203 sum = sum + num 221 sum = sum + num
204 end 222 end
@@ -226,12 +244,11 @@ local function fill_as_builtin(rockspec, libs)
226 incdirs, libdirs = {}, {} 244 incdirs, libdirs = {}, {}
227 for _, lib in ipairs(libs) do 245 for _, lib in ipairs(libs) do
228 local upper = lib:upper() 246 local upper = lib:upper()
229 incdirs[#incdirs+1] = "$("..upper.."_INCDIR)" 247 incdirs[#incdirs + 1] = "$(" .. upper .. "_INCDIR)"
230 libdirs[#libdirs+1] = "$("..upper.."_LIBDIR)" 248 libdirs[#libdirs + 1] = "$(" .. upper .. "_LIBDIR)"
231 end 249 end
232 end 250 end
233 251 (rockspec.build).modules, rockspec.build.install, rockspec.build.copy_directories = builtin.autodetect_modules(libs, incdirs, libdirs)
234 rockspec.build.modules, rockspec.build.install, rockspec.build.copy_directories = builtin.autodetect_modules(libs, incdirs, libdirs)
235end 252end
236 253
237local function rockspec_cleanup(rockspec) 254local function rockspec_cleanup(rockspec)
@@ -246,15 +263,15 @@ local function rockspec_cleanup(rockspec)
246 rockspec.format_is_at_least = nil 263 rockspec.format_is_at_least = nil
247 rockspec.local_abs_filename = nil 264 rockspec.local_abs_filename = nil
248 rockspec.rocks_provided = nil 265 rockspec.rocks_provided = nil
249 for _, list in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do 266 for _, list in ipairs({ "dependencies", "build_dependencies", "test_dependencies" }) do
250 if rockspec[list] and not next(rockspec[list]) then 267 if (rockspec)[list] and not next((rockspec)[list]) then
251 rockspec[list] = nil 268 (rockspec)[list] = nil
252 end 269 end
253 end 270 end
254 for _, list in ipairs({"dependencies", "build_dependencies", "test_dependencies"}) do 271 for _, list in ipairs({ "dependencies", "build_dependencies", "test_dependencies" }) do
255 if rockspec[list] then 272 if (rockspec)[list] then
256 for i, entry in ipairs(rockspec[list]) do 273 for i, entry in ipairs((rockspec)[list]) do
257 rockspec[list][i] = tostring(entry) 274 (rockspec)[list][i] = tostring(entry)
258 end 275 end
259 end 276 end
260 end 277 end
@@ -297,11 +314,11 @@ function write_rockspec.command(args)
297 end 314 end
298 315
299 if not name then 316 if not name then
300 return nil, "Could not infer rock name. "..util.see_help("write_rockspec") 317 return nil, "Could not infer rock name. " .. util.see_help("write_rockspec")
301 end 318 end
302 version = version or "dev" 319 version = version or "dev"
303 320
304 local filename = args.output or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") 321 local filename = args.output or dir.path(fs.current_dir(), name:lower() .. "-" .. version .. "-1.rockspec")
305 322
306 local url = detect_url(location) 323 local url = detect_url(location)
307 local homepage = detect_homepage(url, args.homepage) 324 local homepage = detect_homepage(url, args.homepage)
@@ -309,7 +326,7 @@ function write_rockspec.command(args)
309 local rockspec, err = rockspecs.from_persisted_table(filename, { 326 local rockspec, err = rockspecs.from_persisted_table(filename, {
310 rockspec_format = args.rockspec_format, 327 rockspec_format = args.rockspec_format,
311 package = name, 328 package = name,
312 version = version.."-1", 329 version = version .. "-1",
313 source = { 330 source = {
314 url = url, 331 url = url,
315 tag = args.tag, 332 tag = args.tag,
@@ -321,7 +338,7 @@ function write_rockspec.command(args)
321 license = args.license or "*** please specify a license ***", 338 license = args.license or "*** please specify a license ***",
322 }, 339 },
323 dependencies = { 340 dependencies = {
324 lua_version_dep[args.lua_versions], 341 (lua_version_dep)[args.lua_versions],
325 }, 342 },
326 build = {}, 343 build = {},
327 }) 344 })
@@ -329,7 +346,7 @@ function write_rockspec.command(args)
329 rockspec.source.protocol = protocol 346 rockspec.source.protocol = protocol
330 347
331 if not next(rockspec.dependencies) then 348 if not next(rockspec.dependencies) then
332 util.warning("Please specify supported Lua versions with --lua-versions=<ver>. "..util.see_help("write_rockspec")) 349 util.warning("Please specify supported Lua versions with --lua-versions=<ver>. " .. util.see_help("write_rockspec"))
333 end 350 end
334 351
335 local local_dir = location 352 local local_dir = location
@@ -366,13 +383,13 @@ function write_rockspec.command(args)
366 for lib in args.lib:gmatch("([^,]+)") do 383 for lib in args.lib:gmatch("([^,]+)") do
367 table.insert(libs, lib) 384 table.insert(libs, lib)
368 rockspec.external_dependencies[lib:upper()] = { 385 rockspec.external_dependencies[lib:upper()] = {
369 library = lib 386 library = lib,
370 } 387 }
371 end 388 end
372 end 389 end
373 390
374 local ok, err = fs.change_dir(local_dir) 391 local ok, err = fs.change_dir(local_dir)
375 if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end 392 if not ok then return nil, "Failed reaching files from project - error entering directory " .. local_dir end
376 393
377 if not (args.summary and args.detailed) then 394 if not (args.summary and args.detailed) then
378 local summary, detailed = detect_description() 395 local summary, detailed = detect_description()
@@ -399,7 +416,7 @@ function write_rockspec.command(args)
399 persist.save_from_table(filename, rockspec, type_rockspec.order) 416 persist.save_from_table(filename, rockspec, type_rockspec.order)
400 417
401 util.printout() 418 util.printout()
402 util.printout("Wrote template at "..filename.." -- you should now edit and finish it.") 419 util.printout("Wrote template at " .. filename .. " -- you should now edit and finish it.")
403 util.printout() 420 util.printout()
404 421
405 return true 422 return true