From 63ac87a36cd1a11659243813c6dae35f08be8152 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 28 Feb 2024 20:14:10 -0300 Subject: feat(build,install): only rebuild and reinstall when using --force --- spec/quick/build.q | 40 ++++++++++++++++++++++++++++++++++++++++ spec/quick/install.q | 42 ++++++++++++++++++++++++++++++++++++++++++ src/luarocks/cmd/build.lua | 15 ++++++++++++++- src/luarocks/cmd/install.lua | 8 +++++++- src/luarocks/cmd/make.lua | 3 ++- src/luarocks/fs/lua.lua | 4 ++++ 6 files changed, 109 insertions(+), 3 deletions(-) diff --git a/spec/quick/build.q b/spec/quick/build.q index c6ca433c..a1731da2 100644 --- a/spec/quick/build.q +++ b/spec/quick/build.q @@ -120,3 +120,43 @@ failed to force the lock -------------------------------------------------------------------------------- NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec + + + +================================================================================ +TEST: luarocks build: do not rebuild when already installed + +FILE: a_rock-1.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "a_rock" +version = "1.0-1" +source = { + url = "file://%{url(%{fixtures_dir})}/a_rock.lua" +} +description = { + summary = "An example rockspec", +} +dependencies = { + "lua >= 5.1" +} +build = { + modules = { + build = "a_rock.lua" + }, +} +-------------------------------------------------------------------------------- +RUN: luarocks build a_rock-1.0-1.rockspec + +RUN: luarocks show a_rock +STDOUT: +-------------------------------------------------------------------------------- +a_rock 1.0 +-------------------------------------------------------------------------------- + +RUN: luarocks build a_rock-1.0-1.rockspec +STDOUT: +-------------------------------------------------------------------------------- +a_rock 1.0-1 is already installed +Use --force to reinstall +-------------------------------------------------------------------------------- diff --git a/spec/quick/install.q b/spec/quick/install.q index ab576605..503aaacc 100644 --- a/spec/quick/install.q +++ b/spec/quick/install.q @@ -373,3 +373,45 @@ RUN: luarocks install myrock-1.0-2.all.rock --no-doc EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess~ + + + +================================================================================ +TEST: do not reinstall when already installed + +FILE: myrock-1.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "myrock" +version = "1.0-1" +source = { + url = "file://%{url(tmpdir)}/rock.lua" +} +build = { + modules = { rock = "rock.lua" } +} +-------------------------------------------------------------------------------- + +FILE: rock.lua +-------------------------------------------------------------------------------- +return "hello" +-------------------------------------------------------------------------------- + +RUN: luarocks build myrock-1.0-1.rockspec +RUN: luarocks pack myrock +RUN: luarocks remove myrock + +RUN: luarocks install ./myrock-1.0-1.all.rock + +RUN: luarocks show myrock +STDOUT: +-------------------------------------------------------------------------------- +myrock 1.0 +-------------------------------------------------------------------------------- + +RUN: luarocks install ./myrock-1.0-1.all.rock +STDOUT: +-------------------------------------------------------------------------------- +myrock 1.0-1 is already installed +Use --force to reinstall +-------------------------------------------------------------------------------- diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua index 16c0aff2..c73ceebe 100644 --- a/src/luarocks/cmd/build.lua +++ b/src/luarocks/cmd/build.lua @@ -16,6 +16,7 @@ local writer = require("luarocks.manif.writer") local search = require("luarocks.search") local make = require("luarocks.cmd.make") local cmd = require("luarocks.cmd") +local repos = require("luarocks.repos") function cmd_build.add_to_parser(parser) local cmd = parser:command("build", "Build and install a rock, compiling its C parts if any.\n".. -- luacheck: ignore 431 @@ -93,6 +94,15 @@ local function do_build(name, namespace, version, opts) end end + name, version = path.parse_name(url) + if name and repos.is_installed(name, version) then + if (not opts.force) and (not opts.force_fast) then + util.printout(name .. " " .. version .. " is already installed in " .. path.root_dir(cfg.root_dir)) + util.printout("Use --force to reinstall.") + return name, version, "skip" + end + end + if url:match("%.rockspec$") then local rockspec, err = fetch.load_rockspec(url, nil, opts.verify) if not rockspec then @@ -151,10 +161,13 @@ function cmd_build.command(args) return nil, err, cmd.errorcodes.PERMISSIONDENIED end - local name, version = do_build(args.rock, args.namespace, args.version, opts) + local name, version, skip = do_build(args.rock, args.namespace, args.version, opts) if not name then return nil, version end + if skip == "skip" then + return name, version + end if args.no_doc then util.remove_doc_dir(name, version) diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index b4f15cb8..e221f611 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua @@ -28,7 +28,8 @@ function install.add_to_parser(parser) "rock after building a new one. This behavior can be made permanent by ".. "setting keep_other_versions=true in the configuration file.") cmd:flag("--force", "If --keep is not specified, force removal of ".. - "previously installed versions if it would break dependencies.") + "previously installed versions if it would break dependencies. ".. + "If rock is already installed, reinstall it anyway.") cmd:flag("--force-fast", "Like --force, but performs a forced removal ".. "without reporting dependency issues.") cmd:flag("--only-deps --deps-only", "Install only the dependencies of the rock.") @@ -84,6 +85,11 @@ function install.install_binary_rock(rock_file, opts) return nil, "Incompatible architecture "..arch, "arch" end if repos.is_installed(name, version) then + if (not opts.force) and (not opts.force_fast) then + util.printout(name .. " " .. version .. " is already installed in " .. path.root_dir(cfg.root_dir)) + util.printout("Use --force to reinstall.") + return name, version + end repos.delete_version(name, version, opts.deps_mode) end diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua index 8147b5df..b75a9043 100644 --- a/src/luarocks/cmd/make.lua +++ b/src/luarocks/cmd/make.lua @@ -25,7 +25,8 @@ function make.cmd_options(parser) "rock after building a new one. This behavior can be made permanent by ".. "setting keep_other_versions=true in the configuration file.") parser:flag("--force", "If --keep is not specified, force removal of ".. - "previously installed versions if it would break dependencies.") + "previously installed versions if it would break dependencies. ".. + "If rock is already installed, reinstall it anyway.") parser:flag("--force-fast", "Like --force, but performs a forced removal ".. "without reporting dependency issues.") parser:flag("--verify", "Verify signature of the rockspec or src.rock being ".. diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 71695701..55c64b72 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -1161,6 +1161,9 @@ end function fs_lua.check_command_permissions(args) local ok = true local err = "" + if args._command_permissions_checked then + return true + end for _, directory in ipairs { cfg.rocks_dir, cfg.deploy_lua_dir, cfg.deploy_bin_dir, cfg.deploy_lua_dir } do if fs.exists(directory) then if not fs.is_writable(directory) then @@ -1185,6 +1188,7 @@ function fs_lua.check_command_permissions(args) end end if ok then + args._command_permissions_checked = true return true else if args["local"] or cfg.local_by_default then -- cgit v1.2.3-55-g6feb