From 93bec0272c3992b0428b5bda073cf6120be5ff36 Mon Sep 17 00:00:00 2001 From: dwenegar Date: Wed, 16 Sep 2020 22:52:05 +0900 Subject: Add the `--no-install` option to the `make` command (#1213) * feat: add --no-install to make Add the --no-install option to the make command to build the rock w/o installing it. --- src/luarocks/build.lua | 38 ++++++++++++++++++++++++++------------ src/luarocks/build/builtin.lua | 26 ++++++++++++++------------ src/luarocks/build/cmake.lua | 4 ++-- src/luarocks/build/command.lua | 4 ++-- src/luarocks/build/make.lua | 10 ++++++---- src/luarocks/cmd/build.lua | 1 + src/luarocks/cmd/make.lua | 8 ++++++-- 7 files changed, 57 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index eee4bb99..f11edb6f 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -23,6 +23,7 @@ build.opts = util.opts_table("build.opts", { verify = "boolean", check_lua_versions = "boolean", pin = "boolean", + no_install = "boolean" }) do @@ -188,7 +189,7 @@ local function prepare_install_dirs(name, version) return dirs end -local function run_build_driver(rockspec) +local function run_build_driver(rockspec, no_install) local btype = rockspec.build.type if btype == "none" then return true @@ -206,7 +207,7 @@ local function run_build_driver(rockspec) if not pok or type(driver) ~= "table" then return nil, "Failed initializing build back-end for build type '"..btype.."': "..driver end - local ok, err = driver.run(rockspec) + local ok, err = driver.run(rockspec, no_install) if not ok then return nil, "Build error: " .. err end @@ -385,16 +386,21 @@ function build.build_rockspec(rockspec, opts) return name, version end - if repos.is_installed(name, version) then - repos.delete_version(name, version, opts.deps_mode) + local dirs, err + local rollback + if not opts.no_install then + if repos.is_installed(name, version) then + repos.delete_version(name, version, opts.deps_mode) + end + + dirs, err = prepare_install_dirs(name, version) + if not dirs then return nil, err end + + rollback = util.schedule_function(function() + fs.delete(path.install_dir(name, version)) + fs.remove_dir_if_empty(path.versions_dir(name)) + end) end - local dirs, err = prepare_install_dirs(name, version) - if not dirs then return nil, err end - - local rollback = util.schedule_function(function() - fs.delete(path.install_dir(name, version)) - fs.remove_dir_if_empty(path.versions_dir(name)) - end) ok, err = build.apply_patches(rockspec) if not ok then return nil, err end @@ -402,9 +408,17 @@ function build.build_rockspec(rockspec, opts) ok, err = check_macosx_deployment_target(rockspec) if not ok then return nil, err end - ok, err = run_build_driver(rockspec) + ok, err = run_build_driver(rockspec, opts.no_install) if not ok then return nil, err end + if opts.no_install then + fs.pop_dir() + if opts.need_to_fetch then + fs.pop_dir() + end + return name, version + end + ok, err = install_files(rockspec, dirs) if not ok then return nil, err end diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index fb4431cd..70651ce8 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -149,7 +149,7 @@ end -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors occurred, -- nil and an error message otherwise. -function builtin.run(rockspec) +function builtin.run(rockspec, no_install) assert(rockspec:type() == "rockspec") local compile_object, compile_library, compile_static_library @@ -344,19 +344,21 @@ function builtin.run(rockspec) ]] end end - for _, mods in ipairs({{ tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" }}) do - for name, dest in pairs(mods.tbl) do - fs.make_dir(dir.dir_name(dest)) - ok, err = fs.copy(name, dest, mods.perms) - if not ok then - return nil, "Failed installing "..name.." in "..dest..": "..err + if not no_install then + for _, mods in ipairs({{ tbl = lua_modules, perms = "read" }, { tbl = lib_modules, perms = "exec" }}) do + for name, dest in pairs(mods.tbl) do + fs.make_dir(dir.dir_name(dest)) + ok, err = fs.copy(name, dest, mods.perms) + if not ok then + return nil, "Failed installing "..name.." in "..dest..": "..err + end end end - end - if fs.is_dir("lua") then - ok, err = fs.copy_contents("lua", luadir) - if not ok then - return nil, "Failed copying contents of 'lua' directory: "..err + if fs.is_dir("lua") then + ok, err = fs.copy_contents("lua", luadir) + if not ok then + return nil, "Failed copying contents of 'lua' directory: "..err + end end end return true diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua index 0bf44dda..d7ecc83c 100644 --- a/src/luarocks/build/cmake.lua +++ b/src/luarocks/build/cmake.lua @@ -10,7 +10,7 @@ local cfg = require("luarocks.core.cfg") -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors occurred, -- nil and an error message otherwise. -function cmake.run(rockspec) +function cmake.run(rockspec, no_install) assert(rockspec:type() == "rockspec") local build = rockspec.build local variables = build.variables or {} @@ -66,7 +66,7 @@ function cmake.run(rockspec) return nil, "Failed building." end end - if do_install then + if do_install and not no_install then if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --target install --config Release") then return nil, "Failed installing." end diff --git a/src/luarocks/build/command.lua b/src/luarocks/build/command.lua index 755a39d2..309c4a16 100644 --- a/src/luarocks/build/command.lua +++ b/src/luarocks/build/command.lua @@ -10,7 +10,7 @@ local cfg = require("luarocks.core.cfg") -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors occurred, -- nil and an error message otherwise. -function command.run(rockspec) +function command.run(rockspec, not_install) assert(rockspec:type() == "rockspec") local build = rockspec.build @@ -29,7 +29,7 @@ function command.run(rockspec) return nil, "Failed building." end end - if build.install_command then + if build.install_command and not not_install then util.printout(build.install_command) if not fs.execute_env(env, build.install_command) then return nil, "Failed installing." diff --git a/src/luarocks/build/make.lua b/src/luarocks/build/make.lua index 5df3050d..ccab1af0 100644 --- a/src/luarocks/build/make.lua +++ b/src/luarocks/build/make.lua @@ -38,7 +38,7 @@ end -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors occurred, -- nil and an error message otherwise. -function make.run(rockspec) +function make.run(rockspec, not_install) assert(rockspec:type() == "rockspec") local build = rockspec.build @@ -86,9 +86,11 @@ function make.run(rockspec) if not ok then return nil, "Failed building." end - ok = make_pass(make_cmd, build.install_pass, build.install_target, build.install_variables) - if not ok then - return nil, "Failed installing." + if not not_install then + ok = make_pass(make_cmd, build.install_pass, build.install_target, build.install_variables) + if not ok then + return nil, "Failed installing." + end end return true end diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index bc2b9bb6..31622f35 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua @@ -129,6 +129,7 @@ function cmd_build.command(args) verify = not not args.verify, check_lua_versions = not not args.check_lua_versions, pin = not not args.pin, + no_install = false }) if args.sign and not args.pack_binary_rock then diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index 60a0f11e..78647b63 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua @@ -18,6 +18,7 @@ local writer = require("luarocks.manif.writer") local cmd = require("luarocks.cmd") function make.cmd_options(parser) + parser:flag("--no-install", "Do not install the rock.") parser:flag("--no-doc", "Install the rock without its documentation.") parser:flag("--pack-binary-rock", "Do not install rock. Instead, produce a ".. ".rock file with the contents of compilation in the current directory.") @@ -104,14 +105,17 @@ function make.command(args) branch = args.branch, verify = not not args.verify, check_lua_versions = not not args.check_lua_versions, - pin = not not args.pin + pin = not not args.pin, + no_install = not not args.no_install }) if args.sign and not args.pack_binary_rock then return nil, "In the make command, --sign is meant to be used only with --pack-binary-rock" end - if args.pack_binary_rock then + if args.no_install then + return build.build_rockspec(rockspec, opts) + elseif args.pack_binary_rock then return pack.pack_binary_rock(name, namespace, rockspec.version, args.sign, function() local name, version = build.build_rockspec(rockspec, opts) if name and args.no_doc then -- cgit v1.2.3-55-g6feb