From 550662aa5b8e4d55eb8fbc84b319a13154e439d0 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Tue, 29 Mar 2022 00:02:13 +0800 Subject: [PATCH 1/4] Fix path for artifacts using remotedir in manifests. --- .../action/require/impl/actions/install.lua | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index 24f355ae03b..c2d4a951d64 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -97,10 +97,12 @@ function _patch_pkgconfig(package) end end +-- Match to path like (string insides brackets is matched): +-- /home/user/.xmake/packages[/f/foo/9adc96bd69124211aad7dd58a36f02ce]/v1.0 +local _PACKAGE_BUILDHASH_VERSION_PATTERN = "[\\/]%w[\\/][^\\/]+[\\/][^\\/]+[\\/]" .. string.rep('%x', 32) + function _fix_path_for_file(file, search_pattern) - -- Match to path like (string insides brackets is matched): - -- /home/user/.xmake[/packages/f/foo/9adc96bd69124211aad7dd58a36f02ce]/v1.0 - -- Replace path string before "packages" with local package install + -- Replace path string before package pattern with local package install -- directory. -- Note: It's possible that package A references files in package B, thus we -- need to match against all possible package install paths. @@ -109,12 +111,10 @@ function _fix_path_for_file(file, search_pattern) -- The sub capture will be replaced with local install path. -- The whole capture is to make the search more precise and less likely to -- match non package path. - local buildhash_pattern = string.rep('%x', 32) - local package_pattern = "[\\/]packages[\\/]%w[\\/][^\\/]+[\\/][^\\/]+[\\/]" .. buildhash_pattern - local prefix = path.directory(core_package.installdir()) + local prefix = core_package.installdir() io.gsub(file, search_pattern, function(whole_value, value) - local mat = value:match(package_pattern) + local mat = value:match(_PACKAGE_BUILDHASH_VERSION_PATTERN) if not mat then return nil end @@ -122,14 +122,14 @@ function _fix_path_for_file(file, search_pattern) local result local splitinfo = value:split(mat, {plain = true}) if #splitinfo == 2 then - -- /home/user[/packages/f/foo/buildhash]/v1.0 + -- /home/user/packages[/f/foo/buildhash]/v1.0 result = path.join(prefix, mat, splitinfo[2]) elseif #splitinfo == 1 then if value:startswith(mat) then - -- path begins with matched pattern: [/packages/f/foo/buildhash]/v1.0 + -- path begins with matched pattern: [/f/foo/buildhash]/v1.0 result = path.join(prefix, value) else - -- path ends with matched pattern: /home/user[/packages/f/foo/buildhash] + -- path ends with matched pattern: /home/user/packages[/f/foo/buildhash] result = path.join(prefix, mat) end else @@ -172,12 +172,40 @@ function _fix_paths_for_precompiled_package(package) search_pattern = {"([%w_]+%s*=%s*(.-)\n)", "(%-[I|L]%s*(%S+))", '("(.-)")'}, }, } + + -- If artifact contains installdir where it's built (remotedir), extract + -- path prefix and do plain replace with local install dir. + local remotedir + local manifest = package:manifest_load() + if manifest and manifest.artifacts then + remotedir = manifest.artifacts.remotedir + end + + local remote_prefix + local local_prefix + if remotedir then + local idx = remotedir:find(_PACKAGE_BUILDHASH_VERSION_PATTERN) + if idx then + remote_prefix = remotedir:sub(1, idx) + local_prefix = core_package.installdir() + if not local_prefix:endswith(path.sep()) then + local_prefix = local_prefix .. path.sep() + end + else + cprint("WARNING no package buildhash pattern found in artifacts remotedir: %s", remotedir) + end + end + for _, pat in ipairs(patterns) do for _, filepat in ipairs(pat.file_pattern) do local filepattern = path.join(package:installdir(), filepat) for _, file in ipairs(os.files(filepattern)) do - for _, search_pattern in ipairs(pat.search_pattern) do - _fix_path_for_file(file, search_pattern) + if remote_prefix then + io.replace(file, remote_prefix, local_prefix, {plain = true}) + else + for _, search_pattern in ipairs(pat.search_pattern) do + _fix_path_for_file(file, search_pattern) + end end end end From 69a9d7c9d887d5f7bd0deff7329910d9951261c8 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Tue, 29 Mar 2022 00:41:53 +0800 Subject: [PATCH 2/4] Fix package path match pattern. --- xmake/modules/private/action/require/impl/actions/install.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index c2d4a951d64..31610278eb5 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -99,7 +99,7 @@ end -- Match to path like (string insides brackets is matched): -- /home/user/.xmake/packages[/f/foo/9adc96bd69124211aad7dd58a36f02ce]/v1.0 -local _PACKAGE_BUILDHASH_VERSION_PATTERN = "[\\/]%w[\\/][^\\/]+[\\/][^\\/]+[\\/]" .. string.rep('%x', 32) +local _PACKAGE_BUILDHASH_VERSION_PATTERN = "[\\/]%w[\\/][^\\/]+[\\/]" .. string.rep('%x', 32) function _fix_path_for_file(file, search_pattern) -- Replace path string before package pattern with local package install From f21e4769f320e7b6405c6144df4646097b57d84b Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Tue, 29 Mar 2022 01:00:16 +0800 Subject: [PATCH 3/4] Revert package pattern, update comments. --- .../private/action/require/impl/actions/install.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index 31610278eb5..0013b002ba7 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -98,8 +98,8 @@ function _patch_pkgconfig(package) end -- Match to path like (string insides brackets is matched): --- /home/user/.xmake/packages[/f/foo/9adc96bd69124211aad7dd58a36f02ce]/v1.0 -local _PACKAGE_BUILDHASH_VERSION_PATTERN = "[\\/]%w[\\/][^\\/]+[\\/]" .. string.rep('%x', 32) +-- /home/user/.xmake/packages[/f/foo/v0.1.0/9adc96bd69124211aad7dd58a36f02ce]/lib +local _PACKAGE_VERSION_BUILDHASH_PATTERN = "[\\/]%w[\\/][^\\/]+[\\/][^\\/]+[\\/]" .. string.rep('%x', 32) function _fix_path_for_file(file, search_pattern) -- Replace path string before package pattern with local package install @@ -114,7 +114,7 @@ function _fix_path_for_file(file, search_pattern) local prefix = core_package.installdir() io.gsub(file, search_pattern, function(whole_value, value) - local mat = value:match(_PACKAGE_BUILDHASH_VERSION_PATTERN) + local mat = value:match(_PACKAGE_VERSION_BUILDHASH_PATTERN) if not mat then return nil end @@ -184,7 +184,7 @@ function _fix_paths_for_precompiled_package(package) local remote_prefix local local_prefix if remotedir then - local idx = remotedir:find(_PACKAGE_BUILDHASH_VERSION_PATTERN) + local idx = remotedir:find(_PACKAGE_VERSION_BUILDHASH_PATTERN) if idx then remote_prefix = remotedir:sub(1, idx) local_prefix = core_package.installdir() From 19c15c660b214820b0513007a05d9ccee4a4e55e Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 29 Mar 2022 11:08:59 +0800 Subject: [PATCH 4/4] Update install.lua --- xmake/modules/private/action/require/impl/actions/install.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index 0013b002ba7..6e451b89131 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -192,7 +192,7 @@ function _fix_paths_for_precompiled_package(package) local_prefix = local_prefix .. path.sep() end else - cprint("WARNING no package buildhash pattern found in artifacts remotedir: %s", remotedir) + wprint("no package buildhash pattern found in artifacts remotedir: %s", remotedir) end end