فهرست منبع

Improve to test packages (#5946)

* improve to test package

* improve ci

* add windows cache

* improve xml2
ruki 9 ماه پیش
والد
کامیت
0a8abe67f7
4فایلهای تغییر یافته به همراه75 افزوده شده و 53 حذف شده
  1. 2 9
      .github/workflows/android_windows.yml
  2. 2 10
      .github/workflows/windows.yml
  3. 2 9
      .github/workflows/windows_v3.yml
  4. 69 25
      scripts/test.lua

+ 2 - 9
.github/workflows/android_windows.yml

@@ -23,6 +23,8 @@ jobs:
       - uses: xmake-io/github-action-setup-xmake@v1
         with:
           xmake-version: branch@master
+          actions-cache-folder: '.xmake-cache'
+          actions-cache-key: 'android-windows'
 
       - name: Configure Pagefile
         uses: al-cheb/[email protected]
@@ -43,15 +45,6 @@ jobs:
 
       - name: Tests
         run: |
-          git clone https://github.com/xmake-io/xmake.git --recurse-submodules -b master xmakesrc
-          cd xmakesrc/core
-          xmake
-          cd ../..
-          Copy-Item ./xmakesrc/core/build/xmake.exe ./xmakesrc/xmake
-          Copy-Item ./xmakesrc/scripts/xrepo.bat ./xmakesrc/xmake
-          Copy-Item ./xmakesrc/scripts/xrepo.ps1 ./xmakesrc/xmake
           $Env:XMAKE_MAIN_REPO = "https://github.com/xmake-io/xmake-repo.git"
-          $Env:XMAKE_PROGRAM_DIR = $(Resolve-Path ./xmakesrc/xmake)
-          Set-Item -Path Env:Path -Value ($Env:XMAKE_PROGRAM_DIR + ";" + $Env:Path)
           xmake --version
           xmake l ./scripts/test.lua -D -p android --ndk=D:/a/xmake-repo/xmake-repo/ndk/android-ndk-${{ matrix.ndk }} --ndk_sdkver=${{ matrix.ndk_sdkver }} -a ${{ matrix.arch }}

+ 2 - 10
.github/workflows/windows.yml

@@ -25,6 +25,8 @@ jobs:
       - uses: xmake-io/github-action-setup-xmake@v1
         with:
           xmake-version: branch@master
+          actions-cache-folder: '.xmake-cache'
+          actions-cache-key: 'windows'
 
       - name: Configure Pagefile
         uses: al-cheb/[email protected]
@@ -35,16 +37,6 @@ jobs:
 
       - name: Tests
         run: |
-          git clone https://github.com/xmake-io/xmake.git --recurse-submodules -b master xmakesrc
-          cd xmakesrc/core
-          xmake
-          cd ../..
-          Copy-Item ./xmakesrc/core/build/xmake.exe ./xmakesrc/xmake
-          Copy-Item ./xmakesrc/scripts/xrepo.bat ./xmakesrc/xmake
-          Copy-Item ./xmakesrc/scripts/xrepo.ps1 ./xmakesrc/xmake
-          $Env:XMAKE_MAIN_REPO = "https://github.com/xmake-io/xmake-repo.git"
-          $Env:XMAKE_PROGRAM_DIR = $(Resolve-Path ./xmakesrc/xmake)
-          Set-Item -Path Env:Path -Value ($Env:XMAKE_PROGRAM_DIR + ";" + $Env:Path)
           xmake --version
           if ("${{ matrix.os }}" -eq "windows-2019") {
             xmake l ./scripts/test.lua -vD -a ${{ matrix.arch }} -k ${{ matrix.kind }} --runtimes=${{ matrix.runtimes }} --vs_sdkver=10.0.19041.0 --linkjobs=2

+ 2 - 9
.github/workflows/windows_v3.yml

@@ -24,6 +24,8 @@ jobs:
       - uses: xmake-io/github-action-setup-xmake@v1
         with:
           xmake-version: branch@master
+          actions-cache-folder: '.xmake-cache'
+          actions-cache-key: 'windows-v3'
 
       - name: Configure Pagefile
         uses: al-cheb/[email protected]
@@ -34,16 +36,7 @@ jobs:
 
       - name: Tests
         run: |
-          git clone https://github.com/xmake-io/xmake.git --recurse-submodules -b master xmakesrc
-          cd xmakesrc/core
-          xmake
-          cd ../..
-          Copy-Item ./xmakesrc/core/build/xmake.exe ./xmakesrc/xmake
-          Copy-Item ./xmakesrc/scripts/xrepo.bat ./xmakesrc/xmake
-          Copy-Item ./xmakesrc/scripts/xrepo.ps1 ./xmakesrc/xmake
           $Env:XMAKE_MAIN_REPO = "https://github.com/xmake-io/xmake-repo.git"
-          $Env:XMAKE_PROGRAM_DIR = $(Resolve-Path ./xmakesrc/xmake)
-          Set-Item -Path Env:Path -Value ($Env:XMAKE_PROGRAM_DIR + ";" + $Env:Path)
           xmake --version
           xmake l ./scripts/test.lua -vD -a ${{ matrix.arch }} -k ${{ matrix.kind }} --policies=compatibility.version:3.0 --linkjobs=2
 

+ 69 - 25
scripts/test.lua

@@ -53,8 +53,8 @@ function _check_package_is_supported()
     end
 end
 
--- require packages
-function _require_packages(argv, packages)
+-- config packages
+function _config_packages(argv, packages)
     local config_argv = {"f", "-c"}
     if argv.verbose then
         table.insert(config_argv, "-v")
@@ -128,6 +128,56 @@ function _require_packages(argv, packages)
         table.insert(config_argv, "--ldflags=" .. argv.ldflags)
     end
     os.vexecv(os.programfile(), config_argv)
+end
+
+-- get extra string
+function _get_extra_str(argv)
+    local extra = {}
+    if argv.mode == "debug" then
+        extra.debug = true
+    end
+    -- Some packages set shared=true as default, so we need to force set
+    -- shared=false to test static build.
+    extra.configs = extra.configs or {}
+    extra.configs.shared = argv.kind == "shared"
+    local configs = argv.configs
+    if configs then
+        extra.system  = false
+        extra.configs = extra.configs or {}
+        local extra_configs, errors = ("{" .. configs .. "}"):deserialize()
+        if extra_configs then
+            table.join2(extra.configs, extra_configs)
+        else
+            raise(errors)
+        end
+    end
+    return string.serialize(extra, {indent = false, strip = true})
+end
+
+-- load packages
+function _load_packages(argv, packages)
+    _config_packages(argv, packages)
+    local info_argv = {"require", "-f", "-y", "--info"}
+    if argv.verbose then
+        table.insert(info_argv, "-v")
+    end
+    if argv.diagnosis then
+        table.insert(info_argv, "-D")
+    end
+    local extra_str = _get_extra_str(argv)
+    table.insert(info_argv, "--extra=" .. extra_str)
+
+    -- call `xrepo info` to test on_load
+    if #packages > 0 then
+        print("testing to load packages ...")
+        print("  > if it causes errors, please remove assert/raise() to on_check.")
+        os.vexecv(os.programfile(), table.join(info_argv, packages))
+    end
+end
+
+-- require packages
+function _require_packages(argv, packages)
+    _config_packages(argv, packages)
     local require_argv = {"require", "-f", "-y"}
     local check_argv = {"require", "-f", "-y", "--check"}
     if not argv.precompiled then
@@ -158,31 +208,14 @@ function _require_packages(argv, packages)
     if argv.fetch then
         table.insert(require_argv, "--fetch")
     end
-    local extra = {}
-    if argv.mode == "debug" then
-        extra.debug = true
-    end
-    -- Some packages set shared=true as default, so we need to force set
-    -- shared=false to test static build.
-    extra.configs = extra.configs or {}
-    extra.configs.shared = argv.kind == "shared"
-    local configs = argv.configs
-    if configs then
-        extra.system  = false
-        extra.configs = extra.configs or {}
-        local extra_configs, errors = ("{" .. configs .. "}"):deserialize()
-        if extra_configs then
-            table.join2(extra.configs, extra_configs)
-        else
-            raise(errors)
-        end
-    end
-    local extra_str = string.serialize(extra, {indent = false, strip = true})
+    local extra_str = _get_extra_str(argv)
     table.insert(require_argv, "--extra=" .. extra_str)
     table.insert(check_argv, "--extra=" .. extra_str)
 
+    -- test on_check
     local install_packages = {}
     if _check_package_is_supported() then
+        print("testing to check packages ...")
         for _, package in ipairs(packages) do
             local ok = os.vexecv(os.programfile(), table.join(check_argv, package), {try = true})
             if ok == 0 then
@@ -192,7 +225,10 @@ function _require_packages(argv, packages)
     else
         install_packages = packages
     end
+
+    -- test installation
     if #install_packages > 0 then
+        print("testing to install packages ...")
         os.vexecv(os.programfile(), table.join(require_argv, install_packages))
     else
         print("no testable packages on %s or you're using lower version xmake!", argv.plat or os.subhost())
@@ -215,6 +251,7 @@ function _package_is_supported(argv, packagename)
                     arch = os.subarch()
                 end
                 for _, package_arch in ipairs(package.archs) do
+                    print(package_arch, package.archs)
                     if arch == package_arch then
                         return true
                     end
@@ -266,6 +303,7 @@ function main(...)
     end
 
     -- remove unsupported packages
+    local packages_original = table.clone(packages)
     for idx, package in irpairs(packages) do
         assert(package == package:lower(), "package(%s) must be lower case!", package)
         if not _package_is_supported(argv, package) then
@@ -305,9 +343,15 @@ function main(...)
     os.execv(os.programfile(), {"repo", "--add", "local-repo", repodir})
     os.execv(os.programfile(), {"repo", "-l"})
 
+    -- load packages
+    _load_packages(argv, packages_original)
+
+    -- no unsupported packages
+    if #packages == 0 then
+        print("no testable packages on %s!", argv.plat or os.subhost())
+        return
+    end
+
     -- require packages
     _require_packages(argv, packages)
-    --[[for _, package in ipairs(packages) do
-        _require_packages(argv, package)
-    end]]
 end