From 478fc5517c686c080797f840cc000cc9828ffcb4 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Thu, 20 Oct 2016 23:22:44 +0300 Subject: Remove some unused locals and imports --- src/luarocks/build.lua | 2 +- src/luarocks/command_line.lua | 1 - src/luarocks/deps.lua | 1 - src/luarocks/manif.lua | 3 +-- src/luarocks/path_cmd.lua | 3 --- src/luarocks/remove.lua | 1 - 6 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index f52fb7a8..20d094b1 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -203,7 +203,7 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m end if not minimal_mode then - local _, source_dir + local source_dir if need_to_fetch then ok, source_dir, errcode = fetch.fetch_sources(rockspec, true) if not ok then diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 858e871f..ecf3a61b 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -2,7 +2,6 @@ --- Functions for command-line scripts. local command_line = {} -local pack = function(...) return {...}, select("#", ...) end local unpack = unpack or table.unpack local util = require("luarocks.util") diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index f8deff3c..756ba6bd 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -691,7 +691,6 @@ function deps.scan_deps(results, missing, manifest, name, version, deps_mode) local fetch = require("luarocks.fetch") - local err if results[name] then return results, missing end diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 1b75452b..2d983a85 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -55,7 +55,6 @@ end function manif.make_rock_manifest(name, version) local install_dir = path.install_dir(name, version) - local rock_manifest = path.rock_manifest_file(name, version) local tree = {} for _, file in ipairs(fs.find(install_dir)) do local full_path = dir.path(install_dir, file) @@ -80,7 +79,7 @@ function manif.make_rock_manifest(name, version) last[last_name] = sum end end - rock_manifest = { rock_manifest=tree } + local rock_manifest = { rock_manifest=tree } manif.rock_manifest_cache[name.."/"..version] = rock_manifest save_table(install_dir, "rock_manifest", rock_manifest ) end diff --git a/src/luarocks/path_cmd.lua b/src/luarocks/path_cmd.lua index 15fb9ca2..eba85d46 100644 --- a/src/luarocks/path_cmd.lua +++ b/src/luarocks/path_cmd.lua @@ -4,7 +4,6 @@ local path_cmd = {} local util = require("luarocks.util") -local deps = require("luarocks.deps") local cfg = require("luarocks.cfg") util.add_run_function(path_cmd) @@ -35,8 +34,6 @@ And on Windows: --- Driver function for "path" command. -- @return boolean This function always succeeds. function path_cmd.command(flags) - local deps_mode = deps.get_deps_mode(flags) - local lr_path, lr_cpath, lr_bin = cfg.package_paths(flags["tree"]) local path_sep = cfg.export_path_separator diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 82c9818b..54756388 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -11,7 +11,6 @@ local repos = require("luarocks.repos") local path = require("luarocks.path") local util = require("luarocks.util") local cfg = require("luarocks.cfg") -local manif = require("luarocks.manif") local fs = require("luarocks.fs") util.add_run_function(remove) -- cgit v1.2.3-55-g6feb From cc76ce062f587b8a2ce6f34ca7ad57c585b82117 Mon Sep 17 00:00:00 2001 From: Hisham Date: Tue, 25 Oct 2016 16:43:18 -0200 Subject: Check rockspec_version before running type check. --- src/luarocks/fetch.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 824a3731..76f366cd 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -197,18 +197,18 @@ function fetch.load_local_rockspec(filename, quick) end local globals = err + if rockspec.rockspec_format then + if deps.compare_versions(rockspec.rockspec_format, type_check.rockspec_format) then + return nil, "Rockspec format "..rockspec.rockspec_format.." is not supported, please upgrade LuaRocks." + end + end + if not quick then local ok, err = type_check.type_check_rockspec(rockspec, globals) if not ok then return nil, filename..": "..err end end - - if rockspec.rockspec_format then - if deps.compare_versions(rockspec.rockspec_format, type_check.rockspec_format) then - return nil, "Rockspec format "..rockspec.rockspec_format.." is not supported, please upgrade LuaRocks." - end - end util.platform_overrides(rockspec.build) util.platform_overrides(rockspec.dependencies) -- cgit v1.2.3-55-g6feb From e5f6a46679192893782a58e17ccd3d371964ae6f Mon Sep 17 00:00:00 2001 From: Hisham Date: Tue, 25 Oct 2016 18:18:06 -0200 Subject: Add link_lua_explicitly option. Remove explicit reference to cygwin, and make option available for custom environments. --- src/luarocks/build/builtin.lua | 2 +- src/luarocks/cfg.lua | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 6719be81..c36aa96f 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -164,7 +164,7 @@ function builtin.run(rockspec) add_flags(extras, "-Wl,-rpath,%s:", libdirs) end add_flags(extras, "-l%s", libraries) - if cfg.is_platform("cygwin") then + if cfg.link_lua_explicitly then add_flags(extras, "-l%s", {"lua"}) end return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 33176161..9200dd26 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -315,6 +315,7 @@ local defaults = { arch = "unknown", lib_extension = "unknown", obj_extension = "unknown", + link_lua_explicitly = false, rocks_servers = { { @@ -527,6 +528,7 @@ if cfg.platforms.cygwin then defaults.variables.CC = "echo -llua | xargs gcc" defaults.variables.LD = "echo -llua | xargs gcc" defaults.variables.LIBFLAG = "-shared" + defaults.link_lua_explicitly = true end if cfg.platforms.msys then -- cgit v1.2.3-55-g6feb From a9c34fc0c92a5931eb73d867d18fbad410683ea0 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Wed, 26 Oct 2016 16:22:10 +0300 Subject: Treat rock name arguments in case insensitive way Internally package names are lowercased, however, rockspec may contain a name with uppercase letters, which will be displayed by `luarocks show`. Some commands, like `luarocks search`, `luarocks install` and `luarocks build`, support this and convert input name to lowercase before passing it to interanl functions. Do the same thing in other commands accepting rock names. --- src/luarocks/doc.lua | 2 ++ src/luarocks/download.lua | 2 +- src/luarocks/lint.lua | 2 +- src/luarocks/new_version.lua | 2 +- src/luarocks/pack.lua | 2 +- src/luarocks/remove.lua | 1 + src/luarocks/show.lua | 2 +- src/luarocks/unpack.lua | 2 +- 8 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index 15460b31..423ebe02 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua @@ -63,6 +63,8 @@ function doc.command(flags, name, version) return nil, "Argument missing. "..util.see_help("doc") end + name = name:lower() + local iname, iversion, repo = search.pick_installed_rock(name, version, flags["tree"]) if not iname then util.printout(name..(version and " "..version or "").." is not installed. Looking for it in the rocks servers...") diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 18573ae4..e434cdbb 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua @@ -102,7 +102,7 @@ function download.command(flags, name, version) arch = flags["arch"] end - local dl, err = download.download(arch, name, version, flags["all"]) + local dl, err = download.download(arch, name:lower(), version, flags["all"]) return dl and true, err end diff --git a/src/luarocks/lint.lua b/src/luarocks/lint.lua index d5cc48d0..0fd81a20 100644 --- a/src/luarocks/lint.lua +++ b/src/luarocks/lint.lua @@ -26,7 +26,7 @@ function lint.command(flags, input) local filename = input if not input:match(".rockspec$") then local err - filename, err = download.download("rockspec", input) + filename, err = download.download("rockspec", input:lower()) if not filename then return nil, err end diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index 8fc00a86..91f7607c 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua @@ -141,7 +141,7 @@ function new_version.command(flags, input, version, url) return nil, err end else - filename, err = download.download("rockspec", input) + filename, err = download.download("rockspec", input:lower()) if not filename then return nil, err end diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 932ff0d5..35bbe838 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -184,7 +184,7 @@ function pack.command(flags, arg, version) if arg:match(".*%.rockspec") then file, err = pack.pack_source_rock(arg) else - file, err = do_pack_binary_rock(arg, version, flags["tree"]) + file, err = do_pack_binary_rock(arg:lower(), version, flags["tree"]) end if err then return nil, err diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 54756388..601eedcf 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -155,6 +155,7 @@ function remove.command(flags, name, version) end local results = {} + name = name:lower() search.manifest_search(results, cfg.rocks_dir, search.make_query(name, version)) if not results[name] then return nil, "Could not find rock '"..name..(version and " "..version or "").."' in "..path.rocks_tree_to_string(cfg.root_dir) diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 88f9512d..85c7edcb 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -78,7 +78,7 @@ function show.command(flags, name, version) end local repo, repo_url - name, version, repo, repo_url = search.pick_installed_rock(name, version, flags["tree"]) + name, version, repo, repo_url = search.pick_installed_rock(name:lower(), version, flags["tree"]) if not name then return nil, version end diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua index c3dc9a4c..0922f9b9 100644 --- a/src/luarocks/unpack.lua +++ b/src/luarocks/unpack.lua @@ -159,7 +159,7 @@ function unpack.command(flags, name, version) return run_unpacker(name, flags["force"]) else local search = require("luarocks.search") - return search.act_on_src_or_rockspec(run_unpacker, name, version) + return search.act_on_src_or_rockspec(run_unpacker, name:lower(), version) end end -- cgit v1.2.3-55-g6feb From 6a72d843a7bb3dc9f5e133f9a9d614af46f92daa Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Wed, 26 Oct 2016 16:26:53 +0300 Subject: Add two tests for uppercase rock name arguments --- spec/remove_spec.lua | 9 ++++++++- spec/show_spec.lua | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index 3d321e30..03b3681e 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua @@ -35,12 +35,19 @@ describe("LuaRocks remove tests #blackbox #b_remove", function() assert.is_false(run.luarocks_bool("remove luacov --deps-mode")) end) - it("LuaRocks remove builded abelhas", function() + it("LuaRocks remove built abelhas", function() assert.is_true(run.luarocks_bool("build abelhas 1.0")) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/abelhas")) assert.is_true(run.luarocks_bool("remove abelhas 1.0")) assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/abelhas")) end) + + it("LuaRocks remove built abelhas with uppercase name", function() + assert.is_true(run.luarocks_bool("build abelhas 1.0")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/abelhas")) + assert.is_true(run.luarocks_bool("remove Abelhas 1.0")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/abelhas")) + end) end) describe("LuaRocks remove more complex tests", function() diff --git a/spec/show_spec.lua b/spec/show_spec.lua index b2cdc07e..d07fdc31 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua @@ -22,6 +22,11 @@ describe("LuaRocks show tests #blackbox #b_show", function() local output = run.luarocks("show luacov") assert.is.truthy(output:match("LuaCov")) end) + + it("LuaRocks show luacov with uppercase name", function() + local output = run.luarocks("show LuaCov") + assert.is.truthy(output:match("LuaCov")) + end) it("LuaRocks show modules of luacov", function() local output = run.luarocks("show --modules luacov") -- cgit v1.2.3-55-g6feb From 48e5329617f20e97262ca5510264fdb5d645ae6f Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 26 Oct 2016 15:18:58 -0200 Subject: Improve check of Lua interpreter (e.g. allow it to find `lua5.1` when lua is 5.3 and only `--lua-version=5.1` is given). --- configure | 77 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/configure b/configure index 3636aed3..15cc21f8 100755 --- a/configure +++ b/configure @@ -229,15 +229,17 @@ detect_lua_version() { detected_lua=`$1 -e 'print(_VERSION:match(" (5%.[123])$"))' 2> /dev/null` if [ "$detected_lua" != "nil" ] then - echo "Lua version detected: $detected_lua" if [ "$LUA_VERSION_SET" != "yes" ] then + echo "Lua version detected: $detected_lua" LUA_VERSION=$detected_lua - elif [ "$LUA_VERSION" != "$detected_lua" ] + return 0 + elif [ "$LUA_VERSION" = "$detected_lua" ] then - die "This clashes with the value of --lua-version. Please check your configuration." + return 0 fi fi + return 1 } search_interpreter() { @@ -247,23 +249,35 @@ search_interpreter() { find_lua="$LUA_BINDIR" elif [ "$LUA_DIR_SET" = "yes" ] then - if [ -f "$LUA_DIR/bin/lua$suffix" ] + LUA_BINDIR="$LUA_DIR/bin" + if [ -f "$LUA_BINDIR/lua$suffix" ] then - find_lua="$LUA_DIR/bin" + find_lua="$LUA_BINDIR" fi else find_lua=`find_program lua$suffix` fi if [ -n "$find_lua" -a -x "$find_lua/lua$suffix" ] then - echo "Lua interpreter found: $find_lua/lua$suffix..." - LUA_SUFFIX=$suffix - detect_lua_version "$find_lua/lua$LUA_SUFFIX" - return 0 + if detect_lua_version "$find_lua/lua$suffix" + then + echo "Lua interpreter found: $find_lua/lua$suffix..." + if [ "$LUA_BINDIR_SET" != "yes" ] + then + LUA_BINDIR="$find_lua" + fi + if [ "$LUA_DIR_SET" != "yes" ] + then + LUA_DIR=`dirname "$find_lua"` + fi + LUA_SUFFIX="$suffix" + return 0 + fi fi return 1 } +lua_interp_found=no if [ "$LUA_SUFFIX_SET" != "yes" ] then if [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.1" ] @@ -278,7 +292,6 @@ then else suffixes="5.3 53 -5.3 -53 5.2 52 -5.2 -52 5.1 51 -5.1 -51" fi - lua_interp_found=no for suffix in "" `echo $suffixes` do search_interpreter "$suffix" && { @@ -286,23 +299,28 @@ then break } done +else + search_interpreter "$LUA_SUFFIX" && { + lua_interp_found=yes + } fi -if [ "$LUA_DIR_SET" != "yes" ] +if [ "$lua_interp_found" != "yes" ] then - if [ -z "$find_lua" ] - then - echo_n "Looking for Lua... " - find_lua=`find_program lua$LUA_SUFFIX` - fi + [ "$LUA_VERSION_SET" ] && { interp="Lua $LUA_VERSION" ;} || { interp="Lua" ;} + [ "$LUA_DIR_SET" -o "$LUA_BINDIR_SET" ] && { where="$LUA_BINDIR" ;} || { interp="\$PATH" ;} + echo "$interp interpreter not found in $where" + die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help." +fi - if [ -n "$find_lua" ] +if [ "$LUA_VERSION_SET" = "yes" ] +then + echo_n "Checking if $LUA_BINDIR/lua$LUA_SUFFIX is Lua version $LUA_VERSION... " + if detect_lua_version "$LUA_BINDIR/lua$LUA_SUFFIX" then - LUA_DIR=`dirname $find_lua` - LUA_BINDIR="$find_lua" - echo "lua$LUA_SUFFIX found in \$PATH: $find_lua" + echo "yes" else - echo "lua$LUA_SUFFIX not found in \$PATH." + echo "no" die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help." fi fi @@ -317,23 +335,6 @@ then LUA_LIBDIR="$LUA_DIR/lib" fi -if [ "$LUA_DIR_SET" = "yes" -a "$LUA_BINDIR_SET" != "yes" ] -then - LUA_BINDIR="$LUA_DIR/bin" -fi - -if [ "$lua_interp_found" != "yes" ] -then - echo_n "Checking Lua interpreter... " - if [ -x "$LUA_BINDIR/lua$LUA_SUFFIX" ] - then - echo "lua$LUA_SUFFIX found in $LUA_BINDIR" - else - echo "lua$LUA_SUFFIX not found (looked in $LUA_BINDIR)" - die "You may want to use the flag --with-lua or --with-lua-bin. See --help." - fi -fi - echo_n "Checking Lua includes... " lua_h="$LUA_INCDIR/lua.h" if [ -f "$lua_h" ] -- cgit v1.2.3-55-g6feb From 86e1bef85084b5bf09688bd19077a8eaa82ae15c Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 26 Oct 2016 15:19:42 -0200 Subject: Check if header matches interpreter. --- configure | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/configure b/configure index 15cc21f8..ae2696d2 100755 --- a/configure +++ b/configure @@ -361,6 +361,18 @@ else fi fi +echo_n "Checking if Lua header version matches that of the interpreter... " +header_version=$(sed -n 's/.*LUA_VERSION_NUM.*5.\(.\).*/5.\1/p' "$lua_h") +if [ "$header_version" = "$LUA_VERSION" ] +then + echo "yes" +else + echo "no" + echo "lua.h version mismatch (interpreter: $LUA_VERSION; lua.h: $header_version)." + die "You may want to use the flag --with-lua or --with-lua-include. See --help." +fi + + if [ "$LUAROCKS_DOWNLOADER_SET" != "yes" ] then find_helper "a downloader helper program" curl wget fetch -- cgit v1.2.3-55-g6feb From f7ae6213f430798ec86883f9ab9917b156e1758d Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 26 Oct 2016 15:28:23 -0200 Subject: Support user-defined platforms array. Let the user set their own custom platform entries, but also provide fallbacks to make sure things work. --- src/luarocks/cfg.lua | 87 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 30 deletions(-) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 9200dd26..1141acf6 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -131,24 +131,27 @@ else -- Fall back to Unix in unknown systems. end --- Set order for platform overrides +-- Set order for platform overrides. +-- More general platform identifiers should be listed first, +-- more specific ones later. local platform_order = { -- Unixes - unix = 1, - bsd = 2, - solaris = 3, - netbsd = 4, - openbsd = 5, - freebsd = 6, - linux = 7, - macosx = 8, - cygwin = 9, - msys = 10, - haiku = 11, + "unix", + "bsd", + "solaris", + "netbsd", + "openbsd", + "freebsd", + "linux", + "macosx", + "cygwin", + "msys", + "haiku", -- Windows - win32 = 12, - mingw32 = 13, - windows = 14 } + "win32", + "mingw32", + "windows", +} -- Path configuration: local sys_config_file, home_config_file @@ -274,26 +277,50 @@ if not next(cfg.rocks_trees) then end end - -- update platforms list; keyed -> array do - local lst = {} -- use temp array to not confuse `pairs` in loop - for plat in pairs(cfg.platforms) do - if cfg.platforms[plat] then -- entries set to 'false' skipped - if not platform_order[plat] then - local pl = "" - for k,_ in pairs(platform_order) do pl = pl .. ", " .. k end - io.stderr:write("Bad platform given; "..tostring(plat)..". Valid entries are: "..pl:sub(3,-1) ..".\n") - os.exit(cfg.errorcodes.CONFIGFILE) + -- if explicitly given by user, + if cfg.platforms[1] then + local is_windows = cfg.platforms.windows + -- Clear auto-detected values + for k, _ in pairs(cfg.platforms) do + if type(k) == "string" then + cfg.platforms[k] = nil + end + end + -- and set the ones given by the user. + for _, plat in ipairs(cfg.platforms) do + cfg.platforms[plat] = true + end + -- If no major platform family was set by the user, + if not (cfg.platforms.unix or cfg.platforms.windows) then + -- set some fallback defaults in case the user provides an incomplete configuration. + -- LuaRocks expects a set of defaults to be available. + -- This is used for setting defaults here only; the platform overrides + -- will use only the user's list. + if is_windows then + cfg.platforms.windows = true + table.insert(cfg.platforms, "windows") + else + cfg.platforms.unix = true + table.insert(cfg.platforms, "unix") + end + end + else + -- Sort detected platform defaults + local order = {} + for i, v in ipairs(platform_order) do + order[v] = i + end + local entries = {} + for k, v in pairs(cfg.platforms) do + if type(k) == "string" and v == true then + table.insert(entries, k) end - table.insert(lst, plat) - else - cfg.platforms[plat] = nil end + table.sort(entries, function(a, b) return order[a] < order[b] end) + util.deep_merge(cfg.platforms, entries) end - -- platform overrides depent on the order, so set priorities - table.sort(lst, function(key1, key2) return platform_order[key1] < platform_order[key2] end) - util.deep_merge(cfg.platforms, lst) end -- Configure defaults: -- cgit v1.2.3-55-g6feb