aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2013-10-13 19:29:01 +0200
committerPhilipp Janda <siffiejoe@gmx.net>2013-10-13 19:29:01 +0200
commit309ad25d1ac13584e8c7656833bb632c5e179036 (patch)
treeb28da9f7008b1cb31a2cd8a5b8c0abb518c7cecb
parente6e0e57a4c36f2d93fa674292658e701d1a4640f (diff)
parent57bde51526bcd9c022e29802f29ae432a3a03bef (diff)
downloadluarocks-309ad25d1ac13584e8c7656833bb632c5e179036.tar.gz
luarocks-309ad25d1ac13584e8c7656833bb632c5e179036.tar.bz2
luarocks-309ad25d1ac13584e8c7656833bb632c5e179036.zip
Merge remote-tracking branch 'upstream/master' into linux-multiarch
-rw-r--r--Makefile5
-rwxr-xr-xsrc/bin/luarocks1
-rw-r--r--src/luarocks/fetch.lua14
-rw-r--r--src/luarocks/fetch/git.lua8
-rw-r--r--src/luarocks/new_version.lua10
-rw-r--r--src/luarocks/type_check.lua7
-rw-r--r--src/luarocks/write_rockspec.lua276
-rwxr-xr-xtest/testing.sh8
8 files changed, 311 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index 2f640ae6..ee06b670 100644
--- a/Makefile
+++ b/Makefile
@@ -16,11 +16,12 @@ LUAROCKS_FILES = fs/unix/tools.lua fs/unix.lua fs/win32/tools.lua fs/win32.lua \
16fs/lua.lua persist.lua list.lua require.lua repos.lua dir.lua make_manifest.lua \ 16fs/lua.lua persist.lua list.lua require.lua repos.lua dir.lua make_manifest.lua \
17command_line.lua install.lua build/command.lua build/cmake.lua build/make.lua \ 17command_line.lua install.lua build/command.lua build/cmake.lua build/make.lua \
18build/builtin.lua fetch/cvs.lua fetch/git.lua fetch/sscm.lua tools/patch.lua \ 18build/builtin.lua fetch/cvs.lua fetch/git.lua fetch/sscm.lua tools/patch.lua \
19fetch/svn.lua tools/zip.lua tools/tar.lua pack.lua type_check.lua make.lua path.lua \ 19fetch/svn.lua tools/zip.lua tools/tar.lua pack.lua type_check.lua make.lua \
20remove.lua fs.lua manif.lua add.lua deps.lua build.lua search.lua show.lua \ 20remove.lua fs.lua manif.lua add.lua deps.lua build.lua search.lua show.lua \
21manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \ 21manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \
22help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \ 22help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \
23admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua purge.lua 23admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \
24purge.lua path.lua write_rockspec.lua
24 25
25CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua 26CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua
26 27
diff --git a/src/bin/luarocks b/src/bin/luarocks
index b64051d4..e28b17b8 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -19,6 +19,7 @@ commands.path = require("luarocks.path")
19commands.show = require("luarocks.show") 19commands.show = require("luarocks.show")
20commands.new_version = require("luarocks.new_version") 20commands.new_version = require("luarocks.new_version")
21commands.lint = require("luarocks.lint") 21commands.lint = require("luarocks.lint")
22commands.write_rockspec = require("luarocks.write_rockspec")
22commands.purge = require("luarocks.purge") 23commands.purge = require("luarocks.purge")
23 24
24command_line.run_command(...) 25command_line.run_command(...)
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua
index a742b7fc..111d229a 100644
--- a/src/luarocks/fetch.lua
+++ b/src/luarocks/fetch.lua
@@ -11,6 +11,10 @@ local persist = require("luarocks.persist")
11local util = require("luarocks.util") 11local util = require("luarocks.util")
12local cfg = require("luarocks.cfg") 12local cfg = require("luarocks.cfg")
13 13
14function is_basic_protocol(protocol, remote)
15 return protocol == "http" or protocol == "https" or protocol == "ftp" or (not remote and protocol == "file")
16end
17
14--- Fetch a local or remote file. 18--- Fetch a local or remote file.
15-- Make a remote or local URL/pathname local, fetching the file if necessary. 19-- Make a remote or local URL/pathname local, fetching the file if necessary.
16-- Other "fetch" and "load" functions use this function to obtain files. 20-- Other "fetch" and "load" functions use this function to obtain files.
@@ -30,7 +34,7 @@ function fetch_url(url, filename)
30 local protocol, pathname = dir.split_url(url) 34 local protocol, pathname = dir.split_url(url)
31 if protocol == "file" then 35 if protocol == "file" then
32 return fs.absolute_name(pathname) 36 return fs.absolute_name(pathname)
33 elseif protocol == "http" or protocol == "ftp" or protocol == "https" then 37 elseif is_basic_protocol(protocol, true) then
34 local ok, err = fs.download(url, filename) 38 local ok, err = fs.download(url, filename)
35 if not ok then 39 if not ok then
36 return nil, "Failed downloading "..url..(err and " - "..err or ""), "network" 40 return nil, "Failed downloading "..url..(err and " - "..err or ""), "network"
@@ -171,7 +175,7 @@ function load_local_rockspec(filename)
171 end 175 end
172 176
173 local protocol, pathname = dir.split_url(rockspec.source.url) 177 local protocol, pathname = dir.split_url(rockspec.source.url)
174 if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then 178 if is_basic_protocol(protocol) then
175 rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) 179 rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url)
176 end 180 end
177 rockspec.source.protocol, rockspec.source.pathname = protocol, pathname 181 rockspec.source.protocol, rockspec.source.pathname = protocol, pathname
@@ -254,7 +258,8 @@ end
254-- @param rockspec table: The rockspec table 258-- @param rockspec table: The rockspec table
255-- @param extract boolean: Whether to extract the sources from 259-- @param extract boolean: Whether to extract the sources from
256-- the fetched source tarball or not. 260-- the fetched source tarball or not.
257-- @param dest_dir string or nil: If set, will extract to the given directory. 261-- @param dest_dir string or nil: If set, will extract to the given directory;
262-- if not given, will extract to a temporary directory.
258-- @return (string, string) or (nil, string, [string]): The absolute pathname of 263-- @return (string, string) or (nil, string, [string]): The absolute pathname of
259-- the fetched source tarball and the temporary directory created to 264-- the fetched source tarball and the temporary directory created to
260-- store it; or nil and an error message and optional error code. 265-- store it; or nil and an error message and optional error code.
@@ -301,6 +306,7 @@ end
301-- @param extract boolean: When downloading compressed formats, whether to extract 306-- @param extract boolean: When downloading compressed formats, whether to extract
302-- the sources from the fetched archive or not. 307-- the sources from the fetched archive or not.
303-- @param dest_dir string or nil: If set, will extract to the given directory. 308-- @param dest_dir string or nil: If set, will extract to the given directory.
309-- if not given, will extract to a temporary directory.
304-- @return (string, string) or (nil, string): The absolute pathname of 310-- @return (string, string) or (nil, string): The absolute pathname of
305-- the fetched source tarball and the temporary directory created to 311-- the fetched source tarball and the temporary directory created to
306-- store it; or nil and an error message. 312-- store it; or nil and an error message.
@@ -311,7 +317,7 @@ function fetch_sources(rockspec, extract, dest_dir)
311 317
312 local protocol = rockspec.source.protocol 318 local protocol = rockspec.source.protocol
313 local ok, proto 319 local ok, proto
314 if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then 320 if is_basic_protocol(protocol) then
315 proto = require("luarocks.fetch") 321 proto = require("luarocks.fetch")
316 else 322 else
317 ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_")) 323 ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_"))
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index 44151927..90d4eea8 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -11,13 +11,13 @@ local util = require("luarocks.util")
11-- clone by tag then we'll have to issue a subsequent command to check out the 11-- clone by tag then we'll have to issue a subsequent command to check out the
12-- given tag. 12-- given tag.
13-- @return boolean: Whether Git can clone by tag. 13-- @return boolean: Whether Git can clone by tag.
14local function git_can_clone_by_tag() 14local function git_can_clone_by_tag(git_cmd)
15 local version_string = io.popen('git --version'):read() 15 local version_string = io.popen(git_cmd..' --version'):read()
16 local major, minor, tiny = version_string:match('(%d-)%.(%d+)%.?(%d*)') 16 local major, minor, tiny = version_string:match('(%d-)%.(%d+)%.?(%d*)')
17 major, minor, tiny = tonumber(major), tonumber(minor), tonumber(tiny) or 0 17 major, minor, tiny = tonumber(major), tonumber(minor), tonumber(tiny) or 0
18 local value = major > 1 or (major == 1 and (minor > 7 or (minor == 7 and tiny >= 10))) 18 local value = major > 1 or (major == 1 and (minor > 7 or (minor == 7 and tiny >= 10)))
19 git_can_clone_by_tag = function() return value end 19 git_can_clone_by_tag = function() return value end
20 return git_can_clone_by_tag() 20 return value
21end 21end
22 22
23--- Download sources for building a rock, using git. 23--- Download sources for building a rock, using git.
@@ -57,7 +57,7 @@ function get_sources(rockspec, extract, dest_dir)
57 -- we can avoid passing it to Git since it's the default. 57 -- we can avoid passing it to Git since it's the default.
58 if tag_or_branch == "master" then tag_or_branch = nil end 58 if tag_or_branch == "master" then tag_or_branch = nil end
59 if tag_or_branch then 59 if tag_or_branch then
60 if git_can_clone_by_tag() then 60 if git_can_clone_by_tag(git_cmd) then
61 -- The argument to `--branch` can actually be a branch or a tag as of 61 -- The argument to `--branch` can actually be a branch or a tag as of
62 -- Git 1.7.10. 62 -- Git 1.7.10.
63 table.insert(command, 4, "--branch=" .. tag_or_branch) 63 table.insert(command, 4, "--branch=" .. tag_or_branch)
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua
index f93d0c29..7f255d0d 100644
--- a/src/luarocks/new_version.lua
+++ b/src/luarocks/new_version.lua
@@ -10,6 +10,7 @@ local fetch = require("luarocks.fetch")
10local persist = require("luarocks.persist") 10local persist = require("luarocks.persist")
11local dir = require("luarocks.dir") 11local dir = require("luarocks.dir")
12local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
13local type_check = require("luarocks.type_check")
13 14
14help_summary = "Auto-write a rockspec for a new version of a rock." 15help_summary = "Auto-write a rockspec for a new version of a rock."
15help_arguments = "{<package>|<rockspec>} [<new_version>] [<new_url>]" 16help_arguments = "{<package>|<rockspec>} [<new_version>] [<new_url>]"
@@ -33,13 +34,6 @@ WARNING: it writes the new rockspec to the current directory,
33overwriting the file if it already exists. 34overwriting the file if it already exists.
34]] 35]]
35 36
36local order = {"rockspec_format", "package", "version",
37 { "source", { "url", "tag", "branch", "md5" } },
38 { "description", {"summary", "detailed", "homepage", "license" } },
39 "supported_platforms", "dependencies", "external_dependencies",
40 { "build", {"type", "modules", "copy_directories", "platforms"} },
41 "hooks"}
42
43local function try_replace(tbl, field, old, new) 37local function try_replace(tbl, field, old, new)
44 if not tbl[field] then 38 if not tbl[field] then
45 return false 39 return false
@@ -166,7 +160,7 @@ function run(...)
166 160
167 local out_filename = out_name.."-"..new_rockver.."-"..new_rev..".rockspec" 161 local out_filename = out_name.."-"..new_rockver.."-"..new_rev..".rockspec"
168 162
169 persist.save_from_table(out_filename, out_rs, order) 163 persist.save_from_table(out_filename, out_rs, type_check.rockspec_order)
170 164
171 util.printout("Wrote "..out_filename) 165 util.printout("Wrote "..out_filename)
172 166
diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua
index 28e6e7b9..6a0ee7e7 100644
--- a/src/luarocks/type_check.lua
+++ b/src/luarocks/type_check.lua
@@ -74,6 +74,13 @@ rockspec_types = {
74 } 74 }
75} 75}
76 76
77rockspec_order = {"rockspec_format", "package", "version",
78 { "source", { "url", "tag", "branch", "md5" } },
79 { "description", {"summary", "detailed", "homepage", "license" } },
80 "supported_platforms", "dependencies", "external_dependencies",
81 { "build", {"type", "modules", "copy_directories", "platforms"} },
82 "hooks"}
83
77function load_extensions() 84function load_extensions()
78 rockspec_format = "1.1" 85 rockspec_format = "1.1"
79 rockspec_types.deploy = { 86 rockspec_types.deploy = {
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua
new file mode 100644
index 00000000..68547cdf
--- /dev/null
+++ b/src/luarocks/write_rockspec.lua
@@ -0,0 +1,276 @@
1
2module("luarocks.write_rockspec", package.seeall)
3
4local dir = require("luarocks.dir")
5local fetch = require("luarocks.fetch")
6local fs = require("luarocks.fs")
7local path = require("luarocks.path")
8local persist = require("luarocks.persist")
9local type_check = require("luarocks.type_check")
10local util = require("luarocks.util")
11
12help_summary = "Write a template for a rockspec file."
13help_arguments = "[--output=<file> ...] <name> [<version>] [<url>|<path>]"
14help = [[
15This command writes an initial version of a rockspec file,
16based on an URL or a local path.
17
18If a repository URL is given with no version, it creates an 'scm' rock.
19
20Note that the generated file is a _starting point_ for writing a
21rockspec, and is not guaranteed to be complete or correct.
22
23--output=<file> Write the rockspec with the given filename.
24 If not given, a file is written in the current
25 directory with a filename based on given name and version.
26--license="<string>" A license string, such as "MIT/X11" or "GNU GPL v3".
27--summary="<txt>" A short one-line description summary.
28--description="<txt>" A longer description string.
29--homepage=<url> Project homepage.
30--lua-version=<ver> Supported Lua versions. Accepted values are "5.1", "5.2"
31 or "5.1,5.2".
32--lib=<lib>[,<lib>] A comma-separated list of libraries that C files need to
33 link to.
34]]
35
36
37local function get_url(rockspec)
38 local url = rockspec.source.url
39 local file, temp_dir = fetch.fetch_sources(rockspec, true)
40 if not file then
41 util.warning("Could not fetch sources - "..temp_dir)
42 return false
43 end
44 util.printout("File successfully downloaded. Making checksum and checking base dir...")
45 local md5 = nil
46 if fetch.is_basic_protocol(rockspec.source.protocol) then
47 rockspec.source.md5 = fs.get_md5(file)
48 end
49 local ok, err = fs.change_dir(temp_dir)
50 if not ok then return false end
51 fs.unpack_archive(file)
52 local base_dir = fetch.url_to_base_dir(url)
53 if not fs.exists(base_dir) then
54 util.printerr("Directory "..base_dir.." not found")
55 local files = fs.list_dir()
56 if files[1] and fs.is_dir(files[1]) then
57 util.printerr("Found "..files[1])
58 base_dir = files[1]
59 end
60 end
61 fs.pop_dir()
62 return true, base_dir, temp_dir
63end
64
65local function configure_lua_version(rockspec, luaver)
66 if luaver == "5.1" then
67 table.insert(rockspec.dependencies, "lua ~> 5.1")
68 elseif luaver == "5.2" then
69 table.insert(rockspec.dependencies, "lua ~> 5.2")
70 elseif luaver == "5.1,5.2" then
71 table.insert(rockspec.dependencies, "lua >= 5.1, <= 5.3")
72 else
73 util.warning("Please specify supported Lua version with --lua-version=<ver>. "..util.see_help("write_rockspec"))
74 end
75end
76
77local function detect_description(rockspec)
78 local fd = io.open("README.md", "r")
79 if not fd then fd = io.open("README", "r") end
80 if not fd then return end
81 local data = fd:read("*a")
82 fd:close()
83 local paragraph = data:match("\n\n(.-)\n\n")
84 if not paragraph then paragraph = data:match("\n\n(.*)") end
85 if paragraph then
86 if #paragraph < 80 then
87 rockspec.description.summary = paragraph:gsub("\n", "")
88 rockspec.description.detailed = paragraph
89 else
90 local summary = paragraph:gsub("\n", " "):match("([^.]*%.) ")
91 if summary then
92 rockspec.description.summary = summary:gsub("\n", "")
93 end
94 rockspec.description.detailed = paragraph
95 end
96 end
97end
98
99local function get_cmod_name(file)
100 local fd = io.open(file, "r")
101 if not fd then return nil end
102 local data = fd:read("*a")
103 fd:close()
104 return (data:match("int%s+luaopen_([a-zA-Z0-9_]+)"))
105end
106
107local luamod_blacklist = {
108 test = true,
109 tests = true,
110}
111
112local function fill_as_builtin(rockspec, libs)
113 rockspec.build.type = "builtin"
114 rockspec.build.modules = {}
115 local prefix = ""
116
117 for _, parent in ipairs({"src", "lua"}) do
118 if fs.is_dir(parent) then
119 fs.change_dir(parent)
120 prefix = parent.."/"
121 break
122 end
123 end
124
125 local incdirs, libdirs
126 if libs then
127 incdirs, libdirs = {}, {}
128 for _, lib in ipairs(libs) do
129 local upper = lib:upper()
130 incdirs[#incdirs+1] = "$("..upper.."_INCDIR)"
131 libdirs[#libdirs+1] = "$("..upper.."_LIBDIR)"
132 end
133 end
134
135 for _, file in ipairs(fs.find()) do
136 local luamod = file:match("(.*)%.lua$")
137 if luamod and not luamod_blacklist[luamod] then
138 rockspec.build.modules[path.path_to_module(file)] = prefix..file
139 else
140 local cmod = file:match("(.*)%.c$")
141 if cmod then
142 local modname = get_cmod_name(file) or path.path_to_module(file:gsub("%.c$", ".lua"))
143 rockspec.build.modules[modname] = {
144 sources = prefix..file,
145 libraries = libs,
146 incdirs = incdirs,
147 libdirs = libdirs,
148 }
149 end
150 end
151 end
152
153 for _, directory in ipairs({ "doc", "docs", "samples", "tests" }) do
154 if fs.is_dir(directory) then
155 if not rockspec.build.copy_directories then
156 rockspec.build.copy_directories = {}
157 end
158 table.insert(rockspec.build.copy_directories, directory)
159 end
160 end
161
162 if prefix ~= "" then
163 fs.pop_dir()
164 end
165end
166
167local function rockspec_cleanup(rockspec)
168 rockspec.source.protocol = nil
169 rockspec.variables = nil
170 rockspec.name = nil
171end
172
173function run(...)
174 local flags, name, version, local_dir = util.parse_flags(...)
175
176 if not name then
177 return nil, "Missing arguments. "..util.see_help("write_rockspec")
178 end
179
180 if name and not version then
181 local protocol, path = dir.split_url(name)
182 if not fetch.is_basic_protocol(protocol) then
183 local_dir = name
184 version = "scm"
185 name = dir.base_name(name):gsub("%.[^.]+$", "")
186 else
187 return nil, "Missing name and version arguments. "..util.see_help("write_rockspec")
188 end
189 end
190
191 if not local_dir then
192 local protocol, path = dir.split_url(version)
193 if not fetch.is_basic_protocol(protocol) then
194 local_dir = version
195 version = "scm"
196 elseif protocol ~= "file" then
197 return nil, "Missing version argument. "..util.see_help("write_rockspec")
198 end
199 end
200
201 local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec")
202
203 local rockspec = {
204 package = name,
205 name = name:lower(),
206 version = version.."-1",
207 source = {
208 url = "*** please add URL for source tarball, zip or repository here ***"
209 },
210 description = {
211 summary = flags["summary"] or "*** please specify description summary ***",
212 detailed = flags["detailed"] or "*** please enter a detailed description ***",
213 homepage = flags["homepage"] or "*** please enter a project homepage ***",
214 license = flags["license"] or "*** please specify a license ***",
215 },
216 dependencies = {},
217 build = {},
218 }
219 path.configure_paths(rockspec)
220 rockspec.source.protocol = dir.split_url(local_dir)
221
222 configure_lua_version(rockspec, flags["lua-version"])
223
224 if local_dir:match("://") then
225 rockspec.source.url = local_dir
226 if not fetch.is_basic_protocol(rockspec.source.protocol) then
227 if version ~= "scm" then
228 rockspec.source.tag = "v" .. version
229 end
230 end
231 local ok, base_dir, temp_dir = get_url(rockspec)
232 if ok then
233 if base_dir ~= dir.base_name(local_dir) then
234 rockspec.source.dir = base_dir
235 end
236 end
237 if base_dir then
238 local_dir = dir.path(temp_dir, base_dir)
239 else
240 local_dir = nil
241 end
242 end
243
244 if not local_dir then
245 local_dir = "."
246 end
247
248 local libs = nil
249 if flags["lib"] then
250 libs = {}
251 rockspec.external_dependencies = {}
252 for lib in flags["lib"]:gmatch("([^,]+)") do
253 table.insert(libs, lib)
254 rockspec.external_dependencies[lib:upper()] = {
255 library = lib
256 }
257 end
258 end
259
260 local ok, err = fs.change_dir(local_dir)
261 if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end
262
263 detect_description(rockspec)
264
265 fill_as_builtin(rockspec, libs)
266
267 rockspec_cleanup(rockspec)
268
269 persist.save_from_table(filename, rockspec, type_check.rockspec_order)
270
271 util.printout()
272 util.printout("Wrote template at "..filename.." -- you should now edit and finish it.")
273 util.printout()
274
275 return true
276end
diff --git a/test/testing.sh b/test/testing.sh
index 207bdfbc..5b3de201 100755
--- a/test/testing.sh
+++ b/test/testing.sh
@@ -7,6 +7,14 @@
7 exit 1 7 exit 1
8} 8}
9 9
10if [ -z "$@"]
11then
12 ps aux | grep -q '[s]shd' || {
13 echo "Run sudo /bin/sshd in order to perform all tests."
14 exit 1
15 }
16fi
17
10testing_dir="$PWD" 18testing_dir="$PWD"
11 19
12testing_tree="$testing_dir/testing" 20testing_tree="$testing_dir/testing"