aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile17
-rwxr-xr-xconfigure11
-rwxr-xr-xsrc/bin/luarocks1
-rw-r--r--src/luarocks/cfg.lua4
-rw-r--r--src/luarocks/deps.lua36
-rw-r--r--src/luarocks/fetch.lua14
-rw-r--r--src/luarocks/fetch/git.lua8
-rw-r--r--src/luarocks/fs/unix.lua8
-rw-r--r--src/luarocks/fs/win32.lua12
-rw-r--r--src/luarocks/new_version.lua10
-rw-r--r--src/luarocks/type_check.lua7
-rw-r--r--src/luarocks/util.lua4
-rw-r--r--src/luarocks/write_rockspec.lua276
-rwxr-xr-xtest/testing.sh8
14 files changed, 370 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index 1213a589..cb7dbd09 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
@@ -80,6 +81,11 @@ src/luarocks/site_config.lua: config.unix
80 echo "LUAROCKS_UNAME_M=[[$(LUAROCKS_UNAME_M)]]" >> src/luarocks/site_config.lua 81 echo "LUAROCKS_UNAME_M=[[$(LUAROCKS_UNAME_M)]]" >> src/luarocks/site_config.lua
81 echo "LUAROCKS_DOWNLOADER=[[$(LUAROCKS_DOWNLOADER)]]" >> src/luarocks/site_config.lua 82 echo "LUAROCKS_DOWNLOADER=[[$(LUAROCKS_DOWNLOADER)]]" >> src/luarocks/site_config.lua
82 echo "LUAROCKS_MD5CHECKER=[[$(LUAROCKS_MD5CHECKER)]]" >> src/luarocks/site_config.lua 83 echo "LUAROCKS_MD5CHECKER=[[$(LUAROCKS_MD5CHECKER)]]" >> src/luarocks/site_config.lua
84 if [ -n "$(MULTIARCH_SUBDIR)" ] ;\
85 then \
86 echo 'LUAROCKS_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\
87 echo 'LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\
88 fi
83 89
84dev: 90dev:
85 $(MAKE) build_bins LUADIR=$(PWD)/src 91 $(MAKE) build_bins LUADIR=$(PWD)/src
@@ -168,11 +174,6 @@ write_sysconfig: built
168install: install_bins install_luas install_site_config write_sysconfig 174install: install_bins install_luas install_site_config write_sysconfig
169 175
170bootstrap: src/luarocks/site_config.lua install_site_config write_sysconfig 176bootstrap: src/luarocks/site_config.lua install_site_config write_sysconfig
171 if [ -n "$$LUA_PATH_5_2" ] ;\ 177 '$(LUA_BINDIR)/lua$(LUA_SUFFIX)' -e "package.path=[[$$PWD/src/?.lua;]]..package.path" src/bin/luarocks make rockspec --tree="$(PREFIX)"
172 then \
173 LUA_PATH="$$PWD/src/?.lua;$$LUA_PATH" LUA_PATH_5_2="$$PWD/src/?.lua;$$LUA_PATH_5_2" src/bin/luarocks make rockspec --tree="$(PREFIX)" ;\
174 else \
175 LUA_PATH="$$PWD/src/?.lua;$$LUA_PATH" src/bin/luarocks make rockspec --tree="$(PREFIX)" ;\
176 fi
177 178
178install_rock: install_bins install_luas 179install_rock: install_bins install_luas
diff --git a/configure b/configure
index a5aa1f4d..579e96f5 100755
--- a/configure
+++ b/configure
@@ -14,6 +14,7 @@ LUA_BINDIR="/usr/bin"
14LUA_INCDIR="/usr/include" 14LUA_INCDIR="/usr/include"
15LUA_LIBDIR="/usr/lib" 15LUA_LIBDIR="/usr/lib"
16LUA_VERSION="5.1" 16LUA_VERSION="5.1"
17MULTIARCH_SUBDIR=""
17 18
18# ---------------------------------------------------------------------------- 19# ----------------------------------------------------------------------------
19# FUNCTION DEFINITIONS 20# FUNCTION DEFINITIONS
@@ -396,6 +397,15 @@ else
396 echo "Using unversioned rocks dir: $PREFIX$LUAROCKS_ROCKS_SUBDIR" 397 echo "Using unversioned rocks dir: $PREFIX$LUAROCKS_ROCKS_SUBDIR"
397fi 398fi
398 399
400if [ "$LUAROCKS_UNAME_S" = Linux ]
401then
402 GCC_ARCH=`gcc -print-multiarch 2>/dev/null`
403 if [ -n "$GCC_ARCH" -a -d "/usr/lib/$GCC_ARCH" ]
404 then
405 MULTIARCH_SUBDIR="lib/$GCC_ARCH"
406 fi
407fi
408
399if [ -f config.unix ]; then 409if [ -f config.unix ]; then
400 rm -f config.unix 410 rm -f config.unix
401fi 411fi
@@ -426,6 +436,7 @@ LUAROCKS_UNAME_S=$LUAROCKS_UNAME_S
426LUAROCKS_DOWNLOADER=$LUAROCKS_DOWNLOADER 436LUAROCKS_DOWNLOADER=$LUAROCKS_DOWNLOADER
427LUAROCKS_MD5CHECKER=$LUAROCKS_MD5CHECKER 437LUAROCKS_MD5CHECKER=$LUAROCKS_MD5CHECKER
428LUAROCKS_ROCKS_SUBDIR=$LUAROCKS_ROCKS_SUBDIR 438LUAROCKS_ROCKS_SUBDIR=$LUAROCKS_ROCKS_SUBDIR
439MULTIARCH_SUBDIR=$MULTIARCH_SUBDIR
429 440
430EOF 441EOF
431 442
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/cfg.lua b/src/luarocks/cfg.lua
index 8e26bb46..94afe0a0 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -254,12 +254,12 @@ local defaults = {
254 STATFLAG = "-c '%a'", 254 STATFLAG = "-c '%a'",
255 }, 255 },
256 256
257 external_deps_subdirs = { 257 external_deps_subdirs = site_config.LUAROCKS_EXTERNAL_DEPS_SUBDIRS or {
258 bin = "bin", 258 bin = "bin",
259 lib = "lib", 259 lib = "lib",
260 include = "include" 260 include = "include"
261 }, 261 },
262 runtime_external_deps_subdirs = { 262 runtime_external_deps_subdirs = site_config.LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS or {
263 bin = "bin", 263 bin = "bin",
264 lib = "lib", 264 lib = "lib",
265 include = "include" 265 include = "include"
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index f24dc507..7f3b44f2 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -583,7 +583,19 @@ function check_external_deps(rockspec, mode)
583 prefix = prefix.prefix 583 prefix = prefix.prefix
584 end 584 end
585 for dirname, dirdata in pairs(dirs) do 585 for dirname, dirdata in pairs(dirs) do
586 dirdata.dir = vars[name.."_"..dirname] or dir.path(prefix, dirdata.subdir) 586 local paths
587 local path_var_value = vars[name.."_"..dirname]
588 if path_var_value then
589 paths = { path_var_value }
590 elseif type(dirdata.subdir) == "table" then
591 paths = {}
592 for i,v in ipairs(dirdata.subdir) do
593 paths[i] = dir.path(prefix, v)
594 end
595 else
596 paths = { dir.path(prefix, dirdata.subdir) }
597 end
598 dirdata.dir = paths[1]
587 local file = files[dirdata.testfile] 599 local file = files[dirdata.testfile]
588 if file then 600 if file then
589 local files = {} 601 local files = {}
@@ -605,16 +617,22 @@ function check_external_deps(rockspec, mode)
605 if f:match("%.so$") or f:match("%.dylib$") or f:match("%.dll$") then 617 if f:match("%.so$") or f:match("%.dylib$") or f:match("%.dll$") then
606 f = f:gsub("%.[^.]+$", "."..cfg.external_lib_extension) 618 f = f:gsub("%.[^.]+$", "."..cfg.external_lib_extension)
607 end 619 end
608 if f:match("%*") then 620 for _, d in ipairs(paths) do
609 local replaced = f:gsub("%.", "%%."):gsub("%*", ".*") 621 if f:match("%*") then
610 for _, entry in ipairs(fs.list_dir(dirdata.dir)) do 622 local replaced = f:gsub("%.", "%%."):gsub("%*", ".*")
611 if entry:match(replaced) then 623 for _, entry in ipairs(fs.list_dir(d)) do
612 found = true 624 if entry:match(replaced) then
613 break 625 found = true
626 break
627 end
614 end 628 end
629 else
630 found = fs.is_file(dir.path(d, f))
631 end
632 if found then
633 dirdata.dir = d
634 break
615 end 635 end
616 else
617 found = fs.is_file(dir.path(dirdata.dir, f))
618 end 636 end
619 if found then 637 if found then
620 break 638 break
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/fs/unix.lua b/src/luarocks/fs/unix.lua
index cccbbd33..e154ef45 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -53,15 +53,15 @@ function wrap_script(file, dest, name, version)
53 53
54 local base = dir.base_name(file) 54 local base = dir.base_name(file)
55 local wrapname = fs.is_dir(dest) and dest.."/"..base or dest 55 local wrapname = fs.is_dir(dest) and dest.."/"..base or dest
56 local lpath, lcpath = cfg.package_paths()
57 lpath = util.escape_doublebrackets(lpath)
58 lcpath = util.escape_doublebrackets(lcpath)
56 local wrapper = io.open(wrapname, "w") 59 local wrapper = io.open(wrapname, "w")
57 if not wrapper then 60 if not wrapper then
58 return nil, "Could not open "..wrapname.." for writing." 61 return nil, "Could not open "..wrapname.." for writing."
59 end 62 end
60 wrapper:write("#!/bin/sh\n\n") 63 wrapper:write("#!/bin/sh\n\n")
61 wrapper:write('LUA_PATH="'..package.path..';$LUA_PATH"\n') 64 wrapper:write('exec "'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -e \'package.path=[['..lpath..';]]..package.path\' -e \'package.cpath=[['..lcpath..';]]..package.cpath\' -lluarocks.loader -e\'luarocks.loader.add_context([['..name..']],[['..version..']])\' "'..file..'" "$@"\n')
62 wrapper:write('LUA_CPATH="'..package.cpath..';$LUA_CPATH"\n')
63 wrapper:write('export LUA_PATH LUA_CPATH\n')
64 wrapper:write('exec "'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -lluarocks.loader -e\'luarocks.loader.add_context([['..name..']],[['..version..']])\' "'..file..'" "$@"\n')
65 wrapper:close() 65 wrapper:close()
66 if fs.chmod(wrapname, "0755") then 66 if fs.chmod(wrapname, "0755") then
67 return true 67 return true
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index 2bc595f6..ba3ba2b3 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -7,6 +7,7 @@ local fs = require("luarocks.fs")
7 7
8local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
9local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
10local util = require("luarocks.util")
10 11
11--- Annotate command string for quiet execution. 12--- Annotate command string for quiet execution.
12-- @param cmd string: A command-line string. 13-- @param cmd string: A command-line string.
@@ -63,18 +64,15 @@ function wrap_script(file, dest, name, version)
63 local base = dir.base_name(file) 64 local base = dir.base_name(file)
64 local wrapname = fs.is_dir(dest) and dest.."/"..base or dest 65 local wrapname = fs.is_dir(dest) and dest.."/"..base or dest
65 wrapname = wrapname..".bat" 66 wrapname = wrapname..".bat"
67 local lpath, lcpath = cfg.package_paths()
68 lpath = util.escape_doublebrackets(lpath)
69 lcpath = util.escape_doublebrackets(lcpath)
66 local wrapper = io.open(wrapname, "w") 70 local wrapper = io.open(wrapname, "w")
67 if not wrapper then 71 if not wrapper then
68 return nil, "Could not open "..wrapname.." for writing." 72 return nil, "Could not open "..wrapname.." for writing."
69 end 73 end
70 wrapper:write("@echo off\n") 74 wrapper:write("@echo off\n")
71 wrapper:write("setlocal\n") 75 wrapper:write('"'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -e "package.path=[['..lpath..';]]..package.path" -e "package.cpath=[['..lcpath..';]]..package.cpath" -lluarocks.loader -e"luarocks.loader.add_context([['..name..']],[['..version..']])" "'..file..'" %*\n')
72 wrapper:write('set LUA_PATH='..package.path..";%LUA_PATH%\n")
73 wrapper:write('set LUA_CPATH='..package.cpath..";%LUA_CPATH%\n")
74 wrapper:write('if not "%LUA_PATH_5_2%"=="" set LUA_PATH_5_2='..package.path..";%LUA_PATH_5_2%\n")
75 wrapper:write('if not "%LUA_CPATH_5_2%"=="" set LUA_CPATH_5_2='..package.cpath..";%LUA_CPATH_5_2%\n")
76 wrapper:write('"'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -lluarocks.loader -e"luarocks.loader.add_context([['..name..']],[['..version..']])" "'..file..'" %*\n')
77 wrapper:write("endlocal\n")
78 wrapper:close() 76 wrapper:close()
79 return true 77 return true
80end 78end
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/util.lua b/src/luarocks/util.lua
index e3260359..cfcd2013 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -511,3 +511,7 @@ function array_contains(tbl, value)
511 end 511 end
512 return false 512 return false
513end 513end
514
515function escape_doublebrackets(s)
516 return s:gsub("(([%[%]])%2)","]]..'%1'..[[")
517end \ No newline at end of file
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua
new file mode 100644
index 00000000..9c20a054
--- /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"