From 6ce1f1490413a8afdd976be33c0bec7f27da21a5 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 15 Jan 2025 23:47:52 +0800 Subject: [PATCH] fix package cache --- src/build-cache.ts | 11 ++++++++++- src/package-cache.ts | 14 ++++++++++++++ tests/sample/xmake.lua | 4 ++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/build-cache.ts b/src/build-cache.ts index 679c8be6..0f4a612f 100644 --- a/src/build-cache.ts +++ b/src/build-cache.ts @@ -56,6 +56,10 @@ async function getBuildCachePath(): Promise { const projectRootPath = getProjectRootPath(); if (projectRootPath && projectRootPath !== '' && fsutils.isDir(projectRootPath)) { const options: ExecOptions = {}; + options.env = { + ...process.env, + XMAKE_ROOT: 'y' + }; options.cwd = projectRootPath; options.listeners = { stdout: (data: Buffer) => { @@ -153,7 +157,12 @@ export async function saveBuildCache(): Promise { await io.cp(buildCachePath, fullCachePath, { recursive: true, }); - await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'build_cache_saved.txt')]); + const options: ExecOptions = {}; + options.env = { + ...process.env, + XMAKE_ROOT: 'y' + }; + await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'build_cache_saved.txt')], options); await cache.saveCache([buildCacheFolder], buildCacheKey); } } diff --git a/src/package-cache.ts b/src/package-cache.ts index 819fcecf..4a14f21e 100644 --- a/src/package-cache.ts +++ b/src/package-cache.ts @@ -27,6 +27,10 @@ async function getPackageCacheKey(): Promise { const projectRootPath = getProjectRootPath(); if (projectRootPath && projectRootPath !== '' && fsutils.isDir(projectRootPath)) { const options: ExecOptions = {}; + options.env = { + ...process.env, + XMAKE_ROOT: 'y' + }; options.cwd = projectRootPath; options.listeners = { stdout: (data: Buffer) => { @@ -43,6 +47,10 @@ async function getPackageCacheKey(): Promise { async function getPackageCachePath(): Promise { let packageCachePath = ''; const options: ExecOptions = {}; + options.env = { + ...process.env, + XMAKE_ROOT: 'y' + }; options.listeners = { stdout: (data: Buffer) => { packageCachePath += data.toString(); @@ -112,6 +120,12 @@ export async function savePackageCache(): Promise { await io.cp(packageCachePath, fullCachePath, { recursive: true, }); + const options: ExecOptions = {}; + options.env = { + ...process.env, + XMAKE_ROOT: 'y' + }; + await exec('xmake', ['l', 'os.touch', path.join(fullCachePath, 'package_cache_saved.txt')], options); await cache.saveCache([packageCacheFolder], packageCacheKey); } } diff --git a/tests/sample/xmake.lua b/tests/sample/xmake.lua index 8c88caf1..530ef36a 100644 --- a/tests/sample/xmake.lua +++ b/tests/sample/xmake.lua @@ -1,9 +1,9 @@ add_rules("mode.debug", "mode.release") -add_requires("libpng", "libogg", {system = false}) +add_requires("libpng", "libogg", "libjpeg", {system = false}) target("sample") set_kind("binary") add_files("src/*.cpp") - add_packages("libpng", "libogg") + add_packages("libpng", "libogg", "libjpeg")