From c026b15ed8f66112ff7fb81d13922ba7492b58e3 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 2 Oct 2013 13:38:24 -0300 Subject: Fix hardcoded reference to git --- src/luarocks/fetch/git.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index 44151927..85714eb2 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -11,8 +11,8 @@ local util = require("luarocks.util") -- clone by tag then we'll have to issue a subsequent command to check out the -- given tag. -- @return boolean: Whether Git can clone by tag. -local function git_can_clone_by_tag() - local version_string = io.popen('git --version'):read() +local function git_can_clone_by_tag(git_cmd) + local version_string = io.popen(git_cmd..' --version'):read() local major, minor, tiny = version_string:match('(%d-)%.(%d+)%.?(%d*)') major, minor, tiny = tonumber(major), tonumber(minor), tonumber(tiny) or 0 local value = major > 1 or (major == 1 and (minor > 7 or (minor == 7 and tiny >= 10))) @@ -57,7 +57,7 @@ function get_sources(rockspec, extract, dest_dir) -- we can avoid passing it to Git since it's the default. if tag_or_branch == "master" then tag_or_branch = nil end if tag_or_branch then - if git_can_clone_by_tag() then + if git_can_clone_by_tag(git_cmd) then -- The argument to `--branch` can actually be a branch or a tag as of -- Git 1.7.10. table.insert(command, 4, "--branch=" .. tag_or_branch) -- cgit v1.2.3-55-g6feb From ee42f7491734866e6898a0ba4ac232a776027cc2 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 11 Oct 2013 19:46:34 -0300 Subject: Added new command 'luarocks write_rockspec', which writes a template for a new rockspec. --- src/bin/luarocks | 1 + src/luarocks/fetch.lua | 14 +- src/luarocks/fetch/git.lua | 2 +- src/luarocks/new_version.lua | 10 +- src/luarocks/type_check.lua | 7 + src/luarocks/write_rockspec.lua | 276 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 297 insertions(+), 13 deletions(-) create mode 100644 src/luarocks/write_rockspec.lua 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") commands.show = require("luarocks.show") commands.new_version = require("luarocks.new_version") commands.lint = require("luarocks.lint") +commands.write_rockspec = require("luarocks.write_rockspec") commands.purge = require("luarocks.purge") command_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") local util = require("luarocks.util") local cfg = require("luarocks.cfg") +function is_basic_protocol(protocol, remote) + return protocol == "http" or protocol == "https" or protocol == "ftp" or (not remote and protocol == "file") +end + --- Fetch a local or remote file. -- Make a remote or local URL/pathname local, fetching the file if necessary. -- Other "fetch" and "load" functions use this function to obtain files. @@ -30,7 +34,7 @@ function fetch_url(url, filename) local protocol, pathname = dir.split_url(url) if protocol == "file" then return fs.absolute_name(pathname) - elseif protocol == "http" or protocol == "ftp" or protocol == "https" then + elseif is_basic_protocol(protocol, true) then local ok, err = fs.download(url, filename) if not ok then return nil, "Failed downloading "..url..(err and " - "..err or ""), "network" @@ -171,7 +175,7 @@ function load_local_rockspec(filename) end local protocol, pathname = dir.split_url(rockspec.source.url) - if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then + if is_basic_protocol(protocol) then rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) end rockspec.source.protocol, rockspec.source.pathname = protocol, pathname @@ -254,7 +258,8 @@ end -- @param rockspec table: The rockspec table -- @param extract boolean: Whether to extract the sources from -- the fetched source tarball or not. --- @param dest_dir string or nil: If set, will extract to the given directory. +-- @param dest_dir string or nil: If set, will extract to the given directory; +-- if not given, will extract to a temporary directory. -- @return (string, string) or (nil, string, [string]): The absolute pathname of -- the fetched source tarball and the temporary directory created to -- store it; or nil and an error message and optional error code. @@ -301,6 +306,7 @@ end -- @param extract boolean: When downloading compressed formats, whether to extract -- the sources from the fetched archive or not. -- @param dest_dir string or nil: If set, will extract to the given directory. +-- if not given, will extract to a temporary directory. -- @return (string, string) or (nil, string): The absolute pathname of -- the fetched source tarball and the temporary directory created to -- store it; or nil and an error message. @@ -311,7 +317,7 @@ function fetch_sources(rockspec, extract, dest_dir) local protocol = rockspec.source.protocol local ok, proto - if protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" then + if is_basic_protocol(protocol) then proto = require("luarocks.fetch") else ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_")) diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index 85714eb2..90d4eea8 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -17,7 +17,7 @@ local function git_can_clone_by_tag(git_cmd) major, minor, tiny = tonumber(major), tonumber(minor), tonumber(tiny) or 0 local value = major > 1 or (major == 1 and (minor > 7 or (minor == 7 and tiny >= 10))) git_can_clone_by_tag = function() return value end - return git_can_clone_by_tag() + return value end --- Download sources for building a rock, using git. 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") local persist = require("luarocks.persist") local dir = require("luarocks.dir") local fs = require("luarocks.fs") +local type_check = require("luarocks.type_check") help_summary = "Auto-write a rockspec for a new version of a rock." help_arguments = "{|} [] []" @@ -33,13 +34,6 @@ WARNING: it writes the new rockspec to the current directory, overwriting the file if it already exists. ]] -local order = {"rockspec_format", "package", "version", - { "source", { "url", "tag", "branch", "md5" } }, - { "description", {"summary", "detailed", "homepage", "license" } }, - "supported_platforms", "dependencies", "external_dependencies", - { "build", {"type", "modules", "copy_directories", "platforms"} }, - "hooks"} - local function try_replace(tbl, field, old, new) if not tbl[field] then return false @@ -166,7 +160,7 @@ function run(...) local out_filename = out_name.."-"..new_rockver.."-"..new_rev..".rockspec" - persist.save_from_table(out_filename, out_rs, order) + persist.save_from_table(out_filename, out_rs, type_check.rockspec_order) util.printout("Wrote "..out_filename) 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 = { } } +rockspec_order = {"rockspec_format", "package", "version", + { "source", { "url", "tag", "branch", "md5" } }, + { "description", {"summary", "detailed", "homepage", "license" } }, + "supported_platforms", "dependencies", "external_dependencies", + { "build", {"type", "modules", "copy_directories", "platforms"} }, + "hooks"} + function load_extensions() rockspec_format = "1.1" rockspec_types.deploy = { diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua new file mode 100644 index 00000000..db0bcd44 --- /dev/null +++ b/src/luarocks/write_rockspec.lua @@ -0,0 +1,276 @@ + +module("luarocks.write_rockspec", package.seeall) + +local dir = require("luarocks.dir") +local fetch = require("luarocks.fetch") +local fs = require("luarocks.fs") +local path = require("luarocks.path") +local persist = require("luarocks.persist") +local type_check = require("luarocks.type_check") +local util = require("luarocks.util") + +help_summary = "Write a template for a rockspec file." +help_arguments = "[--output= ...] [] [|]" +help = [[ +This command writes an initial version of a rockspec file, +based on an URL or a local path. + +If a repository URL is given with no version, it creates an 'scm' rock. + +Note that the generated file is a _starting point_ for writing a +rockspec, and is not guaranteed to be complete or correct. + +--output= Write the rockspec with the given filename. + If not given, a file is written in the current + directory with a filename based on given name and version. +--license="" A license string, such as "MIT/X11" or "GNU GPL v3". +--summary="" A short one-line description summary. +--description="" A longer description string. +--homepage= Project homepage. +--lua-version= Supported Lua versions. Accepted values are "5.1", "5.2" + or "5.1,5.2". +--lib=[,] A comma-separated list of libraries that C files need to + link to. +]] + + +local function get_url(rockspec) + local url = rockspec.source.url + local file, temp_dir = fetch.fetch_sources(rockspec, true) + if not file then + util.warning("Could not fetch sources - "..temp_dir) + return false + end + util.printout("File successfully downloaded. Making checksum and checking base dir...") + local md5 = nil + if fetch.is_basic_protocol(rockspec.source.protocol) then + rockspec.source.md5 = fs.get_md5(file) + end + local ok, err = fs.change_dir(temp_dir) + if not ok then return false end + fs.unpack_archive(file) + local base_dir = fetch.url_to_base_dir(url) + if not fs.exists(base_dir) then + util.printerr("Directory "..base_dir.." not found") + local files = fs.list_dir() + if files[1] and fs.is_dir(files[1]) then + util.printerr("Found "..files[1]) + base_dir = files[1] + end + end + fs.pop_dir() + return true, base_dir, temp_dir +end + +local function configure_lua_version(rockspec, luaver) + if luaver == "5.1" then + table.insert(rockspec.dependencies, "lua ~> 5.1") + elseif luaver == "5.2" then + table.insert(rockspec.dependencies, "lua ~> 5.2") + elseif luaver == "5.1,5.2" then + table.insert(rockspec.dependencies, "lua >= 5.1, <= 5.3") + else + util.warning("Please specify supported Lua version with --lua-version=. "..util.see_help("write_rockspec")) + end +end + +local function detect_description(rockspec) + local fd = io.open("README.md", "r") + if not fd then fd = io.open("README", "r") end + if not fd then return end + local data = fd:read("*a") + fd:close() + local paragraph = data:match("\n\n(.-)\n\n") + if not paragraph then paragraph = data:match("\n\n(.*)") end + if paragraph then + if #paragraph < 80 then + rockspec.description.summary = paragraph:gsub("\n", "") + rockspec.description.detailed = paragraph + else + local summary = paragraph:gsub("\n", " "):match("([^.]*%.) ") + if summary then + rockspec.description.summary = summary:gsub("\n", "") + end + rockspec.description.detailed = paragraph + end + end +end + +local function get_cmod_name(file) + local fd = io.open(file, "r") + if not fd then return nil end + local data = fd:read("*a") + fd:close() + return (data:match("int%s+luaopen_([a-zA-Z0-9_]+)")) +end + +local luamod_blacklist = { + test = true, + tests = true, +} + +local function fill_as_builtin(rockspec, libs) + rockspec.build.type = "builtin" + rockspec.build.modules = {} + local prefix = "" + + for _, parent in ipairs({"src", "lua"}) do + if fs.is_dir(parent) then + fs.change_dir(parent) + prefix = parent.."/" + break + end + end + + local incdirs, libdirs + if libs then + incdirs, libdirs = {}, {} + for _, lib in ipairs(libs) do + local upper = lib:upper() + incdirs[#incdirs+1] = "$("..upper.."_INCDIR)" + libdirs[#libdirs+1] = "$("..upper.."_LIBDIR)" + end + end + + for _, file in ipairs(fs.find()) do + local luamod = file:match("(.*)%.lua$") + if luamod and not luamod_blacklist[luamod] then + rockspec.build.modules[path.path_to_module(file)] = prefix..file + else + local cmod = file:match("(.*)%.c$") + if cmod then + local modname = get_cmod_name(file) or path.path_to_module(file:gsub("%.c$", ".lua")) + rockspec.build.modules[modname] = { + sources = prefix..file, + libraries = libs, + incdirs = incdirs, + libdirs = libdirs, + } + end + end + end + + for _, directory in ipairs({ "doc", "docs", "samples", "tests" }) do + if fs.is_dir(directory) then + if not rockspec.build.copy_directories then + rockspec.build.copy_directories = {} + end + table.insert(rockspec.build.copy_directories, directory) + end + end + + if prefix ~= "" then + fs.pop_dir() + end +end + +local function rockspec_cleanup(rockspec) + rockspec.source.protocol = nil + rockspec.variables = nil + rockspec.name = nil +end + +function run(...) + local flags, name, version, local_dir = util.parse_flags(...) + + if not name then + return nil, "Missing arguments. "..util.see_help("write_rockspec") + end + + if name and not version then + local protocol, path = dir.split_url(name) + if not fetch.is_basic_protocol(protocol) then + name = dir.base_name(name):gsub("%.[^.]+$", "") + version = "scm" + local_dir = name + else + return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") + end + end + + if not local_dir then + local protocol, path = dir.split_url(version) + if not fetch.is_basic_protocol(protocol) then + local_dir = version + version = "scm" + elseif protocol ~= "file" then + return nil, "Missing version argument. "..util.see_help("write_rockspec") + end + end + + local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") + + local rockspec = { + package = name, + name = name:lower(), + version = version.."-1", + source = { + url = "*** please add URL for source tarball, zip or repository here ***" + }, + description = { + summary = flags["summary"] or "*** please specify description summary ***", + detailed = flags["detailed"] or "*** please enter a detailed description ***", + homepage = flags["homepage"] or "*** please enter a project homepage ***", + license = flags["license"] or "*** please specify a license ***", + }, + dependencies = {}, + build = {}, + } + path.configure_paths(rockspec) + rockspec.source.protocol = dir.split_url(local_dir) + + configure_lua_version(rockspec, flags["lua-version"]) + + if local_dir:match("://") then + rockspec.source.url = local_dir + if not fetch.is_basic_protocol(rockspec.source.protocol) then + if version ~= "scm" then + rockspec.source.tag = "v" .. version + end + end + local ok, base_dir, temp_dir = get_url(rockspec) + if ok then + if base_dir ~= dir.base_name(local_dir) then + rockspec.source.dir = base_dir + end + end + if base_dir then + local_dir = dir.path(temp_dir, base_dir) + else + local_dir = nil + end + end + + if not local_dir then + local_dir = "." + end + + local libs = nil + if flags["lib"] then + libs = {} + rockspec.external_dependencies = {} + for lib in flags["lib"]:gmatch("([^,]+)") do + table.insert(libs, lib) + rockspec.external_dependencies[lib:upper()] = { + library = lib + } + end + end + + local ok, err = fs.change_dir(local_dir) + if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end + + detect_description(rockspec) + + fill_as_builtin(rockspec, libs) + + rockspec_cleanup(rockspec) + + persist.save_from_table(filename, rockspec, type_check.rockspec_order) + + util.printout() + util.printout("Wrote template at "..filename.." -- you should now edit and finish it.") + util.printout() + + return true +end -- cgit v1.2.3-55-g6feb From c0a59c50fff8455bfa5a094146a5823570ba42b5 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 11 Oct 2013 20:27:29 -0300 Subject: minor fix! --- src/luarocks/write_rockspec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index db0bcd44..68547cdf 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua @@ -180,9 +180,9 @@ function run(...) if name and not version then local protocol, path = dir.split_url(name) if not fetch.is_basic_protocol(protocol) then - name = dir.base_name(name):gsub("%.[^.]+$", "") - version = "scm" local_dir = name + version = "scm" + name = dir.base_name(name):gsub("%.[^.]+$", "") else return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") end -- cgit v1.2.3-55-g6feb From 5b699730c7a525c0f22bbf507aabad9fe8cfb762 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 12 Oct 2013 13:06:18 -0300 Subject: Add reference to write_rockspec.lua in Makefile --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1213a589..202f11aa 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 \ fs/lua.lua persist.lua list.lua require.lua repos.lua dir.lua make_manifest.lua \ command_line.lua install.lua build/command.lua build/cmake.lua build/make.lua \ build/builtin.lua fetch/cvs.lua fetch/git.lua fetch/sscm.lua tools/patch.lua \ -fetch/svn.lua tools/zip.lua tools/tar.lua pack.lua type_check.lua make.lua path.lua \ +fetch/svn.lua tools/zip.lua tools/tar.lua pack.lua type_check.lua make.lua \ remove.lua fs.lua manif.lua add.lua deps.lua build.lua search.lua show.lua \ manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \ help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \ -admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua purge.lua +admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \ +purge.lua path.lua write_rockspec.lua CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua -- cgit v1.2.3-55-g6feb From 57bde51526bcd9c022e29802f29ae432a3a03bef Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 12 Oct 2013 13:07:33 -0300 Subject: Some tests require a local sshd server. Add a small check and message to myself, to avoid running the whole thing only to have it fail at the very end. --- test/testing.sh | 8 ++++++++ 1 file changed, 8 insertions(+) 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 @@ exit 1 } +if [ -z "$@"] +then + ps aux | grep -q '[s]shd' || { + echo "Run sudo /bin/sshd in order to perform all tests." + exit 1 + } +fi + testing_dir="$PWD" testing_tree="$testing_dir/testing" -- cgit v1.2.3-55-g6feb