diff options
| author | ruki <[email protected]> | 2026-01-13 22:42:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-13 22:42:51 +0800 |
| commit | 168ac0bc82ab76b3fec593a944dfd9d929971838 (patch) | |
| tree | e0b6770a5ce22f9aa2a5e8ffb0281f590560d876 | |
| parent | e8ad981e1326c6fa47242c10ff64b4b794bcf215 (diff) | |
fix requirelocks
| -rw-r--r-- | tests/projects/package/requires_lock/test.lua | 41 | ||||
| -rw-r--r-- | tests/projects/package/requires_lock/xmake-requires.lock | 13 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 2 |
3 files changed, 31 insertions, 25 deletions
diff --git a/tests/projects/package/requires_lock/test.lua b/tests/projects/package/requires_lock/test.lua index 437bff11d..ce6fadd2e 100644 --- a/tests/projects/package/requires_lock/test.lua +++ b/tests/projects/package/requires_lock/test.lua @@ -1,3 +1,5 @@ +import("core.project.config") + -- test lock file generation and basic content validation function test_lock_file_generation(scriptdir) local lockfile = path.join(scriptdir, "xmake-requires.lock") @@ -27,15 +29,19 @@ function test_lock_file_generation(scriptdir) assert(package_data.repo, "zlib should have repo info") assert(package_data.repo.url, "zlib repo should have url") assert(package_data.repo.commit, "zlib repo should have commit") - elseif key:find("zlib~shared#") then - found_zlib_shared = true - assert(package_data.version, "zlib shared should have version") - assert(package_data.repo, "zlib shared should have repo info") end end + -- we should have two zlib entries (one with version constraint, one with shared config) + local zlib_count = 0 + for key, _ in pairs(plat_entries) do + if key:find("zlib") then + zlib_count = zlib_count + 1 + end + end + + assert(zlib_count == 2, "should find 2 zlib entries in lock file, found: " .. zlib_count) assert(found_zlib, "should find zlib entry in lock file") - assert(found_zlib_shared, "should find zlib shared entry in lock file") print("✓ lock file generation test passed") end @@ -47,8 +53,8 @@ function test_lock_file_stability(scriptdir, t) -- get the lock file content after first build local lockdata_after_first = io.load(lockfile) - -- remove packages and reinstall to test lock file stability - os.rm(path.join(scriptdir, ".xmake", "packages")) + -- remove installed packages using xmake lua private.xrepo to trigger reinstallation + os.execv("xmake", {"lua", "private.xrepo", "remove", "--all", "-y", "zlib"}) -- rebuild and verify lock file content doesn't change t:build() @@ -57,7 +63,17 @@ function test_lock_file_stability(scriptdir, t) -- compare lock file content assert(lockdata_after_first.__meta__.version == lockdata_after_second.__meta__.version, "lock metadata version should not change") - assert(table.size(lockdata_after_first) == table.size(lockdata_after_second), "lock file structure should not change") + + -- count table entries properly + local function count_table(t) + local count = 0 + for _ in pairs(t) do + count = count + 1 + end + return count + end + + assert(count_table(lockdata_after_first) == count_table(lockdata_after_second), "lock file structure should not change") -- compare platform-specific entries local plat = config.plat() or os.subhost() @@ -67,7 +83,7 @@ function test_lock_file_stability(scriptdir, t) local first_plat_entries = lockdata_after_first[plat_arch_key] local second_plat_entries = lockdata_after_second[plat_arch_key] - assert(table.size(first_plat_entries) == table.size(second_plat_entries), "platform entries count should not change") + assert(count_table(first_plat_entries) == count_table(second_plat_entries), "platform entries count should not change") -- verify each package entry is identical for key, first_data in pairs(first_plat_entries) do @@ -93,14 +109,17 @@ function main(t) -- build project and generate requires lock t:build() + -- get script directory from context filename + local scriptdir = path.directory(t.filename) + -- test requires lock file generation and content - test_lock_file_generation(t:scriptdir()) + test_lock_file_generation(scriptdir) -- test building with existing lock file t:build() -- test lock file stability across rebuilds - test_lock_file_stability(t:scriptdir(), t) + test_lock_file_stability(scriptdir, t) print("requires lock test passed!") end diff --git a/tests/projects/package/requires_lock/xmake-requires.lock b/tests/projects/package/requires_lock/xmake-requires.lock deleted file mode 100644 index 04633257c..000000000 --- a/tests/projects/package/requires_lock/xmake-requires.lock +++ /dev/null @@ -1,13 +0,0 @@ -{ - __meta__ = { - version = "1.0" - }, - ["macosx|x86_64"] = { - ["zlib >=1.2.11#f56260b5"] = { - version = "v1.3.1" - }, - ["zlib#16fb575b"] = { - version = "v1.3.1" - } - } -}
\ No newline at end of file diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index f6d7963b7..692be9ae8 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -3063,7 +3063,7 @@ function package.load_from_repository(packagename, packagedir, opt) end -- new an instance - instance = _instance.new(packagename, packageinfo, {scriptdir = path.directory(scriptpath), repo = repo}) + instance = _instance.new(packagename, packageinfo, {scriptdir = path.directory(scriptpath), repo = opt.repo}) -- reset plat/arch if opt.plat then |
