diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2016-05-27 17:15:42 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2016-05-27 17:15:42 -0300 |
commit | ab67c73c8dc22cb5f809c53123331fd3cbabbd32 (patch) | |
tree | 5789eaab9d2f9e71d56797b8e0d15f06892cb2dd | |
parent | 38119eca55728e1a1187b101a19d36886818a697 (diff) | |
parent | 24fa7d2c2c8f9032b66a290be0d2d2623c6904b4 (diff) | |
download | luarocks-ab67c73c8dc22cb5f809c53123331fd3cbabbd32.tar.gz luarocks-ab67c73c8dc22cb5f809c53123331fd3cbabbd32.tar.bz2 luarocks-ab67c73c8dc22cb5f809c53123331fd3cbabbd32.zip |
Merge pull request #562 from mpeterv/write-rockspec-infer-scm-url
Write rockspec infer scm url
-rw-r--r-- | src/luarocks/write_rockspec.lua | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index abfca322..213d1b01 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 |
@@ -239,10 +266,6 @@ function write_rockspec.run(...) | |||
239 | version = version or "scm" | 266 | version = version or "scm" |
240 | 267 | ||
241 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") | 268 | local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") |
242 | |||
243 | if not flags["homepage"] and url_or_dir:match("^git://github.com") then | ||
244 | flags["homepage"] = "http://"..url_or_dir:match("^[^:]+://(.*)") | ||
245 | end | ||
246 | 269 | ||
247 | local rockspec = { | 270 | local rockspec = { |
248 | rockspec_format = flags["rockspec-format"], | 271 | rockspec_format = flags["rockspec-format"], |
@@ -290,11 +313,26 @@ function write_rockspec.run(...) | |||
290 | else | 313 | else |
291 | local_dir = nil | 314 | local_dir = nil |
292 | end | 315 | end |
316 | else | ||
317 | rockspec.source.url = detect_scm_url(local_dir) or rockspec.source.url | ||
293 | end | 318 | end |
294 | 319 | ||
295 | if not local_dir then | 320 | if not local_dir then |
296 | local_dir = "." | 321 | local_dir = "." |
297 | end | 322 | end |
323 | |||
324 | if not flags["homepage"] then | ||
325 | local url_protocol, url_path = dir.split_url(rockspec.source.url) | ||
326 | |||
327 | if simple_scm_protocols[url_protocol] then | ||
328 | for _, domain in ipairs({"github.com", "bitbucket.org", "gitlab.com"}) do | ||
329 | if util.starts_with(url_path, domain) then | ||
330 | rockspec.description.homepage = "https://"..url_path:gsub("%.git$", "") | ||
331 | break | ||
332 | end | ||
333 | end | ||
334 | end | ||
335 | end | ||
298 | 336 | ||
299 | local libs = nil | 337 | local libs = nil |
300 | if flags["lib"] then | 338 | if flags["lib"] then |