diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2013-04-12 15:48:45 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-04-12 15:48:45 -0300 |
commit | ddbea89de90923bed634166f2939648fcdd36c16 (patch) | |
tree | 3f9c378ab1d185b9f13e88eef191ff93969dadd8 /src | |
parent | dede5ff5a56eb1d2ddb13ca7450e00cd8d6562dd (diff) | |
download | luarocks-ddbea89de90923bed634166f2939648fcdd36c16.tar.gz luarocks-ddbea89de90923bed634166f2939648fcdd36c16.tar.bz2 luarocks-ddbea89de90923bed634166f2939648fcdd36c16.zip |
Make new_version smarter, so it knows how to look inside an updated tarball to check the dir name.
This version is able, for example to generate an updated rockspec for lpeg 0.12-rc2 by simply typing
`luarocks new_version lpeg 0.12-rc2`
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/fetch.lua | 8 | ||||
-rw-r--r-- | src/luarocks/new_version.lua | 18 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index b835b20e..3bb0cdc0 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua | |||
@@ -120,6 +120,11 @@ function fetch_and_unpack_rock(rock_file, dest) | |||
120 | return unpack_dir | 120 | return unpack_dir |
121 | end | 121 | end |
122 | 122 | ||
123 | function url_to_base_dir(url) | ||
124 | local base = dir.base_name(url) | ||
125 | return base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") | ||
126 | end | ||
127 | |||
123 | --- Back-end function that actually loads the local rockspec. | 128 | --- Back-end function that actually loads the local rockspec. |
124 | -- Performs some validation and postprocessing of the rockspec contents. | 129 | -- Performs some validation and postprocessing of the rockspec contents. |
125 | -- @param filename string: The local filename of the rockspec file. | 130 | -- @param filename string: The local filename of the rockspec file. |
@@ -177,8 +182,7 @@ function load_local_rockspec(filename) | |||
177 | 182 | ||
178 | rockspec.local_filename = filename | 183 | rockspec.local_filename = filename |
179 | local filebase = rockspec.source.file or rockspec.source.url | 184 | local filebase = rockspec.source.file or rockspec.source.url |
180 | local base = dir.base_name(filebase) | 185 | local base = url_to_base_dir(filebase) |
181 | base = base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") | ||
182 | rockspec.source.dir = rockspec.source.dir | 186 | rockspec.source.dir = rockspec.source.dir |
183 | or rockspec.source.module | 187 | or rockspec.source.module |
184 | or ((filebase:match(".lua$") or filebase:match(".c$")) and ".") | 188 | or ((filebase:match(".lua$") or filebase:match(".c$")) and ".") |
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index e1e3f80f..66802f0b 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua | |||
@@ -60,6 +60,18 @@ local function check_url_and_update_md5(out_rs, out_name) | |||
60 | if file then | 60 | if file then |
61 | util.printout("File successfully downloaded. Updating MD5 checksum...") | 61 | util.printout("File successfully downloaded. Updating MD5 checksum...") |
62 | out_rs.source.md5 = fs.get_md5(file) | 62 | out_rs.source.md5 = fs.get_md5(file) |
63 | fs.change_dir(temp_dir) | ||
64 | fs.unpack_archive(file) | ||
65 | local base_dir = out_rs.source.dir or fetch.url_to_base_dir(out_rs.source.url) | ||
66 | if not fs.exists(base_dir) then | ||
67 | util.printerr("Directory "..base_dir.." not found") | ||
68 | local files = fs.list_dir() | ||
69 | if files[1] and fs.is_dir(files[1]) then | ||
70 | util.printerr("Found "..files[1]) | ||
71 | out_rs.source.dir = files[1] | ||
72 | end | ||
73 | end | ||
74 | fs.pop_dir() | ||
63 | else | 75 | else |
64 | util.printerr("Warning: invalid URL - "..temp_dir) | 76 | util.printerr("Warning: invalid URL - "..temp_dir) |
65 | end | 77 | end |
@@ -110,6 +122,12 @@ function run(...) | |||
110 | check_url_and_update_md5(out_rs, out_name) | 122 | check_url_and_update_md5(out_rs, out_name) |
111 | else | 123 | else |
112 | if new_ver ~= old_ver then | 124 | if new_ver ~= old_ver then |
125 | if out_rs.source and out_rs.source.dir then | ||
126 | try_replace(out_rs.source, "dir", old_ver, new_ver) | ||
127 | end | ||
128 | if out_rs.source and out_rs.source.file then | ||
129 | try_replace(out_rs.source, "file", old_ver, new_ver) | ||
130 | end | ||
113 | local ok = try_replace(out_rs.source, "url", old_ver, new_ver) | 131 | local ok = try_replace(out_rs.source, "url", old_ver, new_ver) |
114 | if ok then | 132 | if ok then |
115 | check_url_and_update_md5(out_rs, out_name) | 133 | check_url_and_update_md5(out_rs, out_name) |