aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2019-09-02 14:32:54 -0300
committerHisham Muhammad <hisham@gobolinux.org>2019-09-03 14:56:49 -0300
commit96b6b9ca9cf77922863d440247850b6b7c4bb9ae (patch)
treef090af9c1d03c21bf3ba8f6d556b17f7630e3a57
parent989c58dff675532cf6378ade3790fd7e28e5bc07 (diff)
downloadluarocks-96b6b9ca9cf77922863d440247850b6b7c4bb9ae.tar.gz
luarocks-96b6b9ca9cf77922863d440247850b6b7c4bb9ae.tar.bz2
luarocks-96b6b9ca9cf77922863d440247850b6b7c4bb9ae.zip
build: fix --branch flag
The `--branch` flag is optional and takes a string argument. The `--branch` flag does not make sense for `luarocks make` because it does not fetch sources, it builds/installs based on whatever is in the current directory. This also adds tests that verify the behavior, but these don't run in Travis CI because of issues running a Git daemon there. They were verified locally.
-rw-r--r--spec/build_spec.lua35
-rw-r--r--spec/install_spec.lua29
-rw-r--r--spec/util/git_repo.lua1
-rw-r--r--src/luarocks/build.lua15
-rw-r--r--src/luarocks/cmd/build.lua6
-rw-r--r--src/luarocks/cmd/install.lua2
-rw-r--r--src/luarocks/cmd/make.lua6
7 files changed, 67 insertions, 27 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua
index 41c169d9..f0377b5f 100644
--- a/spec/build_spec.lua
+++ b/spec/build_spec.lua
@@ -4,6 +4,7 @@ local get_tmp_path = test_env.get_tmp_path
4local run = test_env.run 4local run = test_env.run
5local testing_paths = test_env.testing_paths 5local testing_paths = test_env.testing_paths
6local write_file = test_env.write_file 6local write_file = test_env.write_file
7local git_repo = require("spec.util.git_repo")
7 8
8test_env.unload_luarocks() 9test_env.unload_luarocks()
9local cfg = require("luarocks.core.cfg") 10local cfg = require("luarocks.core.cfg")
@@ -109,12 +110,6 @@ describe("LuaRocks build tests #integration", function()
109 end, finally) 110 end, finally)
110 end) 111 end)
111 112
112 it("LuaRocks build lpeg branch=master", function()
113 -- FIXME should use dev package
114 assert.is_true(run.luarocks_bool("build --branch=master lpeg"))
115 assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec"))
116 end)
117
118 it("LuaRocks build fails if the deps-mode argument is invalid", function() 113 it("LuaRocks build fails if the deps-mode argument is invalid", function()
119 assert.is_false(run.luarocks_bool("build --deps-mode=123 " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec")) 114 assert.is_false(run.luarocks_bool("build --deps-mode=123 " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec"))
120 assert.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) 115 assert.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec"))
@@ -928,5 +923,33 @@ describe("LuaRocks build tests #unit", function()
928 end) 923 end)
929 end) 924 end)
930 end) 925 end)
926
927 describe("#unix build from #git", function()
928 local git
929
930 setup(function()
931 git = git_repo.start()
932 end)
933
934 teardown(function()
935 if git then
936 git:stop()
937 end
938 end)
939
940 it("using --branch", function()
941 write_file("my_branch-1.0-1.rockspec", [[
942 rockspec_format = "3.0"
943 package = "my_branch"
944 version = "1.0-1"
945 source = {
946 url = "git://localhost/testrock"
947 }
948 ]], finally)
949 assert.is_false(run.luarocks_bool("build --branch unknown-branch ./my_branch-1.0-1.rockspec"))
950 assert.is_true(run.luarocks_bool("build --branch test-branch ./my_branch-1.0-1.rockspec"))
951 end)
952 end)
953
931end) 954end)
932 955
diff --git a/spec/install_spec.lua b/spec/install_spec.lua
index 77ac6225..3b0b22fb 100644
--- a/spec/install_spec.lua
+++ b/spec/install_spec.lua
@@ -3,8 +3,8 @@ local lfs = require("lfs")
3local run = test_env.run 3local run = test_env.run
4local testing_paths = test_env.testing_paths 4local testing_paths = test_env.testing_paths
5local env_variables = test_env.env_variables 5local env_variables = test_env.env_variables
6local get_tmp_path = test_env.get_tmp_path
7local write_file = test_env.write_file 6local write_file = test_env.write_file
7local git_repo = require("spec.util.git_repo")
8 8
9test_env.unload_luarocks() 9test_env.unload_luarocks()
10 10
@@ -234,4 +234,31 @@ describe("luarocks install #integration", function()
234 end) 234 end)
235 end) 235 end)
236 236
237 describe("#unix install runs build from #git", function()
238 local git
239
240 setup(function()
241 git = git_repo.start()
242 end)
243
244 teardown(function()
245 if git then
246 git:stop()
247 end
248 end)
249
250 it("using --branch", function()
251 write_file("my_branch-1.0-1.rockspec", [[
252 rockspec_format = "3.0"
253 package = "my_branch"
254 version = "1.0-1"
255 source = {
256 url = "git://localhost/testrock"
257 }
258 ]], finally)
259 assert.is_false(run.luarocks_bool("install --branch unknown-branch ./my_branch-1.0-1.rockspec"))
260 assert.is_true(run.luarocks_bool("install --branch test-branch ./my_branch-1.0-1.rockspec"))
261 end)
262 end)
263
237end) 264end)
diff --git a/spec/util/git_repo.lua b/spec/util/git_repo.lua
index 6cccfcc4..b3ddd9ef 100644
--- a/spec/util/git_repo.lua
+++ b/spec/util/git_repo.lua
@@ -82,6 +82,7 @@ function git_repo.start()
82 test_env.execute("git add " .. name) 82 test_env.execute("git add " .. name)
83 end 83 end
84 assert(test_env.execute("git commit -a -m 'initial commit'")) 84 assert(test_env.execute("git commit -a -m 'initial commit'"))
85 assert(test_env.execute("git branch test-branch"))
85 print("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &") 86 print("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &")
86 assert(test_env.execute("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &")) 87 assert(test_env.execute("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &"))
87 assert(test_env.execute("sleep 0.1; netstat -ln | grep '0.0.0.0:9418 .* LISTEN'")) 88 assert(test_env.execute("sleep 0.1; netstat -ln | grep '0.0.0.0:9418 .* LISTEN'"))
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 2ac7dd3a..948c5f53 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -18,7 +18,7 @@ build.opts = util.opts_table("build.opts", {
18 deps_mode = "string", 18 deps_mode = "string",
19 build_only_deps = "boolean", 19 build_only_deps = "boolean",
20 namespace = "string?", 20 namespace = "string?",
21 branch = "boolean", 21 branch = "string?",
22 verify = "boolean", 22 verify = "boolean",
23}) 23})
24 24
@@ -337,18 +337,7 @@ local function write_rock_dir_files(rockspec, opts)
337end 337end
338 338
339--- Build and install a rock given a rockspec. 339--- Build and install a rock given a rockspec.
340-- @param rockspec_file string: local or remote filename of a rockspec. 340-- @param opts table: build options table
341-- @param need_to_fetch boolean: true if sources need to be fetched,
342-- false if the rockspec was obtained from inside a source rock.
343-- @param minimal_mode boolean: true if there's no need to fetch,
344-- unpack or change dir (this is used by "luarocks make"). Implies
345-- need_to_fetch = false.
346-- @param deps_mode string: Dependency mode: "one" for the current default tree,
347-- "all" for all trees, "order" for all trees with priority >= the current default,
348-- "none" for no trees.
349-- @param build_only_deps boolean: true to build the listed dependencies only.
350-- @param namespace string?: a namespace for the rockspec
351-- @param branch string?: a forced branch to use
352-- @return (string, string) or (nil, string, [string]): Name and version of 341-- @return (string, string) or (nil, string, [string]): Name and version of
353-- installed rock if succeeded or nil and an error message followed by an error code. 342-- installed rock if succeeded or nil and an error message followed by an error code.
354function build.build_rockspec(rockspec, opts) 343function build.build_rockspec(rockspec, opts)
diff --git a/src/luarocks/cmd/build.lua b/src/luarocks/cmd/build.lua
index 57e722b5..ea47cbb0 100644
--- a/src/luarocks/cmd/build.lua
+++ b/src/luarocks/cmd/build.lua
@@ -31,6 +31,10 @@ function cmd_build.add_to_parser(parser)
31 31
32 cmd:flag("--only-deps", "Installs only the dependencies of the rock.") 32 cmd:flag("--only-deps", "Installs only the dependencies of the rock.")
33 cmd:flag("--no-doc", "Installs the rock without its documentation.") 33 cmd:flag("--no-doc", "Installs the rock without its documentation.")
34 cmd:option("--branch", "Override the `source.branch` field in the loaded "..
35 "rockspec. Allows to specify a different branch to fetch. Particularly "..
36 'for "dev" rocks.')
37 :argname("<name>")
34 make.cmd_options(cmd) 38 make.cmd_options(cmd)
35end 39end
36 40
@@ -131,7 +135,7 @@ function cmd_build.command(args)
131 deps_mode = deps.get_deps_mode(args), 135 deps_mode = deps.get_deps_mode(args),
132 build_only_deps = not not args.only_deps, 136 build_only_deps = not not args.only_deps,
133 namespace = args.namespace, 137 namespace = args.namespace,
134 branch = not not args.branch, 138 branch = args.branch,
135 verify = not not args.verify, 139 verify = not not args.verify,
136 }) 140 })
137 141
diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua
index 4020918e..be4b0104 100644
--- a/src/luarocks/cmd/install.lua
+++ b/src/luarocks/cmd/install.lua
@@ -42,7 +42,7 @@ function install.add_to_parser(parser)
42 util.deps_mode_option(cmd) 42 util.deps_mode_option(cmd)
43 -- luarocks build options 43 -- luarocks build options
44 parser:flag("--pack-binary-rock"):hidden(true) 44 parser:flag("--pack-binary-rock"):hidden(true)
45 parser:flag("--branch"):hidden(true) 45 parser:option("--branch"):hidden(true)
46 parser:flag("--sign"):hidden(true) 46 parser:flag("--sign"):hidden(true)
47end 47end
48 48
diff --git a/src/luarocks/cmd/make.lua b/src/luarocks/cmd/make.lua
index 480ec48d..3ff5c277 100644
--- a/src/luarocks/cmd/make.lua
+++ b/src/luarocks/cmd/make.lua
@@ -26,10 +26,6 @@ function make.cmd_options(parser)
26 "previously installed versions if it would break dependencies.") 26 "previously installed versions if it would break dependencies.")
27 parser:flag("--force-fast", "Like --force, but performs a forced removal ".. 27 parser:flag("--force-fast", "Like --force, but performs a forced removal "..
28 "without reporting dependency issues.") 28 "without reporting dependency issues.")
29 parser:option("--branch", "Override the `source.branch` field in the loaded "..
30 "rockspec. Allows to specify a different branch to fetch. Particularly "..
31 'for "dev" rocks.')
32 :argname("<name>")
33 parser:flag("--verify", "Verify signature of the rockspec or src.rock being ".. 29 parser:flag("--verify", "Verify signature of the rockspec or src.rock being "..
34 "built. If the rockspec or src.rock is being downloaded, LuaRocks will ".. 30 "built. If the rockspec or src.rock is being downloaded, LuaRocks will "..
35 "attempt to download the signature as well. Otherwise, the signature ".. 31 "attempt to download the signature as well. Otherwise, the signature "..
@@ -95,7 +91,7 @@ function make.command(args)
95 deps_mode = deps.get_deps_mode(args), 91 deps_mode = deps.get_deps_mode(args),
96 build_only_deps = false, 92 build_only_deps = false,
97 namespace = args.namespace, 93 namespace = args.namespace,
98 branch = not not args.branch, 94 branch = args.branch,
99 verify = not not args.verify, 95 verify = not not args.verify,
100 }) 96 })
101 97