diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2016-05-22 18:54:47 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2016-05-22 18:54:47 -0300 |
| commit | 3f6eda258d5c6aee610b095a20beb12e026e6714 (patch) | |
| tree | 95a24e1975aa72a26a0df0a8cfd75aa0e268c3d0 | |
| parent | 43c1a5925baf3e4003ca4bf070910b6615f5f829 (diff) | |
| parent | 3e29a935df047976cff9e1f232c716b55fdcde69 (diff) | |
| download | luarocks-3f6eda258d5c6aee610b095a20beb12e026e6714.tar.gz luarocks-3f6eda258d5c6aee610b095a20beb12e026e6714.tar.bz2 luarocks-3f6eda258d5c6aee610b095a20beb12e026e6714.zip | |
Merge pull request #560 from mpeterv/write-rockspec-default-args
Infer name and version for `luarocks write-rockspec` without args
| -rw-r--r-- | src/luarocks/write_rockspec.lua | 55 | ||||
| -rwxr-xr-x | test/testing.sh | 4 |
2 files changed, 29 insertions, 30 deletions
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 26a65808..abfca322 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua | |||
| @@ -12,14 +12,16 @@ local type_check = require("luarocks.type_check") | |||
| 12 | local util = require("luarocks.util") | 12 | local util = require("luarocks.util") |
| 13 | 13 | ||
| 14 | write_rockspec.help_summary = "Write a template for a rockspec file." | 14 | write_rockspec.help_summary = "Write a template for a rockspec file." |
| 15 | write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] {<url>|<path>}" | 15 | write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] [<url>|<path>]" |
| 16 | write_rockspec.help = [[ | 16 | write_rockspec.help = [[ |
| 17 | This command writes an initial version of a rockspec file, | 17 | This command writes an initial version of a rockspec file, |
| 18 | based on an URL or a local path. You may use a relative path such as '.'. | 18 | based on a name, a version, and a location (an URL or a local path). |
| 19 | If a local path is given, name and version arguments are mandatory. | 19 | If only two arguments are given, the first one is considered the name and the |
| 20 | For URLs, LuaRocks will attempt to infer name and version if not given. | 20 | second one is the location. |
| 21 | 21 | If only one argument is given, it must be the location. | |
| 22 | If a repository URL is given with no version, it creates an 'scm' rock. | 22 | If no arguments are given, current directory is used as location. |
| 23 | LuaRocks will attempt to infer name and version if not given, | ||
| 24 | using 'scm' as default version. | ||
| 23 | 25 | ||
| 24 | Note that the generated file is a _starting point_ for writing a | 26 | Note that the generated file is a _starting point_ for writing a |
| 25 | rockspec, and is not guaranteed to be complete or correct. | 27 | rockspec, and is not guaranteed to be complete or correct. |
| @@ -198,19 +200,17 @@ end | |||
| 198 | 200 | ||
| 199 | function write_rockspec.run(...) | 201 | function write_rockspec.run(...) |
| 200 | local flags, name, version, url_or_dir = util.parse_flags(...) | 202 | local flags, name, version, url_or_dir = util.parse_flags(...) |
| 201 | |||
| 202 | if not name then | ||
| 203 | return nil, "Missing arguments. "..util.see_help("write_rockspec") | ||
| 204 | end | ||
| 205 | 203 | ||
| 206 | if name and not version then | 204 | if not name then |
| 205 | url_or_dir = "." | ||
| 206 | elseif not version then | ||
| 207 | url_or_dir = name | 207 | url_or_dir = name |
| 208 | name = nil | 208 | name = nil |
| 209 | elseif not url_or_dir then | 209 | elseif not url_or_dir then |
| 210 | url_or_dir = version | 210 | url_or_dir = version |
| 211 | version = nil | 211 | version = nil |
| 212 | end | 212 | end |
| 213 | 213 | ||
| 214 | if flags["tag"] then | 214 | if flags["tag"] then |
| 215 | if not version then | 215 | if not version then |
| 216 | version = flags["tag"]:gsub("^v", "") | 216 | version = flags["tag"]:gsub("^v", "") |
| @@ -218,28 +218,25 @@ function write_rockspec.run(...) | |||
| 218 | end | 218 | end |
| 219 | 219 | ||
| 220 | local protocol, pathname = dir.split_url(url_or_dir) | 220 | local protocol, pathname = dir.split_url(url_or_dir) |
| 221 | if not fetch.is_basic_protocol(protocol) then | 221 | if protocol == "file" then |
| 222 | if not name then | 222 | if pathname == "." then |
| 223 | name = dir.base_name(url_or_dir):gsub("%.[^.]+$", "") | 223 | name = name or dir.base_name(fs.current_dir()) |
| 224 | end | 224 | end |
| 225 | if not version then | 225 | elseif fetch.is_basic_protocol(protocol) then |
| 226 | version = "scm" | ||
| 227 | end | ||
| 228 | elseif protocol ~= "file" then | ||
| 229 | local filename = dir.base_name(url_or_dir) | 226 | local filename = dir.base_name(url_or_dir) |
| 230 | local newname, newversion = filename:match("(.*)-([^-]+)") | 227 | local newname, newversion = filename:match("(.*)-([^-]+)") |
| 231 | if (not name) and newname then | 228 | if newname then |
| 232 | name = newname | 229 | name = name or newname |
| 233 | end | 230 | version = version or newversion:gsub("%.[a-z]+$", ""):gsub("%.tar$", "") |
| 234 | if (not version) and newversion then | ||
| 235 | version = newversion:gsub(".[a-z]+$", ""):gsub(".tar$", "") | ||
| 236 | end | 231 | end |
| 237 | if not (name and version) then | 232 | else |
| 238 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") | 233 | name = name or dir.base_name(url_or_dir):gsub("%.[^.]+$", "") |
| 239 | end | 234 | end |
| 240 | elseif not version then | 235 | |
| 241 | return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") | 236 | if not name then |
| 237 | return nil, "Could not infer rock name. "..util.see_help("write_rockspec") | ||
| 242 | end | 238 | end |
| 239 | version = version or "scm" | ||
| 243 | 240 | ||
| 244 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") | 241 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") |
| 245 | 242 | ||
diff --git a/test/testing.sh b/test/testing.sh index 4f1b0b87..f56f2aa9 100755 --- a/test/testing.sh +++ b/test/testing.sh | |||
| @@ -364,7 +364,6 @@ fail_upload_noarg() { $luarocks upload; } | |||
| 364 | fail_remove_noarg() { $luarocks remove; } | 364 | fail_remove_noarg() { $luarocks remove; } |
| 365 | fail_doc_noarg() { $luarocks doc; } | 365 | fail_doc_noarg() { $luarocks doc; } |
| 366 | fail_new_version_noarg() { $luarocks new_version; } | 366 | fail_new_version_noarg() { $luarocks new_version; } |
| 367 | fail_write_rockspec_noarg() { $luarocks write_rockspec; } | ||
| 368 | 367 | ||
| 369 | fail_build_invalid() { $luarocks build invalid; } | 368 | fail_build_invalid() { $luarocks build invalid; } |
| 370 | fail_download_invalid() { $luarocks download invalid; } | 369 | fail_download_invalid() { $luarocks download invalid; } |
| @@ -523,6 +522,9 @@ test_deps_mode_make_order() { $luarocks build --tree="$testing_sys_tree" lpeg && | |||
| 523 | test_deps_mode_make_order_sys() { $luarocks build --tree="$testing_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_sys_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ] && rm -rf ./lxsh-${verrev_lxsh}; } | 522 | test_deps_mode_make_order_sys() { $luarocks build --tree="$testing_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_sys_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ] && rm -rf ./lxsh-${verrev_lxsh}; } |
| 524 | 523 | ||
| 525 | test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; } | 524 | test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; } |
| 525 | test_write_rockspec_name() { $luarocks write_rockspec luarocks git://github.com/keplerproject/luarocks; } | ||
| 526 | test_write_rockspec_name_version() { $luarocks write_rockspec luarocks 7.8.9 git://github.com/keplerproject/luarocks; } | ||
| 527 | test_write_rockspec_current_dir() { $luarocks write_rockspec; } | ||
| 526 | test_write_rockspec_tag() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0; } | 528 | test_write_rockspec_tag() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0; } |
| 527 | test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; } | 529 | test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; } |
| 528 | test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; } | 530 | test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; } |
