diff options
| author | ruki <[email protected]> | 2022-09-06 00:31:10 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-09-06 00:31:10 +0800 |
| commit | 80ad4a0ad0f0265654e1cf98c059f8d86ac28dc0 (patch) | |
| tree | 1e7c21d90886e842f08075a4d0b731dbc0b2ec81 | |
| parent | 2eabe3a9efd3ca4eaa4cbac769fbca6a6192af81 (diff) | |
check linkdeps compatibility
| -rw-r--r-- | xmake/core/project/policy.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 40 |
2 files changed, 43 insertions, 4 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 0509fcae8..f2cb546bd 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -71,9 +71,10 @@ function policy.policies() ["package.include_external_headers"] = {description = "Use includes as external headers.", type = "boolean"}, -- inherit the configs from the external command arguments, e.g. toolchains, `xmake f --toolchain=` ["package.inherit_external_configs"] = {description = "Inherit the configs from the external command arguments.", default = true, type = "boolean"}, - -- set version compatibility, if false, then new versions are always incompatible with older versions, - -- all packages that depend on it will generate a new buildhash, @see https://github.com/xmake-io/xmake/issues/2719 - ["package.version_compatibility"] = {description = "Set package version compatibility.", default = true, type = "boolean"}, + -- set strict compatibility for package dependencies + -- if true, then any updates to linked dependencies, such as buildhash changes due to version changes, + -- will force the installed packages to be recompiled and installed. @see https://github.com/xmake-io/xmake/issues/2719 + ["package.linkdeps.strict_compatibility"] = {description = "Set strict compatibility for package dependencies.", type = "boolean"}, } policy._POLICIES = policies end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 3a9f4c991..21164e4bf 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -946,6 +946,41 @@ function _must_depend_on(package, dep) end end +-- compatible with all previous link dependencies? +function _compatible_with_previous_linkdeps(package) + + -- check strict compatibility for linkdeps? + local strict_compatibility = project.policy("package.linkdeps.strict_compatibility") + if strict_compatibility == nil then + strict_compatibility = package:policy("package.linkdeps.strict_compatibility") + end + if not strict_compatibility then + return true + end + + -- compute the buildhash for previous linkdeps + local buildhashes_prev = {} + local manifest = package:manifest_load() + if manifest and manifest.linkdeps then + local deps = manifest.deps or {} + for _, depname in ipairs(manifest.linkdeps) do + local depinfo = deps[depname] + if depinfo and depinfo.buildhash then + table.insert(buildhashes_prev, depinfo.buildhash) + end + end + end + + -- compute the buildhash for current linkdeps + local buildhashes_curr = {} + for _, dep in ipairs(package:linkdeps()) do + table.insert(buildhashes_curr, dep:buildhash()) + end + + -- is compatible? + return table.concat(buildhashes_curr, "") == table.concat(buildhashes_prev) +end + -- the cache directory function cachedir() return path.join(global.directory(), "cache", "packages") @@ -953,7 +988,10 @@ end -- this package should be install? function should_install(package) - if package:is_template() or package:exists() then + if package:is_template() then + return false + end + if package:exists() and _compatible_with_previous_linkdeps(package) then return false end -- we need not install it if this package need only be fetched |
