diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-05-22 19:45:57 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-05-23 14:06:01 +0300 |
commit | b5ee7f79b2d0e54209d714a5eca640d338e17ac6 (patch) | |
tree | cb827c35affb1400477e7b9b116224fa4b66e77a | |
parent | a3650d51e96aef84657cb29e5f52e570fed828c9 (diff) | |
download | luarocks-b5ee7f79b2d0e54209d714a5eca640d338e17ac6.tar.gz luarocks-b5ee7f79b2d0e54209d714a5eca640d338e17ac6.tar.bz2 luarocks-b5ee7f79b2d0e54209d714a5eca640d338e17ac6.zip |
write-rockspec: infer git and hg urls from local repos
-rw-r--r-- | src/luarocks/write_rockspec.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index abfca322..9b6593b6 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua | |||
@@ -3,6 +3,7 @@ | |||
3 | local write_rockspec = {} | 3 | local write_rockspec = {} |
4 | package.loaded["luarocks.write_rockspec"] = write_rockspec | 4 | package.loaded["luarocks.write_rockspec"] = write_rockspec |
5 | 5 | ||
6 | local cfg = require("luarocks.cfg") | ||
6 | local dir = require("luarocks.dir") | 7 | local dir = require("luarocks.dir") |
7 | local fetch = require("luarocks.fetch") | 8 | local fetch = require("luarocks.fetch") |
8 | local fs = require("luarocks.fs") | 9 | local fs = require("luarocks.fs") |
@@ -111,6 +112,32 @@ local function detect_mit_license(data) | |||
111 | return sum == 78656 | 112 | return sum == 78656 |
112 | end | 113 | end |
113 | 114 | ||
115 | local simple_scm_protocols = { | ||
116 | git = true, ["git+http"] = true, ["git+https"] = true, | ||
117 | hg = true, ["hg+http"] = true, ["hg+https"] = true | ||
118 | } | ||
119 | |||
120 | local function detect_url_from_command(program, args, directory) | ||
121 | local command = fs.Q(cfg.variables[program:upper()]).. " "..args | ||
122 | local pipe = io.popen(fs.command_at(directory, fs.quiet_stderr(command))) | ||
123 | if not pipe then return nil end | ||
124 | local url = pipe:read("*a"):match("^([^\r\n]+)") | ||
125 | pipe:close() | ||
126 | if not url then return nil end | ||
127 | if not util.starts_with(url, program.."://") then | ||
128 | url = program.."+"..url | ||
129 | end | ||
130 | |||
131 | if simple_scm_protocols[dir.split_url(url)] then | ||
132 | return url | ||
133 | end | ||
134 | end | ||
135 | |||
136 | local function detect_scm_url(directory) | ||
137 | return detect_url_from_command("git", "config --get remote.origin.url", directory) or | ||
138 | detect_url_from_command("hg", "paths default", directory) | ||
139 | end | ||
140 | |||
114 | local function show_license(rockspec) | 141 | local function show_license(rockspec) |
115 | local fd = open_file("COPYING") or open_file("LICENSE") or open_file("MIT-LICENSE.txt") | 142 | local fd = open_file("COPYING") or open_file("LICENSE") or open_file("MIT-LICENSE.txt") |
116 | if not fd then return nil end | 143 | if not fd then return nil end |
@@ -290,6 +317,8 @@ function write_rockspec.run(...) | |||
290 | else | 317 | else |
291 | local_dir = nil | 318 | local_dir = nil |
292 | end | 319 | end |
320 | else | ||
321 | rockspec.source.url = detect_scm_url(local_dir) or rockspec.source.url | ||
293 | end | 322 | end |
294 | 323 | ||
295 | if not local_dir then | 324 | if not local_dir then |