aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2016-02-11 15:04:40 -0200
committerHisham Muhammad <hisham@gobolinux.org>2016-02-11 15:04:40 -0200
commit9090aef04159fa8d32e359d7c38b51e09555ab23 (patch)
tree323315302a3f72e1f5dd196518f703bc94f4c51d
parent7a27096e5e1231cb49aedd045aa7a5f06c656cbe (diff)
parent5571c28fb73edcfc91ecdf44257481a12357c500 (diff)
downloadluarocks-9090aef04159fa8d32e359d7c38b51e09555ab23.tar.gz
luarocks-9090aef04159fa8d32e359d7c38b51e09555ab23.tar.bz2
luarocks-9090aef04159fa8d32e359d7c38b51e09555ab23.zip
Merge pull request #498 from mpeterv/improve-new-version
Make new_version work with scm rockspecs
-rw-r--r--src/luarocks/new_version.lua84
-rwxr-xr-xtest/testing.sh1
2 files changed, 54 insertions, 31 deletions
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua
index 9ef0cfbb..6969d4b2 100644
--- a/src/luarocks/new_version.lua
+++ b/src/luarocks/new_version.lua
@@ -1,9 +1,7 @@
1 1
2--- Module implementing the LuaRocks "new_version" command. 2--- Module implementing the LuaRocks "new_version" command.
3-- Utility function that writes a new rockspec, updating data from a previous one. 3-- Utility function that writes a new rockspec, updating data from a previous one.
4--module("luarocks.new_version", package.seeall)
5local new_version = {} 4local new_version = {}
6package.loaded["luarocks.new_version"] = new_version
7 5
8local util = require("luarocks.util") 6local util = require("luarocks.util")
9local download = require("luarocks.download") 7local download = require("luarocks.download")
@@ -13,7 +11,7 @@ local fs = require("luarocks.fs")
13local type_check = require("luarocks.type_check") 11local type_check = require("luarocks.type_check")
14 12
15new_version.help_summary = "Auto-write a rockspec for a new version of a rock." 13new_version.help_summary = "Auto-write a rockspec for a new version of a rock."
16new_version.help_arguments = "{<package>|<rockspec>} [<new_version>] [<new_url>]" 14new_version.help_arguments = "[--tag=<tag>] {<package>|<rockspec>} [<new_version>] [<new_url>]"
17new_version.help = [[ 15new_version.help = [[
18This is a utility function that writes a new rockspec, updating data 16This is a utility function that writes a new rockspec, updating data
19from a previous one. 17from a previous one.
@@ -21,8 +19,10 @@ from a previous one.
21If a package name is given, it downloads the latest rockspec from the 19If a package name is given, it downloads the latest rockspec from the
22default server. If a rockspec is given, it uses it instead. 20default server. If a rockspec is given, it uses it instead.
23 21
24If the version number is not given, it only increments the revision 22If the version number is not given and tag is passed using --tag,
25number of the given (or downloaded) rockspec. 23it is used as the version, with 'v' removed from beginning.
24Otherwise, it only increments the revision number of the given
25(or downloaded) rockspec.
26 26
27If a URL is given, it replaces the one from the old rockspec with the 27If a URL is given, it replaces the one from the old rockspec with the
28given URL. If a URL is not given and a new version is given, it tries 28given URL. If a URL is not given and a new version is given, it tries
@@ -30,6 +30,9 @@ to guess the new URL by replacing occurrences of the version number
30in the URL or tag. It also tries to download the new URL to determine 30in the URL or tag. It also tries to download the new URL to determine
31the new MD5 checksum. 31the new MD5 checksum.
32 32
33If a tag is given, it replaces the one from the old rockspec. If there is
34an old tag but no new one passed, it is guessed in the same way URL is.
35
33WARNING: it writes the new rockspec to the current directory, 36WARNING: it writes the new rockspec to the current directory,
34overwriting the file if it already exists. 37overwriting the file if it already exists.
35]] 38]]
@@ -48,58 +51,73 @@ local function try_replace(tbl, field, old, new)
48 return false 51 return false
49end 52end
50 53
51local function check_url_and_update_md5(out_rs, out_name) 54-- Try to download source file using URL from a rockspec.
52 local old_md5 = out_rs.source.md5 55-- If it specified MD5, update it.
53 out_rs.source.md5 = nil 56-- @return (true, false) if MD5 was not specified or it stayed same,
54 local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_name) 57-- (true, true) if MD5 changed, (nil, string) on error.
58local function check_url_and_update_md5(out_rs)
59 local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package)
55 if not file then 60 if not file then
56 util.printerr("Warning: invalid URL - "..temp_dir) 61 util.printerr("Warning: invalid URL - "..temp_dir)
57 return true 62 return true, false
58 end 63 end
59 util.printout("File successfully downloaded. Updating MD5 checksum...") 64
60 out_rs.source.md5 = fs.get_md5(file)
61 local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) 65 local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir)
62 if not inferred_dir then 66 if not inferred_dir then
63 return nil, found_dir 67 return nil, found_dir
64 end 68 end
69
65 if found_dir and found_dir ~= inferred_dir then 70 if found_dir and found_dir ~= inferred_dir then
66 out_rs.source.dir = found_dir 71 out_rs.source.dir = found_dir
67 end 72 end
68 return out_rs.source.md5 ~= old_md5 73
74 if file then
75 if out_rs.source.md5 then
76 util.printout("File successfully downloaded. Updating MD5 checksum...")
77 local new_md5, err = fs.get_md5(file)
78 if not new_md5 then
79 return nil, err
80 end
81 local old_md5 = out_rs.source.md5
82 out_rs.source.md5 = new_md5
83 return true, new_md5 ~= old_md5
84 else
85 util.printout("File successfully downloaded.")
86 return true, false
87 end
88 end
69end 89end
70 90
71local function update_source_section(out_rs, out_name, url, old_ver, new_ver) 91local function update_source_section(out_rs, url, tag, old_ver, new_ver)
92 if tag then
93 out_rs.source.tag = tag
94 end
72 if url then 95 if url then
73 out_rs.source.url = url 96 out_rs.source.url = url
74 check_url_and_update_md5(out_rs, out_name) 97 return check_url_and_update_md5(out_rs)
75 return true
76 end 98 end
77 if new_ver == old_ver then 99 if new_ver == old_ver then
78 return true 100 return true
79 end 101 end
80 if not out_rs.source then
81 return nil, "'source' table is missing. Invalid rockspec?"
82 end
83 if out_rs.source.dir then 102 if out_rs.source.dir then
84 try_replace(out_rs.source, "dir", old_ver, new_ver) 103 try_replace(out_rs.source, "dir", old_ver, new_ver)
85 end 104 end
86 if out_rs.source.file then 105 if out_rs.source.file then
87 try_replace(out_rs.source, "file", old_ver, new_ver) 106 try_replace(out_rs.source, "file", old_ver, new_ver)
88 end 107 end
89 local ok = try_replace(out_rs.source, "url", old_ver, new_ver) 108 if try_replace(out_rs.source, "url", old_ver, new_ver) then
90 if ok then 109 return check_url_and_update_md5(out_rs)
91 check_url_and_update_md5(out_rs, out_name) 110 end
111 if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then
92 return true 112 return true
93 end 113 end
94 ok = try_replace(out_rs.source, "tag", old_ver, new_ver) 114 -- Couldn't replace anything significant, use the old URL.
115 local ok, md5_changed = check_url_and_update_md5(out_rs)
95 if not ok then 116 if not ok then
96 ok = check_url_and_update_md5(out_rs, out_name) 117 return nil, md5_changed
97 if ok then
98 util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.")
99 end
100 end 118 end
101 if not ok then 119 if md5_changed then
102 return nil, "Failed to determine the location of the new version." 120 util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.")
103 end 121 end
104 return true 122 return true
105end 123end
@@ -107,7 +125,7 @@ end
107function new_version.run(...) 125function new_version.run(...)
108 local flags, input, version, url = util.parse_flags(...) 126 local flags, input, version, url = util.parse_flags(...)
109 if not input then 127 if not input then
110 return nil, "Missing arguments: expected program or rockspec. "..util.see_help("new_version") 128 return nil, "Missing argument: expected package or rockspec. "..util.see_help("new_version")
111 end 129 end
112 assert(type(input) == "string") 130 assert(type(input) == "string")
113 131
@@ -127,6 +145,10 @@ function new_version.run(...)
127 145
128 local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") 146 local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$")
129 local new_ver, new_rev 147 local new_ver, new_rev
148
149 if flags.tag and not version then
150 version = flags.tag:gsub("^v", "")
151 end
130 152
131 if version then 153 if version then
132 new_ver, new_rev = version:match("(.*)%-(%d+)$") 154 new_ver, new_rev = version:match("(.*)%-(%d+)$")
@@ -145,7 +167,7 @@ function new_version.run(...)
145 local out_name = out_rs.package:lower() 167 local out_name = out_rs.package:lower()
146 out_rs.version = new_rockver.."-"..new_rev 168 out_rs.version = new_rockver.."-"..new_rev
147 169
148 local ok, err = update_source_section(out_rs, out_name, url, old_ver, new_ver) 170 local ok, err = update_source_section(out_rs, url, flags.tag, old_ver, new_ver)
149 if not ok then return nil, err end 171 if not ok then return nil, err end
150 172
151 if out_rs.build and out_rs.build.type == "module" then 173 if out_rs.build and out_rs.build.type == "module" then
diff --git a/test/testing.sh b/test/testing.sh
index 44e78205..74b39b8f 100755
--- a/test/testing.sh
+++ b/test/testing.sh
@@ -427,6 +427,7 @@ fail_make_which_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks
427 427
428test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } 428test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; }
429test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; } 429test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; }
430test_new_version_tag() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec --tag v0.3 && rm ./luacov-0.3-1.rockspec; }
430 431
431test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; } 432test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; }
432test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; } 433test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; }