diff options
| author | ruki <[email protected]> | 2022-05-26 22:39:53 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-26 22:39:53 +0800 |
| commit | 58aabd2476b610b706b38df17b7b12039a46ee3c (patch) | |
| tree | c8d729be85d165ce0a76636c04417ce173e8e845 | |
| parent | 58187b1d1e77925e31f96c4d8d1c96be88473244 (diff) | |
fallback to source build if precompiled errors
| -rw-r--r-- | xmake/core/package/package.lua | 30 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/actions/install.lua | 31 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/install_packages.lua | 12 |
3 files changed, 57 insertions, 16 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 76563c971..6862d320b 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -267,6 +267,9 @@ end function _instance:artifacts_set(artifacts_info) local versions = self:get("versions") if versions then + -- backup previous package configuration + self._ARTIFACTS_BACKUP = {urls = table.copy(self:urls()), versions = table.copy(versions), install = self:get("install")} + -- we switch to urls of the precompiled artifacts self:urls_set(table.wrap(artifacts_info.urls)) versions[self:version_str()] = artifacts_info.sha256 @@ -305,7 +308,32 @@ end -- is this package built? function _instance:is_built() - return not self._IS_PRECOMPILED + return not self:is_precompiled() +end + +-- is this package precompiled? +function _instance:is_precompiled() + return self._IS_PRECOMPILED +end + +-- fallback to source code build +function _instance:fackback_build() + if self:is_precompiled() then + local artifacts_backup = self._ARTIFACTS_BACKUP + if artifacts_backup then + if artifacts_backup.urls then + self:urls_set(artifacts_backup.urls) + end + if artifacts_backup.versions then + self:set("versions", artifacts_backup.versions) + end + if artifacts_backup.install then + self:set("install", artifacts_backup.install) + end + self._MANIFEST = nil + end + self._IS_PRECOMPILED = false + end end -- get the given dependent package diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index 348986239..d8d5cf606 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -258,6 +258,7 @@ function main(package) end -- install it + local ok = true local oldenvs = os.getenvs() try { @@ -375,22 +376,27 @@ function main(package) end os.tryrm(installdir) - -- failed - if not package:requireinfo().optional then - if os.isfile(errorfile) then - if errors then - print("") - for idx, line in ipairs(errors:split("\n")) do - print(line) - if idx > 16 then - break + -- is precompiled package? we can fallback to source package and try reinstall it again + if package:is_precompiled() then + ok = false + else + -- failed + if not package:requireinfo().optional then + if os.isfile(errorfile) then + if errors then + print("") + for idx, line in ipairs(errors:split("\n")) do + print(line) + if idx > 16 then + break + end end end + cprint("if you want to get more verbose errors, please see:") + cprint(" -> ${bright}%s", errorfile) end - cprint("if you want to get more verbose errors, please see:") - cprint(" -> ${bright}%s", errorfile) + raise("install failed!") end - raise("install failed!") end end } @@ -407,4 +413,5 @@ function main(package) -- leave source codes directory os.cd(oldir) + return ok end diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 2b99076cd..787dd90b2 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -26,12 +26,12 @@ import("core.project.project") import("core.base.tty") import("private.async.runjobs") import("utils.progress") -import("actions.install", {alias = "action_install"}) -import("actions.download", {alias = "action_download"}) import("net.fasturl") import("private.action.require.impl.package") import("private.action.require.impl.lock_packages") import("private.action.require.impl.register_packages") +import("private.action.require.impl.actions.install", {alias = "action_install"}) +import("private.action.require.impl.actions.download", {alias = "action_download"}) -- sort packages urls function _sort_packages_urls(packages) @@ -364,7 +364,13 @@ function _install_packages(packages_install, packages_download, installdeps) -- install this package packages_installing[index] = instance if downloaded then - action_install(instance) + if not action_install(instance) then + assert(instance:is_precompiled(), "package(%s) should be precompiled", instance:name()) + -- we need disable built and re-download and re-install it + instance:fackback_build() + action_download(instance) + action_install(instance) + end end -- register it to local cache if it is root required package |
