aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-02-28 20:14:10 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-02-29 01:22:40 +0000
commit63ac87a36cd1a11659243813c6dae35f08be8152 (patch)
tree1c462f66602e2413274735dc1708b91c655b55f6
parent361d96f856fd2de89ef835c2a6c3e30020deefbe (diff)
downloadluarocks-63ac87a36cd1a11659243813c6dae35f08be8152.tar.gz
luarocks-63ac87a36cd1a11659243813c6dae35f08be8152.tar.bz2
luarocks-63ac87a36cd1a11659243813c6dae35f08be8152.zip
feat(build,install): only rebuild and reinstall when using --force
-rw-r--r--spec/quick/build.q40
-rw-r--r--spec/quick/install.q42
-rw-r--r--src/luarocks/cmd/build.lua15
-rw-r--r--src/luarocks/cmd/install.lua8
-rw-r--r--src/luarocks/cmd/make.lua3
-rw-r--r--src/luarocks/fs/lua.lua4
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
120-------------------------------------------------------------------------------- 120--------------------------------------------------------------------------------
121 121
122NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec 122NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec
123
124
125
126================================================================================
127TEST: luarocks build: do not rebuild when already installed
128
129FILE: a_rock-1.0-1.rockspec
130--------------------------------------------------------------------------------
131rockspec_format = "3.0"
132package = "a_rock"
133version = "1.0-1"
134source = {
135 url = "file://%{url(%{fixtures_dir})}/a_rock.lua"
136}
137description = {
138 summary = "An example rockspec",
139}
140dependencies = {
141 "lua >= 5.1"
142}
143build = {
144 modules = {
145 build = "a_rock.lua"
146 },
147}
148--------------------------------------------------------------------------------
149RUN: luarocks build a_rock-1.0-1.rockspec
150
151RUN: luarocks show a_rock
152STDOUT:
153--------------------------------------------------------------------------------
154a_rock 1.0
155--------------------------------------------------------------------------------
156
157RUN: luarocks build a_rock-1.0-1.rockspec
158STDOUT:
159--------------------------------------------------------------------------------
160a_rock 1.0-1 is already installed
161Use --force to reinstall
162--------------------------------------------------------------------------------
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
373 373
374EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess 374EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess
375NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess~ 375NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess~
376
377
378
379================================================================================
380TEST: do not reinstall when already installed
381
382FILE: myrock-1.0-1.rockspec
383--------------------------------------------------------------------------------
384rockspec_format = "3.0"
385package = "myrock"
386version = "1.0-1"
387source = {
388 url = "file://%{url(tmpdir)}/rock.lua"
389}
390build = {
391 modules = { rock = "rock.lua" }
392}
393--------------------------------------------------------------------------------
394
395FILE: rock.lua
396--------------------------------------------------------------------------------
397return "hello"
398--------------------------------------------------------------------------------
399
400RUN: luarocks build myrock-1.0-1.rockspec
401RUN: luarocks pack myrock
402RUN: luarocks remove myrock
403
404RUN: luarocks install ./myrock-1.0-1.all.rock
405
406RUN: luarocks show myrock
407STDOUT:
408--------------------------------------------------------------------------------
409myrock 1.0
410--------------------------------------------------------------------------------
411
412RUN: luarocks install ./myrock-1.0-1.all.rock
413STDOUT:
414--------------------------------------------------------------------------------
415myrock 1.0-1 is already installed
416Use --force to reinstall
417--------------------------------------------------------------------------------
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")
16local search = require("luarocks.search") 16local search = require("luarocks.search")
17local make = require("luarocks.cmd.make") 17local make = require("luarocks.cmd.make")
18local cmd = require("luarocks.cmd") 18local cmd = require("luarocks.cmd")
19local repos = require("luarocks.repos")
19 20
20function cmd_build.add_to_parser(parser) 21function cmd_build.add_to_parser(parser)
21 local cmd = parser:command("build", "Build and install a rock, compiling its C parts if any.\n".. -- luacheck: ignore 431 22 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)
93 end 94 end
94 end 95 end
95 96
97 name, version = path.parse_name(url)
98 if name and repos.is_installed(name, version) then
99 if (not opts.force) and (not opts.force_fast) then
100 util.printout(name .. " " .. version .. " is already installed in " .. path.root_dir(cfg.root_dir))
101 util.printout("Use --force to reinstall.")
102 return name, version, "skip"
103 end
104 end
105
96 if url:match("%.rockspec$") then 106 if url:match("%.rockspec$") then
97 local rockspec, err = fetch.load_rockspec(url, nil, opts.verify) 107 local rockspec, err = fetch.load_rockspec(url, nil, opts.verify)
98 if not rockspec then 108 if not rockspec then
@@ -151,10 +161,13 @@ function cmd_build.command(args)
151 return nil, err, cmd.errorcodes.PERMISSIONDENIED 161 return nil, err, cmd.errorcodes.PERMISSIONDENIED
152 end 162 end
153 163
154 local name, version = do_build(args.rock, args.namespace, args.version, opts) 164 local name, version, skip = do_build(args.rock, args.namespace, args.version, opts)
155 if not name then 165 if not name then
156 return nil, version 166 return nil, version
157 end 167 end
168 if skip == "skip" then
169 return name, version
170 end
158 171
159 if args.no_doc then 172 if args.no_doc then
160 util.remove_doc_dir(name, version) 173 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)
28 "rock after building a new one. This behavior can be made permanent by ".. 28 "rock after building a new one. This behavior can be made permanent by "..
29 "setting keep_other_versions=true in the configuration file.") 29 "setting keep_other_versions=true in the configuration file.")
30 cmd:flag("--force", "If --keep is not specified, force removal of ".. 30 cmd:flag("--force", "If --keep is not specified, force removal of "..
31 "previously installed versions if it would break dependencies.") 31 "previously installed versions if it would break dependencies. "..
32 "If rock is already installed, reinstall it anyway.")
32 cmd:flag("--force-fast", "Like --force, but performs a forced removal ".. 33 cmd:flag("--force-fast", "Like --force, but performs a forced removal "..
33 "without reporting dependency issues.") 34 "without reporting dependency issues.")
34 cmd:flag("--only-deps --deps-only", "Install only the dependencies of the rock.") 35 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)
84 return nil, "Incompatible architecture "..arch, "arch" 85 return nil, "Incompatible architecture "..arch, "arch"
85 end 86 end
86 if repos.is_installed(name, version) then 87 if repos.is_installed(name, version) then
88 if (not opts.force) and (not opts.force_fast) then
89 util.printout(name .. " " .. version .. " is already installed in " .. path.root_dir(cfg.root_dir))
90 util.printout("Use --force to reinstall.")
91 return name, version
92 end
87 repos.delete_version(name, version, opts.deps_mode) 93 repos.delete_version(name, version, opts.deps_mode)
88 end 94 end
89 95
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)
25 "rock after building a new one. This behavior can be made permanent by ".. 25 "rock after building a new one. This behavior can be made permanent by "..
26 "setting keep_other_versions=true in the configuration file.") 26 "setting keep_other_versions=true in the configuration file.")
27 parser:flag("--force", "If --keep is not specified, force removal of ".. 27 parser:flag("--force", "If --keep is not specified, force removal of "..
28 "previously installed versions if it would break dependencies.") 28 "previously installed versions if it would break dependencies. "..
29 "If rock is already installed, reinstall it anyway.")
29 parser:flag("--force-fast", "Like --force, but performs a forced removal ".. 30 parser:flag("--force-fast", "Like --force, but performs a forced removal "..
30 "without reporting dependency issues.") 31 "without reporting dependency issues.")
31 parser:flag("--verify", "Verify signature of the rockspec or src.rock being ".. 32 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
1161function fs_lua.check_command_permissions(args) 1161function fs_lua.check_command_permissions(args)
1162 local ok = true 1162 local ok = true
1163 local err = "" 1163 local err = ""
1164 if args._command_permissions_checked then
1165 return true
1166 end
1164 for _, directory in ipairs { cfg.rocks_dir, cfg.deploy_lua_dir, cfg.deploy_bin_dir, cfg.deploy_lua_dir } do 1167 for _, directory in ipairs { cfg.rocks_dir, cfg.deploy_lua_dir, cfg.deploy_bin_dir, cfg.deploy_lua_dir } do
1165 if fs.exists(directory) then 1168 if fs.exists(directory) then
1166 if not fs.is_writable(directory) then 1169 if not fs.is_writable(directory) then
@@ -1185,6 +1188,7 @@ function fs_lua.check_command_permissions(args)
1185 end 1188 end
1186 end 1189 end
1187 if ok then 1190 if ok then
1191 args._command_permissions_checked = true
1188 return true 1192 return true
1189 else 1193 else
1190 if args["local"] or cfg.local_by_default then 1194 if args["local"] or cfg.local_by_default then