From f1fbc5c0c4f50e16e1f82ce9374080659320a899 Mon Sep 17 00:00:00 2001 From: Kyle McLamb Date: Fri, 19 Feb 2016 02:53:35 -0500 Subject: Use mkdtemp() where available --- src/luarocks/cfg.lua | 1 + src/luarocks/fs/lua.lua | 36 +++++++++++++++++------------------- src/luarocks/fs/unix.lua | 2 -- src/luarocks/fs/unix/tools.lua | 18 ++++++++++++++++++ src/luarocks/fs/win32.lua | 19 +++++++++++++++++++ 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 0099ec3a..de0a8e65 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -362,6 +362,7 @@ local defaults = { FIND = "find", TEST = "test", CHMOD = "chmod", + MKTEMP = "mktemp", ZIP = "zip", UNZIP = "unzip -n", diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 1d303c67..8f45a829 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -28,8 +28,6 @@ local patch = require("luarocks.tools.patch") local dir_stack = {} -math.randomseed(os.time()) - local dir_separator = "/" --- Quote argument for shell processing. @@ -67,23 +65,6 @@ function fs_lua.is_writable(file) return result end ---- Create a temporary directory. --- @param name string: name pattern to use for avoiding conflicts --- when creating temporary directory. --- @return string or (nil, string): name of temporary directory or (nil, error message) on failure. -function fs_lua.make_temp_dir(name) - assert(type(name) == "string") - name = dir.normalize(name) - - local temp_dir = (os.getenv("TMP") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000)) - local ok, err = fs.make_dir(temp_dir) - if ok then - return temp_dir - else - return nil, err - end -end - local function quote_args(command, ...) local out = { command } for _, arg in ipairs({...}) do @@ -785,6 +766,23 @@ function fs_lua.get_permissions(file) return posix.stat(file, "mode") end +--- Create a temporary directory. +-- @param name string: name pattern to use for avoiding conflicts +-- when creating temporary directory. +-- @return string or (nil, string): name of temporary directory or (nil, error message) on failure. +function fs_lua.make_temp_dir(name) + assert(type(name) == "string") + name = dir.normalize(name) + + local template = (os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-XXXXXX" + local temp_dir, err = posix.mkdtemp(template) + if temp_dir then + return temp_dir + else + return nil, err + end +end + end --------------------------------------------------------------------- diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 8eb3386a..570b26e4 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -9,8 +9,6 @@ local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") local util = require("luarocks.util") -math.randomseed(os.time()) - --- Annotate command string for quiet execution. -- @param cmd string: A command-line string. -- @return string: The command-line, with silencing annotation. diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 442004ce..c6673ad5 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -351,4 +351,22 @@ function tools.set_time(file, time) return fs.execute(vars.TOUCH, "-d", "@"..tostring(time), file) end +--- Create a temporary directory. +-- @param name string: name pattern to use for avoiding conflicts +-- when creating temporary directory. +-- @return string or (nil, string): name of temporary directory or (nil, error message) on failure. +function tools.make_temp_dir(name) + assert(type(name) == "string") + name = dir.normalize(name) + + local template = (os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-XXXXXX" + local pipe = io.popen(vars.MKTEMP.." -d "..fs.Q(template)) + local dirname = pipe:read("*l") + pipe:close() + if dirname and dirname:match("^/") then + return dirname + end + return nil, "Failed to create temporary directory "..tostring(dirname) +end + return tools diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 0c8cc9e9..c14c421b 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -10,6 +10,8 @@ local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") local util = require("luarocks.util") +math.randomseed(os.time()) + -- Monkey patch io.popen and os.execute to make sure quoting -- works as expected. -- See http://lua-users.org/lists/lua-l/2013-11/msg00367.html @@ -221,6 +223,23 @@ function win32.is_writable(file) return result end +--- Create a temporary directory. +-- @param name string: name pattern to use for avoiding conflicts +-- when creating temporary directory. +-- @return string or (nil, string): name of temporary directory or (nil, error message) on failure. +function win32.make_temp_dir(name) + assert(type(name) == "string") + name = dir.normalize(name) + + local temp_dir = os.getenv("TMP") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000)) + local ok, err = fs.make_dir(temp_dir) + if ok then + return temp_dir + else + return nil, err + end +end + function win32.tmpname() return os.getenv("TMP")..os.tmpname() end -- cgit v1.2.3-55-g6feb From 22e033cd800c00d01ef3b43b664bb5b5e7b18aff Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 7 Apr 2016 22:51:30 +0300 Subject: Don't report missing manifests in 'luarocks list' --- src/luarocks/list.lua | 4 ++-- src/luarocks/manif_core.lua | 12 +++++++----- src/luarocks/search.lua | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua index fddded03..99868028 100644 --- a/src/luarocks/list.lua +++ b/src/luarocks/list.lua @@ -93,8 +93,8 @@ function list.run(...) local results = {} for _, tree in ipairs(trees) do - local ok, err = search.manifest_search(results, path.rocks_dir(tree), query) - if not ok then + local ok, err, errcode = search.manifest_search(results, path.rocks_dir(tree), query) + if not ok and errcode ~= "open" then util.warning(err) end end diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua index d719caa2..87fc16cf 100644 --- a/src/luarocks/manif_core.lua +++ b/src/luarocks/manif_core.lua @@ -18,16 +18,18 @@ manif_core.manifest_cache = {} -- @param file string: The local filename of the manifest file. -- @param repo_url string: The repository identifier. -- @param quick boolean: If given, skips type checking. +-- @return table or (nil, string, string): the manifest or nil, +-- error message and error code ("open", "load", "run" or "type"). function manif_core.manifest_loader(file, repo_url, quick) - local manifest, err = persist.load_into_table(file) + local manifest, err, errcode = persist.load_into_table(file) if not manifest then - return nil, "Failed loading manifest for "..repo_url..": "..err + return nil, "Failed loading manifest for "..repo_url..": "..err, errcode end local globals = err if not quick then local ok, err = type_check.type_check_manifest(manifest, globals) if not ok then - return nil, "Error checking manifest: "..err + return nil, "Error checking manifest: "..err, "type" end end @@ -39,8 +41,8 @@ end -- All functions that use manifest tables assume they were obtained -- through either this function or load_manifest. -- @param repo_url string: URL or pathname for the repository. --- @return table or (nil, string): A table representing the manifest, --- or nil followed by an error message. +-- @return table or (nil, string, string): A table representing the manifest, +-- or nil followed by an error message and an error code, see manifest_loader. function manif_core.load_local_manifest(repo_url) assert(type(repo_url) == "string") diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 5e6cf50e..a06fdd45 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -170,7 +170,7 @@ end -- If the arch field is omitted, the local architecture (cfg.arch) -- is used. The special value "any" is also recognized, returning all -- matches regardless of architecture. --- @return true or, in case of errors, nil and an error message. +-- @return true or, in case of errors, nil, an error message and an optional error code. function search.manifest_search(results, repo, query) assert(type(results) == "table") assert(type(repo) == "string") -- cgit v1.2.3-55-g6feb From 46721bbeb6e91411b406b948c60fe25f3213d4de Mon Sep 17 00:00:00 2001 From: Mihai Branescu Date: Sun, 10 Apr 2016 17:01:54 +0300 Subject: A number of tests for the luaRocks test suite. --- test/testing.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/testing.sh b/test/testing.sh index 106f31cd..93c94334 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -329,7 +329,6 @@ need() { need_luasocket() { need luasocket $verrev_luasocket; } # Tests ######################################### - test_version() { $luarocks --version; } fail_unknown_command() { $luarocks unknown_command; } @@ -410,6 +409,7 @@ test_download_rockspecversion() { $luarocks download --rockspec validate-args ${ test_help() { $luarocks help; } fail_help_invalid() { $luarocks help invalid; } +test_install_only_deps() { $luarocks install --only-deps "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; } test_install_binaryrock() { $luarocks build --pack-binary-rock cprint && $luarocks install ./cprint-${verrev_cprint}.${platform}.rock && rm ./cprint-${verrev_cprint}.${platform}.rock; } test_install_with_bin() { $luarocks install wsapi; } fail_install_notazipfile() { $luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"; } @@ -451,7 +451,9 @@ test_path_lr_cpath() { $luarocks path --lr-cpath; } test_path_lr_bin() { $luarocks path --lr-bin; } fail_purge_missing_tree() { $luarocks purge --tree="$testing_tree"; } +fail_purge_tree_notstring() { $luarocks purge --tree=1; } test_purge() { $luarocks purge --tree="$testing_sys_tree"; } +test_purge_oldversions() { $luarocks purge --old-versions --tree="$testing_sys_tree"; } test_remove() { $luarocks build abelhas ${version_abelhas} && $luarocks remove abelhas ${version_abelhas}; } test_remove_force() { need_luasocket; $luarocks build lualogging && $luarocks remove --force luasocket; } @@ -485,6 +487,9 @@ fail_unpack_invalidrockspec() { need_luasocket; $luarocks unpack "invalid.rocksp fail_upload_invalidrockspec() { $luarocks upload "invalid.rockspec"; } fail_upload_invalidkey() { $luarocks upload --api-key="invalid" "invalid.rockspec"; } +fail_upload_skippack() { $luarocks upload --api-key="invalid" --skip-pack "luacov-${verrev_luacov}.rockspec"; } +fail_upload_force() { $luarocks install lua-cjson && $luarocks upload --api-key="invalid" --force "luacov-${verrev_luacov}.rockspec" && $luarocks remove lua-cjson; } + test_admin_help() { $luarocks_admin help; } @@ -547,6 +552,9 @@ EOF test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } test_doc_home() { $luarocks install luacov; $luarocks doc luacov --home; } fail_doc_invalid() { $luarocks doc invalid; } +test_doc_list() { $luarocks install luacov; $luarocks doc luacov --list; } +test_doc_local() { $luarocks install luacov; $luarocks doc luacov --local; } +test_doc_porcelain() { $luarocks install luacov; $luarocks doc luacov --porcelain; } # Driver ######################################### -- cgit v1.2.3-55-g6feb From e92777fb37f27c6c8ddcbbaf9bc492e291ee808c Mon Sep 17 00:00:00 2001 From: Hisham Date: Mon, 18 Apr 2016 13:34:49 -0300 Subject: Update LuaSec --- test/testing.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testing.sh b/test/testing.sh index 106f31cd..8270fc3e 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -237,7 +237,7 @@ mkdir -p "$testing_server" get "$luarocks_repo/stdlib-41.0.0-1.src.rock" get "$luarocks_repo/luarepl-0.4-1.src.rock" get "$luarocks_repo/validate-args-1.5.4-1.rockspec" - get "$luarocks_repo/luasec-0.5-2.rockspec" + get "$luarocks_repo/luasec-0.6-1.rockspec" get "$luarocks_repo/luabitop-1.0.2-1.rockspec" get "$luarocks_repo/luabitop-1.0.2-1.src.rock" get "$luarocks_repo/lpty-1.0.1-1.src.rock" -- cgit v1.2.3-55-g6feb From 0039368efa502cd3faafff849b237b36eef8b3a2 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Mon, 18 Apr 2016 21:25:09 +0300 Subject: Update LuaCov --- test/testing.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testing.sh b/test/testing.sh index 8270fc3e..f3b917c0 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -179,7 +179,7 @@ srcdir_luasocket=luasocket-3.0-rc1 version_cprint=0.1 verrev_cprint=0.1-2 -version_luacov=0.9.1 +version_luacov=0.11.0 verrev_luacov=${version_luacov}-1 version_lxsh=0.8.6 version_validate_args=1.5.4 -- cgit v1.2.3-55-g6feb From 608467a030aa14919e06b2ff8cae529d0db273bd Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sun, 20 Mar 2016 13:05:10 +0300 Subject: Show search error in functions using find_suitable_rock --- src/luarocks/deps.lua | 2 +- src/luarocks/download.lua | 7 +++++-- src/luarocks/search.lua | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 278b6356..812e6d18 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -486,7 +486,7 @@ function deps.fulfill_dependencies(rockspec, deps_mode) if not match_dep(dep, nil, deps_mode) then local url, err = search.find_suitable_rock(dep) if not url then - return nil, "Could not satisfy dependency: "..deps.show_dep(dep) + return nil, "Could not satisfy dependency "..deps.show_dep(dep)..": "..err end local ok, err, errcode = install.run(url, deps.deps_mode_to_flag(deps_mode)) if not ok then diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index f08ba7fe..090f49aa 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua @@ -39,6 +39,7 @@ end function download.download(arch, name, version, all) local query = search.make_query(name, version) if arch then query.arch = arch end + local search_err if all then if name == "" then query.exact_name = false end @@ -67,12 +68,14 @@ function download.download(arch, name, version, all) return all_ok, any_err end else - local url = search.find_suitable_rock(query) + local url + url, search_err = search.find_suitable_rock(query) if url then return get_file(url) end end - return nil, "Could not find a result named "..name..(version and " "..version or "").."." + return nil, "Could not find a result named "..name..(version and " "..version or "").. + (search_err and ": "..search_err or ".") end --- Driver function for the "download" command. diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index a06fdd45..0276dfae 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -369,7 +369,7 @@ function search.act_on_src_or_rockspec(action, name, version, ...) query.arch = "src|rockspec" local url, err = search.find_suitable_rock(query) if not url then - return nil, "Could not find a result named "..name..(version and " "..version or "").."." + return nil, "Could not find a result named "..name..(version and " "..version or "")..": "..err end return action(url, ...) end -- cgit v1.2.3-55-g6feb From 302025e1812ea790248a14b425f8c46b153af622 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 19 Mar 2016 15:50:20 +0300 Subject: Show if rock is supported on other Lua versions on search fail Supporting changes: * Change structure of manifest cache: map from repo_url to tables mapping from lua versions to manifests. * New manif_core cache_manifest and get_cached_manifest functions to hide cache implementation. * lua_version optional argument for functions between search.find_suitable_rock and manifest loader. Main changes: * Add a helper function supported_lua_versions that checks which Lua versions can satisfy a query. * Use this helper function when a search for a rock failed, in search.find_suitable_rock, if constraints can be satisfied under a different Lua version mention that in the error message. Examples of error messages: * Constraint "sailor": "sailor supports only Lua 5.1 and Lua 5.2 but not Lua 5.3." * Constraint "sailor 0.5": "sailor 0.5 supports only Lua 5.1 and Lua 5.2 but not Lua 5.3." * Constraint "sailor >= 0.5": "Matching sailor versions support only Lua 5.1 and Lua 5.2 but not Lua 5.3." --- src/luarocks/manif.lua | 20 ++++++++++-------- src/luarocks/manif_core.lua | 37 ++++++++++++++++++++++++++------- src/luarocks/search.lua | 50 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 88 insertions(+), 19 deletions(-) diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index f53f8dca..05621315 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -105,18 +105,22 @@ end -- All functions that use manifest tables assume they were obtained -- through either this function or load_local_manifest. -- @param repo_url string: URL or pathname for the repository. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. -- @return table or (nil, string, [string]): A table representing the manifest, -- or nil followed by an error message and an optional error code. -function manif.load_manifest(repo_url) +function manif.load_manifest(repo_url, lua_version) assert(type(repo_url) == "string") + assert(type(lua_version) == "string" or not lua_version) + lua_version = lua_version or cfg.lua_version - if manif_core.manifest_cache[repo_url] then - return manif_core.manifest_cache[repo_url] + local cached_manifest = manif_core.get_cached_manifest(repo_url, lua_version) + if cached_manifest then + return cached_manifest end - + local filenames = { - "manifest-"..cfg.lua_version..".zip", - "manifest-"..cfg.lua_version, + "manifest-"..lua_version..".zip", + "manifest-"..lua_version, "manifest", } @@ -156,7 +160,7 @@ function manif.load_manifest(repo_url) end pathname = nozip end - return manif_core.manifest_loader(pathname, repo_url) + return manif_core.manifest_loader(pathname, repo_url, lua_version) end --- Output a table listing items of a package. @@ -381,7 +385,7 @@ function manif.make_manifest(repo, deps_mode, remote) local results = search.disk_search(repo, query) local manifest = { repository = {}, modules = {}, commands = {} } - manif_core.manifest_cache[repo] = manifest + manif_core.cache_manifest(repo, nil, manifest) local dep_handler = nil if not remote then diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua index 87fc16cf..610f9860 100644 --- a/src/luarocks/manif_core.lua +++ b/src/luarocks/manif_core.lua @@ -7,20 +7,43 @@ package.loaded["luarocks.manif_core"] = manif_core local persist = require("luarocks.persist") local type_check = require("luarocks.type_check") +local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") local util = require("luarocks.util") local path = require("luarocks.path") -manif_core.manifest_cache = {} +-- Table with repository identifiers as keys and tables mapping +-- Lua versions to cached loaded manifests as values. +local manifest_cache = {} + +--- Cache a loaded manifest. +-- @param repo_url string: The repository identifier. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. +-- @param manifest table: the manifest to be cached. +function manif_core.cache_manifest(repo_url, lua_version, manifest) + lua_version = lua_version or cfg.lua_version + manifest_cache[repo_url] = manifest_cache[repo_url] or {} + manifest_cache[repo_url][lua_version] = manifest +end + +--- Attempt to get cached loaded manifest. +-- @param repo_url string: The repository identifier. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. +-- @return table or nil: loaded manifest or nil if cache is empty. +function manif_core.get_cached_manifest(repo_url, lua_version) + lua_version = lua_version or cfg.lua_version + return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] +end --- Back-end function that actually loads the manifest -- and stores it in the manifest cache. -- @param file string: The local filename of the manifest file. -- @param repo_url string: The repository identifier. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. -- @param quick boolean: If given, skips type checking. -- @return table or (nil, string, string): the manifest or nil, -- error message and error code ("open", "load", "run" or "type"). -function manif_core.manifest_loader(file, repo_url, quick) +function manif_core.manifest_loader(file, repo_url, lua_version, quick) local manifest, err, errcode = persist.load_into_table(file) if not manifest then return nil, "Failed loading manifest for "..repo_url..": "..err, errcode @@ -33,7 +56,7 @@ function manif_core.manifest_loader(file, repo_url, quick) end end - manif_core.manifest_cache[repo_url] = manifest + manif_core.cache_manifest(repo_url, lua_version, manifest) return manifest end @@ -46,13 +69,13 @@ end function manif_core.load_local_manifest(repo_url) assert(type(repo_url) == "string") - if manif_core.manifest_cache[repo_url] then - return manif_core.manifest_cache[repo_url] + local cached_manifest = manif_core.get_cached_manifest(repo_url) + if cached_manifest then + return cached_manifest end local pathname = dir.path(repo_url, "manifest") - - return manif_core.manifest_loader(pathname, repo_url, true) + return manif_core.manifest_loader(pathname, repo_url, nil, true) end --- Get all versions of a package listed in a manifest file. diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 0276dfae..6c0020c0 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -170,14 +170,15 @@ end -- If the arch field is omitted, the local architecture (cfg.arch) -- is used. The special value "any" is also recognized, returning all -- matches regardless of architecture. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. -- @return true or, in case of errors, nil, an error message and an optional error code. -function search.manifest_search(results, repo, query) +function search.manifest_search(results, repo, query, lua_version) assert(type(results) == "table") assert(type(repo) == "string") assert(type(query) == "table") query_arch_as_table(query) - local manifest, err, errcode = manif.load_manifest(repo) + local manifest, err, errcode = manif.load_manifest(repo, lua_version) if not manifest then return nil, err, errcode end @@ -193,10 +194,11 @@ end --- Search on all configured rocks servers. -- @param query table: A dependency query. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. -- @return table: A table where keys are package names -- and values are tables matching version strings to arrays of -- tables with fields "arch" and "repo". -function search.search_repos(query) +function search.search_repos(query, lua_version) assert(type(query) == "table") local results = {} @@ -210,7 +212,7 @@ function search.search_repos(query) if protocol == "file" then mirror = pathname end - local ok, err, errcode = search.manifest_search(results, mirror, query) + local ok, err, errcode = search.manifest_search(results, mirror, query, lua_version) if errcode == "network" then cfg.disabled_servers[repo] = true end @@ -278,6 +280,23 @@ local function pick_latest_version(name, versions) return nil end +-- Find out which other Lua versions provide rock versions matching a query, +-- @param query table: A dependency query matching a single rock. +-- @return table: array of Lua versions supported, in "5.x" format. +local function supported_lua_versions(query) + local results = {} + + for lua_version in util.lua_versions() do + if lua_version ~= cfg.lua_version then + if search.search_repos(query, lua_version)[query.name] then + table.insert(results, lua_version) + end + end + end + + return results +end + --- Attempt to get a single URL for a given search for a rock. -- @param query table: A dependency query matching a single rock. -- @return string or (nil, string): URL for latest matching version @@ -288,6 +307,29 @@ function search.find_suitable_rock(query) local results = search.search_repos(query) local first_rock = next(results) if not first_rock then + if cfg.rocks_provided[query.name] == nil then + -- Check if constraints are satisfiable with other Lua versions. + local lua_versions = supported_lua_versions(query) + + if #lua_versions ~= 0 then + -- Build a nice message in "only Lua 5.x and 5.y but not 5.z." format + for i, lua_version in ipairs(lua_versions) do + lua_versions[i] = "Lua "..lua_version + end + + local versions_message = "only "..table.concat(lua_versions, " and ").. + " but not Lua "..cfg.lua_version.."." + + if #query.constraints == 0 then + return nil, query.name.." supports "..versions_message + elseif #query.constraints == 1 and query.constraints[1].op == "==" then + return nil, query.name.." "..query.constraints[1].version.string.." supports "..versions_message + else + return nil, "Matching "..query.name.." versions support "..versions_message + end + end + end + return nil, "No results matching query were found." elseif next(results, first_rock) then -- Shouldn't happen as query must match only one package. -- cgit v1.2.3-55-g6feb From 05c1c8b0699d5ac8a85a844332d6b6ae0dff0c89 Mon Sep 17 00:00:00 2001 From: Ryan Hartlage Date: Mon, 18 Apr 2016 19:39:09 -0400 Subject: Add support for the --tree argument to the path command --- src/luarocks/cfg.lua | 12 +++++++++--- src/luarocks/path_cmd.lua | 2 +- test/testing.lua | 1 + test/testing.sh | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 0099ec3a..f01fd205 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -666,17 +666,23 @@ function cfg.make_paths_from_tree(tree) return lua_path, lib_path, bin_path end -function cfg.package_paths() +function cfg.package_paths(current) local new_path, new_cpath, new_bin = {}, {}, {} - for _,tree in ipairs(cfg.rocks_trees) do + local function add_tree_to_paths(tree) local lua_path, lib_path, bin_path = cfg.make_paths_from_tree(tree) table.insert(new_path, lua_path.."/?.lua") table.insert(new_path, lua_path.."/?/init.lua") table.insert(new_cpath, lib_path.."/?."..cfg.lib_extension) table.insert(new_bin, bin_path) end + if current then + add_tree_to_paths(current) + end + for _,tree in ipairs(cfg.rocks_trees) do + add_tree_to_paths(tree) + end if extra_luarocks_module_dir then - table.insert(new_path, extra_luarocks_module_dir) + table.insert(new_path, extra_luarocks_module_dir) end return table.concat(new_path, ";"), table.concat(new_cpath, ";"), table.concat(new_bin, cfg.export_path_separator) end diff --git a/src/luarocks/path_cmd.lua b/src/luarocks/path_cmd.lua index 2bee4cb5..ecd6d4b1 100644 --- a/src/luarocks/path_cmd.lua +++ b/src/luarocks/path_cmd.lua @@ -37,7 +37,7 @@ function path_cmd.run(...) local flags = util.parse_flags(...) local deps_mode = deps.get_deps_mode(flags) - local lr_path, lr_cpath, lr_bin = cfg.package_paths() + local lr_path, lr_cpath, lr_bin = cfg.package_paths(flags["tree"]) local path_sep = cfg.export_path_separator if flags["lr-path"] then diff --git a/test/testing.lua b/test/testing.lua index 6d4b4b05..c37293ee 100644 --- a/test/testing.lua +++ b/test/testing.lua @@ -266,6 +266,7 @@ local tests = { test_path_lr_path = function() return run "$luarocks path --lr-path" end, test_path_lr_cpath = function() return run "$luarocks path --lr-cpath" end, test_path_lr_bin = function() return run "$luarocks path --lr-bin" end, + test_path_with_tree = function() return run "$luarocks path --tree=lua_modules" end, fail_purge_missing_tree = function() return run '$luarocks purge --tree="$testing_tree"' end, test_purge = function() return run '$luarocks purge --tree="$testing_sys_tree"' end, test_remove = function() diff --git a/test/testing.sh b/test/testing.sh index 95b3243c..305168c8 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -449,6 +449,7 @@ test_path() { $luarocks path --bin; } test_path_lr_path() { $luarocks path --lr-path; } test_path_lr_cpath() { $luarocks path --lr-cpath; } test_path_lr_bin() { $luarocks path --lr-bin; } +test_path_with_tree() { $luarocks path --tree=lua_modules; } fail_purge_missing_tree() { $luarocks purge --tree="$testing_tree"; } fail_purge_tree_notstring() { $luarocks purge --tree=1; } -- cgit v1.2.3-55-g6feb From 93f594a394a5ff77c123477b98237103df38d242 Mon Sep 17 00:00:00 2001 From: Hisham Date: Tue, 3 May 2016 16:11:46 -0300 Subject: Feature-test rather than version-test --- src/luarocks/cfg.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index c9fc00eb..591a456a 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -604,13 +604,11 @@ defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BIN -- Add built-in modules to rocks_provided defaults.rocks_provided["lua"] = cfg.lua_version.."-1" -if cfg.lua_version >= "5.2" then - -- Lua 5.2+ +if bit32 then -- Lua 5.2+ defaults.rocks_provided["bit32"] = cfg.lua_version.."-1" end -if cfg.lua_version >= "5.3" then - -- Lua 5.3+ +if utf8 then -- Lua 5.3+ defaults.rocks_provided["utf8"] = cfg.lua_version.."-1" end -- cgit v1.2.3-55-g6feb From e281fea83c49e301ff7bfb4af444e68d02309f5f Mon Sep 17 00:00:00 2001 From: Hisham Date: Tue, 3 May 2016 16:12:50 -0300 Subject: Shorten code a bit. --- src/luarocks/fs/lua.lua | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 8f45a829..483b3e3c 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -774,13 +774,7 @@ function fs_lua.make_temp_dir(name) assert(type(name) == "string") name = dir.normalize(name) - local template = (os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-XXXXXX" - local temp_dir, err = posix.mkdtemp(template) - if temp_dir then - return temp_dir - else - return nil, err - end + return posix.mkdtemp((os.getenv("TMPDIR") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-XXXXXX") end end -- cgit v1.2.3-55-g6feb