Browse Source

Update new.lua

ruki 3 years ago
parent
commit
05322f9bd0
1 changed files with 23 additions and 6 deletions
  1. 23 6
      scripts/new.lua

+ 23 - 6
scripts/new.lua

@@ -4,6 +4,7 @@ import("core.base.json")
 import("lib.detect.find_tool")
 import("lib.detect.find_tool")
 import("lib.detect.find_file")
 import("lib.detect.find_file")
 import("net.http")
 import("net.http")
+import("devel.git")
 import("utils.archive")
 import("utils.archive")
 
 
 local options = {
 local options = {
@@ -47,6 +48,7 @@ function _generate_package_from_github(reponame)
     file:print("")
     file:print("")
 
 
     -- generate package urls and versions
     -- generate package urls and versions
+    local repodir
     local has_xmake
     local has_xmake
     local has_cmake
     local has_cmake
     local has_meson
     local has_meson
@@ -59,13 +61,29 @@ function _generate_package_from_github(reponame)
         file:print('    add_urls("%s",', url)
         file:print('    add_urls("%s",', url)
         file:print('             "%s")', giturl)
         file:print('             "%s")', giturl)
         local tmpfile = os.tmpfile({ramdisk = false}) .. ".tar.gz"
         local tmpfile = os.tmpfile({ramdisk = false}) .. ".tar.gz"
-        local tmpdir = tmpfile .. ".dir"
+        repodir = tmpfile .. ".dir"
         print("downloading %s", url)
         print("downloading %s", url)
         http.download(url, tmpfile)
         http.download(url, tmpfile)
         file:print('    add_versions("%s", "%s")', latest_release.tagName, hash.sha256(tmpfile))
         file:print('    add_versions("%s", "%s")', latest_release.tagName, hash.sha256(tmpfile))
-        archive.extract(tmpfile, tmpdir)
-        local files = os.files(path.join(tmpdir, "*")) or {}
-        table.join2(files, os.files(path.join(tmpdir, "*", "*")))
+        archive.extract(tmpfile, repodir)
+        os.rm(tmpfile)
+    else
+        local giturl = ("https://github.com/%s.git"):format(reponame)
+        repodir = os.tmpfile({ramdisk = false})
+        file:print('    add_urls("%s")', giturl)
+        print("downloading %s", giturl)
+        git.clone(giturl, {outputdir = repodir, depth = 1})
+        local commit = git.lastcommit({repodir = repodir})
+        local version = try{ function() return os.iorunv("git", {"log", "-1", "--date=format:%Y.%m.%d", "--format=%ad"}, {curdir = repodir}) end}
+        if version then
+            file:print('    add_versions("%s", "%s")', version:trim(), commit)
+        end
+    end
+
+    -- detect build system
+    if repodir then
+        local files = os.files(path.join(repodir, "*")) or {}
+        table.join2(files, os.files(path.join(repodir, "*", "*")))
         for _, file in ipairs(files) do
         for _, file in ipairs(files) do
             local filename = path.filename(file)
             local filename = path.filename(file)
             if filename == "xmake.lua" then
             if filename == "xmake.lua" then
@@ -81,8 +99,7 @@ function _generate_package_from_github(reponame)
                 has_meson = true
                 has_meson = true
             end
             end
         end
         end
-        os.rm(tmpdir)
-        os.rm(tmpfile)
+        os.rm(repodir)
     end
     end
 
 
     -- add dependencies
     -- add dependencies