diff options
| author | ruki <[email protected]> | 2021-04-15 00:44:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-04-15 00:44:18 +0800 |
| commit | e2f886e49eb5d6047410e9990db77dadb6984b9d (patch) | |
| tree | a4f134a9aa462b1cf22a9702d6d7fb99ab35bae6 | |
| parent | daba45f8fe5736f18b1af82c9bca2da7c2835da8 (diff) | |
improve export packages
5 files changed, 99 insertions, 99 deletions
diff --git a/xmake/modules/private/action/require/export.lua b/xmake/modules/private/action/require/export.lua index ef1ecf011..8c550a4c3 100644 --- a/xmake/modules/private/action/require/export.lua +++ b/xmake/modules/private/action/require/export.lua @@ -47,9 +47,6 @@ function main(requires_raw) -- export packages local exportdir = option.get("exportdir") local packages = export_packages(requires, {requires_extra = requires_extra, exportdir = exportdir}) - for _, instance in ipairs(packages) do - print("export: %s%s ok!", instance:name(), instance:version_str() and ("-" .. instance:version_str()) or "") - end if not packages or #packages == 0 then cprint("${bright}packages(%s) not found, maybe they don’t exactly match the configuration.", table.concat(requires_raw, ", ")) if os.getenv("XREPO_WORKING") then @@ -61,8 +58,6 @@ function main(requires_raw) print(" - xmake require --export --extra=\"{configs={...}}\" package") print(" - xmake require --export --extra=\"{debug=true,configs={shared=true}}\" package") end - else - print("output: %s", exportdir) end -- leave environment diff --git a/xmake/modules/private/action/require/impl/export_packages.lua b/xmake/modules/private/action/require/impl/export_packages.lua index a169a163f..722a80a9a 100644 --- a/xmake/modules/private/action/require/impl/export_packages.lua +++ b/xmake/modules/private/action/require/impl/export_packages.lua @@ -19,6 +19,7 @@ -- -- imports +import("core.package.package", {alias = "core_package"}) import("private.action.require.impl.package") -- export packages @@ -34,16 +35,16 @@ function main(requires, opt) local packages = {} for _, instance in ipairs(package.load_packages(requires, opt)) do - -- get the exported name - local name = instance:name():lower():gsub("::", "_") - if instance:version_str() then - name = name .. "_" .. instance:version_str() - end - name = name .. "_" .. instance:buildhash() + -- get export path + local installdir = instance:installdir() + local rootdir = core_package.installdir() + local exportpath, count = installdir:replace(rootdir, exportdir, {plain = true}) -- export this package - if instance:fetch() then - os.cp(instance:installdir(), path.join(exportdir, name)) + if exportpath and count == 1 and instance:fetch() then + print("exporting %s-%s %s", instance:displayname(), instance:version_str(), package.get_configs_str(instance)) + cprint(" ${yellow}->${clear} %s", exportpath) + os.cp(instance:installdir(), exportpath) table.insert(packages, instance) end end diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 8bec808c6..1e9dcc4f1 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -46,55 +46,6 @@ function _sort_packages_urls(packages) end end --- get package parents string -function _get_package_parents_str(instance) - local parents = instance:parents() - if parents then - local parentnames = {} - for _, parent in pairs(parents) do - table.insert(parentnames, parent:displayname()) - end - if #parentnames == 0 then - return - end - return table.concat(parentnames, ",") - end -end - --- get package configs string -function _get_package_configs_str(instance) - local configs = {} - if instance:is_optional() then - table.insert(configs, "optional") - end - local requireinfo = instance:requireinfo() - if requireinfo then - if requireinfo.plat then - table.insert(configs, requireinfo.plat) - end - if requireinfo.arch then - table.insert(configs, requireinfo.arch) - end - for k, v in pairs(requireinfo.configs) do - if type(v) == "boolean" then - table.insert(configs, k .. ":" .. (v and "y" or "n")) - else - table.insert(configs, k .. ":" .. v) - end - end - end - local parents_str = _get_package_parents_str(instance) - if parents_str then - table.insert(configs, "from:" .. parents_str) - end - local configs_str = #configs > 0 and "[" .. table.concat(configs, ", ") .. "]" or "" - local limitwidth = os.getwinsize().width * 2 / 3 - if #configs_str > limitwidth then - configs_str = configs_str:sub(1, limitwidth) .. " ..)" - end - return configs_str -end - -- get user confirm function _get_confirm(packages) @@ -138,12 +89,12 @@ function _get_confirm(packages) local group = instance:group() if group and packages_group[group] and #packages_group[group] > 1 then for idx, package_in_group in ipairs(packages_group[group]) do - cprint(" ${yellow}%s${clear} %s %s ${dim}%s", idx == 1 and "->" or " or", package_in_group:displayname(), package_in_group:version_str() or "", _get_package_configs_str(package_in_group)) + cprint(" ${yellow}%s${clear} %s %s ${dim}%s", idx == 1 and "->" or " or", package_in_group:displayname(), package_in_group:version_str() or "", package.get_configs_str(package_in_group)) packages_showed[tostring(package_in_group)] = true end packages_group[group] = nil else - cprint(" ${yellow}->${clear} %s %s ${dim}%s", instance:displayname(), instance:version_str() or "", _get_package_configs_str(instance)) + cprint(" ${yellow}->${clear} %s %s ${dim}%s", instance:displayname(), instance:version_str() or "", package.get_configs_str(instance)) packages_showed[tostring(instance)] = true end end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 72ea3807a..fa11d4fc5 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -605,32 +605,6 @@ function _load_package(packagename, requireinfo, opt) return package end --- this package should be install? -function should_install(package) - if package:exists() then - return false - end - -- we need not install it if this package need only be fetched - if package:is_fetchonly() then - return false - end - -- only get system package? e.g. add_requires("xxx", {system = true}) - local requireinfo = package:requireinfo() - if requireinfo and requireinfo.system then - return false - end - if package:parents() then - -- if all the packages that depend on it already exist, then there is no need to install it - for _, parent in pairs(package:parents()) do - if should_install(parent) and not parent:exists() then - return true - end - end - else - return true - end -end - -- load all required packages function _load_packages(requires, opt) @@ -687,6 +661,81 @@ function cachedir() return path.join(global.directory(), "cache", "packages") end +-- this package should be install? +function should_install(package) + if package:exists() then + return false + end + -- we need not install it if this package need only be fetched + if package:is_fetchonly() then + return false + end + -- only get system package? e.g. add_requires("xxx", {system = true}) + local requireinfo = package:requireinfo() + if requireinfo and requireinfo.system then + return false + end + if package:parents() then + -- if all the packages that depend on it already exist, then there is no need to install it + for _, parent in pairs(package:parents()) do + if should_install(parent) and not parent:exists() then + return true + end + end + else + return true + end +end + +-- get package parents string +function _get_parents_str(package) + local parents = package:parents() + if parents then + local parentnames = {} + for _, parent in pairs(parents) do + table.insert(parentnames, parent:displayname()) + end + if #parentnames == 0 then + return + end + return table.concat(parentnames, ",") + end +end + +-- get package configs string +function get_configs_str(package) + local configs = {} + if package:is_optional() then + table.insert(configs, "optional") + end + local requireinfo = package:requireinfo() + if requireinfo then + if requireinfo.plat then + table.insert(configs, requireinfo.plat) + end + if requireinfo.arch then + table.insert(configs, requireinfo.arch) + end + for k, v in pairs(requireinfo.configs) do + if type(v) == "boolean" then + table.insert(configs, k .. ":" .. (v and "y" or "n")) + else + table.insert(configs, k .. ":" .. v) + end + end + end + local parents_str = _get_parents_str(package) + if parents_str then + table.insert(configs, "from:" .. parents_str) + end + local configs_str = #configs > 0 and "[" .. table.concat(configs, ", ") .. "]" or "" + local limitwidth = os.getwinsize().width * 2 / 3 + if #configs_str > limitwidth then + configs_str = configs_str:sub(1, limitwidth) .. " ..)" + end + return configs_str +end + -- load requires function load_requires(requires, requires_extra, opt) opt = opt or {} diff --git a/xmake/modules/private/xrepo/action/export.lua b/xmake/modules/private/xrepo/action/export.lua index 8295e962a..10e8b9a5a 100644 --- a/xmake/modules/private/xrepo/action/export.lua +++ b/xmake/modules/private/xrepo/action/export.lua @@ -72,13 +72,15 @@ function _export_packages(packages) -- enter working project directory local oldir = os.curdir() - local workdir = path.join(os.tmpdir(), "xrepo", "working") - if not os.isdir(workdir) then - os.mkdir(workdir) - os.cd(workdir) - os.vrunv("xmake", {"create", "-P", "."}) - else - os.cd(workdir) + if packages or not os.isfile(os.projectfile()) then + local workdir = path.join(os.tmpdir(), "xrepo", "working") + if not os.isdir(workdir) then + os.mkdir(workdir) + os.cd(workdir) + os.vrunv("xmake", {"create", "-P", "."}) + else + os.cd(workdir) + end end -- do configure first @@ -149,14 +151,16 @@ function _export_packages(packages) local extra_str = string.serialize(extra, {indent = false, strip = true}) table.insert(require_argv, "--extra=" .. extra_str) end - table.join2(require_argv, packages) + if packages then + table.join2(require_argv, packages) + end os.vexecv("xmake", require_argv) end -- main entry function main() local packages = option.get("packages") - if packages then + if packages or os.isfile(os.projectfile()) then _export_packages(packages) else raise("please specify the packages to be exported.") |
