From a95ee75af458c25f8155ecf23657b6571c9b067e Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 00:38:35 +0800 Subject: improve package task menu --- xmake/actions/package/xmake.lua | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua index d30815a98..67d98aa7b 100644 --- a/xmake/actions/package/xmake.lua +++ b/xmake/actions/package/xmake.lua @@ -18,36 +18,25 @@ -- @file xmake.lua -- --- define task task("package") - - -- set category set_category("action") - - -- on run on_run("main") - - -- set menu set_menu { - -- usage - usage = "xmake package|p [options] [target]" - - -- description - , description = "Package target." - - -- xmake p - , shortname = 'p' - - -- options - , options = - { - {'o', "outputdir", "kv", nil , "Set the output directory." } - , {'a', "all", "k", nil , "Package all targets." } - , {} - , {nil, "target", "v", nil , "The target name. It will package all default targets if this parameter is not specified." - , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } - } - } + usage = "xmake package|p [options] [target]", + description = "Package target.", + shortname = 'p', + options = { + {'o', "outputdir", "kv", nil, "Set the output directory."}, + {'a', "all", "k", nil, "Package all targets."}, + {'f', "format", "kv", "local", "Set the package format.", + values = {"dotpkg", "local"}}, + {}, + {nil, "target", "v", nil, "The target name. It will package all default targets if this parameter is not specified.", + values = function (complete, opt) + return import("private.utils.complete_helper.targets")(complete, opt) + end } + } + } -- cgit v1.3.1 From 7400647d109b785f492c51c29fd217da3a76c928 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 00:41:49 +0800 Subject: add localpkg format stub --- xmake/actions/package/localpkg/main.lua | 226 ++++++++++++++++++++++++++++++++ xmake/actions/package/main.lua | 213 +----------------------------- xmake/actions/package/oldpkg/main.lua | 226 ++++++++++++++++++++++++++++++++ xmake/actions/package/xmake.lua | 16 +-- 4 files changed, 462 insertions(+), 219 deletions(-) create mode 100644 xmake/actions/package/localpkg/main.lua create mode 100644 xmake/actions/package/oldpkg/main.lua diff --git a/xmake/actions/package/localpkg/main.lua b/xmake/actions/package/localpkg/main.lua new file mode 100644 index 000000000..f0202428c --- /dev/null +++ b/xmake/actions/package/localpkg/main.lua @@ -0,0 +1,226 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file main.lua +-- + +-- imports +import("core.base.option") +import("core.base.task") +import("core.base.global") +import("core.project.rule") +import("core.project.config") +import("core.project.project") +import("core.platform.platform") + +-- package library +function _package_library(target) + + -- the output directory + local outputdir = option.get("outputdir") or config.buildir() + + -- the target name + local targetname = target:name() + + -- copy the library file to the output directory + os.vcp(target:targetfile(), format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(target:targetfile()))) + + -- copy the symbol file to the output directory + local symbolfile = target:symbolfile() + if os.isfile(symbolfile) then + os.vcp(symbolfile, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(symbolfile))) + end + + -- copy *.lib for shared/windows (*.dll) target + -- @see https://github.com/xmake-io/xmake/issues/787 + if target:kind() == "shared" and is_plat("windows", "mingw") then + local targetfile = target:targetfile() + local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") + if os.isfile(targetfile_lib) then + os.vcp(targetfile_lib, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/", outputdir, targetname)) + end + end + + -- copy the config.h to the output directory (deprecated) + local configheader = target:configheader() + if configheader then + os.vcp(configheader, format("%s/%s.pkg/$(plat)/$(arch)/include/%s", outputdir, targetname, path.filename(configheader))) + end + + -- copy headers + local srcheaders, dstheaders = target:headerfiles(format("%s/%s.pkg/$(plat)/$(arch)/include", outputdir, targetname)) + if srcheaders and dstheaders then + local i = 1 + for _, srcheader in ipairs(srcheaders) do + local dstheader = dstheaders[i] + if dstheader then + os.vcp(srcheader, dstheader) + end + i = i + 1 + end + end + + -- make xmake.lua + local file = io.open(format("%s/%s.pkg/xmake.lua", outputdir, targetname), "w") + if file then + file:print("option(\"%s\")", targetname) + file:print(" set_showmenu(true)") + file:print(" set_category(\"package\")") + file:print(" add_links(\"%s\")", target:basename()) + file:write(" add_linkdirs(\"$(plat)/$(arch)/lib/$(mode)\")\n") + file:write(" add_includedirs(\"$(plat)/$(arch)/include\")\n") + local languages = target:get("languages") + if languages then + file:print(" set_languages(\"%s\")", table.concat(table.wrap(languages), "\", \"")) + end + file:close() + end +end + +-- do package target +function _do_package_target(target) + + -- is phony target? + if target:is_phony() then + return + end + + -- get kind + local kind = target:kind() + + -- get script + local scripts = + { + binary = function (target) end + , static = _package_library + , shared = _package_library + } + + -- check + assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) + + -- package it + scripts[kind](target) +end + +-- package target +function _on_package_target(target) + + -- build target with rules + local done = false + for _, r in ipairs(target:orderules()) do + local on_package = r:script("package") + if on_package then + on_package(target) + done = true + end + end + if done then return end + + -- do package + _do_package_target(target) +end + +-- package the given target +function _package_target(target) + + -- has been disabled? + if not target:is_enabled() then + return + end + + -- enter project directory + local oldir = os.cd(project.directory()) + + -- enter the environments of the target packages + local oldenvs = os.addenvs(target:pkgenvs()) + + -- the target scripts + local scripts = + { + target:script("package_before") + , function (target) + for _, r in ipairs(target:orderules()) do + local before_package = r:script("package_before") + if before_package then + before_package(target) + end + end + end + , target:script("package", _on_package_target) + , function (target) + for _, r in ipairs(target:orderules()) do + local after_package = r:script("package_after") + if after_package then + after_package(target) + end + end + end + , target:script("package_after") + } + + -- package the target scripts + for i = 1, 5 do + local script = scripts[i] + if script ~= nil then + script(target) + end + end + + -- leave the environments of the target packages + os.setenvs(oldenvs) + + -- leave project directory + os.cd(oldir) +end + +-- package the given targets +function _package_targets(targets) + for _, target in ipairs(targets) do + _package_target(target) + end +end + +-- main +function main() + + -- lock the whole project + project.lock() + + -- get the target name + local targetname = option.get("target") + + -- build it first + task.run("build", {target = targetname, all = option.get("all")}) + + -- package the given target? + if targetname then + local target = project.target(targetname) + _package_targets(target:orderdeps()) + _package_target(target) + else + -- package default or all targets + for _, target in ipairs(project.ordertargets()) do + if target:is_default() or option.get("all") then + _package_target(target) + end + end + end + + -- unlock the whole project + project.unlock() +end diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua index a1fcab5ed..78835bb61 100644 --- a/xmake/actions/package/main.lua +++ b/xmake/actions/package/main.lua @@ -20,217 +20,8 @@ -- imports import("core.base.option") -import("core.base.task") -import("core.base.global") -import("core.project.rule") -import("core.project.config") -import("core.project.project") -import("core.platform.platform") --- package library -function _package_library(target) - - -- the output directory - local outputdir = option.get("outputdir") or config.buildir() - - -- the target name - local targetname = target:name() - - -- copy the library file to the output directory - os.vcp(target:targetfile(), format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(target:targetfile()))) - - -- copy the symbol file to the output directory - local symbolfile = target:symbolfile() - if os.isfile(symbolfile) then - os.vcp(symbolfile, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(symbolfile))) - end - - -- copy *.lib for shared/windows (*.dll) target - -- @see https://github.com/xmake-io/xmake/issues/787 - if target:kind() == "shared" and is_plat("windows", "mingw") then - local targetfile = target:targetfile() - local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") - if os.isfile(targetfile_lib) then - os.vcp(targetfile_lib, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/", outputdir, targetname)) - end - end - - -- copy the config.h to the output directory (deprecated) - local configheader = target:configheader() - if configheader then - os.vcp(configheader, format("%s/%s.pkg/$(plat)/$(arch)/include/%s", outputdir, targetname, path.filename(configheader))) - end - - -- copy headers - local srcheaders, dstheaders = target:headerfiles(format("%s/%s.pkg/$(plat)/$(arch)/include", outputdir, targetname)) - if srcheaders and dstheaders then - local i = 1 - for _, srcheader in ipairs(srcheaders) do - local dstheader = dstheaders[i] - if dstheader then - os.vcp(srcheader, dstheader) - end - i = i + 1 - end - end - - -- make xmake.lua - local file = io.open(format("%s/%s.pkg/xmake.lua", outputdir, targetname), "w") - if file then - file:print("option(\"%s\")", targetname) - file:print(" set_showmenu(true)") - file:print(" set_category(\"package\")") - file:print(" add_links(\"%s\")", target:basename()) - file:write(" add_linkdirs(\"$(plat)/$(arch)/lib/$(mode)\")\n") - file:write(" add_includedirs(\"$(plat)/$(arch)/include\")\n") - local languages = target:get("languages") - if languages then - file:print(" set_languages(\"%s\")", table.concat(table.wrap(languages), "\", \"")) - end - file:close() - end -end - --- do package target -function _do_package_target(target) - - -- is phony target? - if target:is_phony() then - return - end - - -- get kind - local kind = target:kind() - - -- get script - local scripts = - { - binary = function (target) end - , static = _package_library - , shared = _package_library - } - - -- check - assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) - - -- package it - scripts[kind](target) -end - --- package target -function _on_package_target(target) - - -- build target with rules - local done = false - for _, r in ipairs(target:orderules()) do - local on_package = r:script("package") - if on_package then - on_package(target) - done = true - end - end - if done then return end - - -- do package - _do_package_target(target) -end - --- package the given target -function _package_target(target) - - -- has been disabled? - if not target:is_enabled() then - return - end - - -- enter project directory - local oldir = os.cd(project.directory()) - - -- enter the environments of the target packages - local oldenvs = os.addenvs(target:pkgenvs()) - - -- the target scripts - local scripts = - { - target:script("package_before") - , function (target) - for _, r in ipairs(target:orderules()) do - local before_package = r:script("package_before") - if before_package then - before_package(target) - end - end - end - , target:script("package", _on_package_target) - , function (target) - for _, r in ipairs(target:orderules()) do - local after_package = r:script("package_after") - if after_package then - after_package(target) - end - end - end - , target:script("package_after") - } - - -- package the target scripts - for i = 1, 5 do - local script = scripts[i] - if script ~= nil then - script(target) - end - end - - -- leave the environments of the target packages - os.setenvs(oldenvs) - - -- leave project directory - os.cd(oldir) -end - --- package the given targets -function _package_targets(targets) - for _, target in ipairs(targets) do - _package_target(target) - end -end - --- main +-- main entry function main() - - -- --archs? deprecated - if option.get("archs") then - - -- load config - config.load() - - -- deprecated - raise("please run \"xmake m package %s\" instead of \"xmake p --archs=%s\"", config.get("plat"), option.get("archs")) - end - - -- lock the whole project - project.lock() - - -- get the target name - local targetname = option.get("target") - - -- build it first - task.run("build", {target = targetname, all = option.get("all")}) - - -- package the given target? - if targetname then - local target = project.target(targetname) - _package_targets(target:orderdeps()) - _package_target(target) - else - -- package default or all targets - for _, target in ipairs(project.ordertargets()) do - if target:is_default() or option.get("all") then - _package_target(target) - end - end - end - - -- unlock the whole project - project.lock() + import(option.get("format") or "local")() end diff --git a/xmake/actions/package/oldpkg/main.lua b/xmake/actions/package/oldpkg/main.lua new file mode 100644 index 000000000..f0202428c --- /dev/null +++ b/xmake/actions/package/oldpkg/main.lua @@ -0,0 +1,226 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file main.lua +-- + +-- imports +import("core.base.option") +import("core.base.task") +import("core.base.global") +import("core.project.rule") +import("core.project.config") +import("core.project.project") +import("core.platform.platform") + +-- package library +function _package_library(target) + + -- the output directory + local outputdir = option.get("outputdir") or config.buildir() + + -- the target name + local targetname = target:name() + + -- copy the library file to the output directory + os.vcp(target:targetfile(), format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(target:targetfile()))) + + -- copy the symbol file to the output directory + local symbolfile = target:symbolfile() + if os.isfile(symbolfile) then + os.vcp(symbolfile, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(symbolfile))) + end + + -- copy *.lib for shared/windows (*.dll) target + -- @see https://github.com/xmake-io/xmake/issues/787 + if target:kind() == "shared" and is_plat("windows", "mingw") then + local targetfile = target:targetfile() + local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") + if os.isfile(targetfile_lib) then + os.vcp(targetfile_lib, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/", outputdir, targetname)) + end + end + + -- copy the config.h to the output directory (deprecated) + local configheader = target:configheader() + if configheader then + os.vcp(configheader, format("%s/%s.pkg/$(plat)/$(arch)/include/%s", outputdir, targetname, path.filename(configheader))) + end + + -- copy headers + local srcheaders, dstheaders = target:headerfiles(format("%s/%s.pkg/$(plat)/$(arch)/include", outputdir, targetname)) + if srcheaders and dstheaders then + local i = 1 + for _, srcheader in ipairs(srcheaders) do + local dstheader = dstheaders[i] + if dstheader then + os.vcp(srcheader, dstheader) + end + i = i + 1 + end + end + + -- make xmake.lua + local file = io.open(format("%s/%s.pkg/xmake.lua", outputdir, targetname), "w") + if file then + file:print("option(\"%s\")", targetname) + file:print(" set_showmenu(true)") + file:print(" set_category(\"package\")") + file:print(" add_links(\"%s\")", target:basename()) + file:write(" add_linkdirs(\"$(plat)/$(arch)/lib/$(mode)\")\n") + file:write(" add_includedirs(\"$(plat)/$(arch)/include\")\n") + local languages = target:get("languages") + if languages then + file:print(" set_languages(\"%s\")", table.concat(table.wrap(languages), "\", \"")) + end + file:close() + end +end + +-- do package target +function _do_package_target(target) + + -- is phony target? + if target:is_phony() then + return + end + + -- get kind + local kind = target:kind() + + -- get script + local scripts = + { + binary = function (target) end + , static = _package_library + , shared = _package_library + } + + -- check + assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) + + -- package it + scripts[kind](target) +end + +-- package target +function _on_package_target(target) + + -- build target with rules + local done = false + for _, r in ipairs(target:orderules()) do + local on_package = r:script("package") + if on_package then + on_package(target) + done = true + end + end + if done then return end + + -- do package + _do_package_target(target) +end + +-- package the given target +function _package_target(target) + + -- has been disabled? + if not target:is_enabled() then + return + end + + -- enter project directory + local oldir = os.cd(project.directory()) + + -- enter the environments of the target packages + local oldenvs = os.addenvs(target:pkgenvs()) + + -- the target scripts + local scripts = + { + target:script("package_before") + , function (target) + for _, r in ipairs(target:orderules()) do + local before_package = r:script("package_before") + if before_package then + before_package(target) + end + end + end + , target:script("package", _on_package_target) + , function (target) + for _, r in ipairs(target:orderules()) do + local after_package = r:script("package_after") + if after_package then + after_package(target) + end + end + end + , target:script("package_after") + } + + -- package the target scripts + for i = 1, 5 do + local script = scripts[i] + if script ~= nil then + script(target) + end + end + + -- leave the environments of the target packages + os.setenvs(oldenvs) + + -- leave project directory + os.cd(oldir) +end + +-- package the given targets +function _package_targets(targets) + for _, target in ipairs(targets) do + _package_target(target) + end +end + +-- main +function main() + + -- lock the whole project + project.lock() + + -- get the target name + local targetname = option.get("target") + + -- build it first + task.run("build", {target = targetname, all = option.get("all")}) + + -- package the given target? + if targetname then + local target = project.target(targetname) + _package_targets(target:orderdeps()) + _package_target(target) + else + -- package default or all targets + for _, target in ipairs(project.ordertargets()) do + if target:is_default() or option.get("all") then + _package_target(target) + end + end + end + + -- unlock the whole project + project.unlock() +end diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua index 67d98aa7b..5fe7bf20d 100644 --- a/xmake/actions/package/xmake.lua +++ b/xmake/actions/package/xmake.lua @@ -26,15 +26,15 @@ task("package") description = "Package target.", shortname = 'p', options = { - {'o', "outputdir", "kv", nil, "Set the output directory."}, - {'a', "all", "k", nil, "Package all targets."}, - {'f', "format", "kv", "local", "Set the package format.", - values = {"dotpkg", "local"}}, + {'o', "outputdir", "kv", nil, "Set the output directory."}, + {'a', "all", "k", nil, "Package all targets."}, + {'f', "format", "kv", "localpkg", "Set the package format.", + values = {"oldpkg", "localpkg"}}, {}, - {nil, "target", "v", nil, "The target name. It will package all default targets if this parameter is not specified.", - values = function (complete, opt) - return import("private.utils.complete_helper.targets")(complete, opt) - end } + {nil, "target", "v", nil, "The target name. It will package all default targets if this parameter is not specified.", + values = function (complete, opt) + return import("private.utils.complete_helper.targets")(complete, opt) + end } } } -- cgit v1.3.1 From d721e17b252a7de7b601c829c56290587e5ef6ff Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 00:44:06 +0800 Subject: improve some code styles --- xmake/actions/package/localpkg/main.lua | 89 --------------------------------- xmake/actions/package/oldpkg/main.lua | 39 ++++----------- 2 files changed, 11 insertions(+), 117 deletions(-) diff --git a/xmake/actions/package/localpkg/main.lua b/xmake/actions/package/localpkg/main.lua index f0202428c..8118bff7a 100644 --- a/xmake/actions/package/localpkg/main.lua +++ b/xmake/actions/package/localpkg/main.lua @@ -21,106 +21,19 @@ -- imports import("core.base.option") import("core.base.task") -import("core.base.global") import("core.project.rule") import("core.project.config") import("core.project.project") -import("core.platform.platform") - --- package library -function _package_library(target) - - -- the output directory - local outputdir = option.get("outputdir") or config.buildir() - - -- the target name - local targetname = target:name() - - -- copy the library file to the output directory - os.vcp(target:targetfile(), format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(target:targetfile()))) - - -- copy the symbol file to the output directory - local symbolfile = target:symbolfile() - if os.isfile(symbolfile) then - os.vcp(symbolfile, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/%s", outputdir, targetname, path.filename(symbolfile))) - end - - -- copy *.lib for shared/windows (*.dll) target - -- @see https://github.com/xmake-io/xmake/issues/787 - if target:kind() == "shared" and is_plat("windows", "mingw") then - local targetfile = target:targetfile() - local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") - if os.isfile(targetfile_lib) then - os.vcp(targetfile_lib, format("%s/%s.pkg/$(plat)/$(arch)/lib/$(mode)/", outputdir, targetname)) - end - end - - -- copy the config.h to the output directory (deprecated) - local configheader = target:configheader() - if configheader then - os.vcp(configheader, format("%s/%s.pkg/$(plat)/$(arch)/include/%s", outputdir, targetname, path.filename(configheader))) - end - - -- copy headers - local srcheaders, dstheaders = target:headerfiles(format("%s/%s.pkg/$(plat)/$(arch)/include", outputdir, targetname)) - if srcheaders and dstheaders then - local i = 1 - for _, srcheader in ipairs(srcheaders) do - local dstheader = dstheaders[i] - if dstheader then - os.vcp(srcheader, dstheader) - end - i = i + 1 - end - end - - -- make xmake.lua - local file = io.open(format("%s/%s.pkg/xmake.lua", outputdir, targetname), "w") - if file then - file:print("option(\"%s\")", targetname) - file:print(" set_showmenu(true)") - file:print(" set_category(\"package\")") - file:print(" add_links(\"%s\")", target:basename()) - file:write(" add_linkdirs(\"$(plat)/$(arch)/lib/$(mode)\")\n") - file:write(" add_includedirs(\"$(plat)/$(arch)/include\")\n") - local languages = target:get("languages") - if languages then - file:print(" set_languages(\"%s\")", table.concat(table.wrap(languages), "\", \"")) - end - file:close() - end -end -- do package target function _do_package_target(target) - - -- is phony target? if target:is_phony() then return end - - -- get kind - local kind = target:kind() - - -- get script - local scripts = - { - binary = function (target) end - , static = _package_library - , shared = _package_library - } - - -- check - assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) - - -- package it - scripts[kind](target) end -- package target function _on_package_target(target) - - -- build target with rules local done = false for _, r in ipairs(target:orderules()) do local on_package = r:script("package") @@ -130,8 +43,6 @@ function _on_package_target(target) end end if done then return end - - -- do package _do_package_target(target) end diff --git a/xmake/actions/package/oldpkg/main.lua b/xmake/actions/package/oldpkg/main.lua index f0202428c..d47d8d474 100644 --- a/xmake/actions/package/oldpkg/main.lua +++ b/xmake/actions/package/oldpkg/main.lua @@ -21,11 +21,9 @@ -- imports import("core.base.option") import("core.base.task") -import("core.base.global") import("core.project.rule") import("core.project.config") import("core.project.project") -import("core.platform.platform") -- package library function _package_library(target) @@ -47,7 +45,7 @@ function _package_library(target) -- copy *.lib for shared/windows (*.dll) target -- @see https://github.com/xmake-io/xmake/issues/787 - if target:kind() == "shared" and is_plat("windows", "mingw") then + if target:is_shared() and target:is_plat("windows", "mingw") then local targetfile = target:targetfile() local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") if os.isfile(targetfile_lib) then @@ -93,34 +91,21 @@ end -- do package target function _do_package_target(target) - - -- is phony target? - if target:is_phony() then - return + if not target:is_phony() then + local scripts = + { + binary = function (target) end + , static = _package_library + , shared = _package_library + } + local kind = target:kind() + assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) + scripts[kind](target) end - - -- get kind - local kind = target:kind() - - -- get script - local scripts = - { - binary = function (target) end - , static = _package_library - , shared = _package_library - } - - -- check - assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) - - -- package it - scripts[kind](target) end -- package target function _on_package_target(target) - - -- build target with rules local done = false for _, r in ipairs(target:orderules()) do local on_package = r:script("package") @@ -130,8 +115,6 @@ function _on_package_target(target) end end if done then return end - - -- do package _do_package_target(target) end -- cgit v1.3.1 From 9ce75674d39133415fc292381ec59c04b55cae14 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 00:45:08 +0800 Subject: add local and remote package --- xmake/actions/package/local/main.lua | 137 ++++++++++++++++++++++++++++++++ xmake/actions/package/localpkg/main.lua | 137 -------------------------------- xmake/actions/package/remote/main.lua | 137 ++++++++++++++++++++++++++++++++ xmake/actions/package/xmake.lua | 16 ++-- 4 files changed, 282 insertions(+), 145 deletions(-) create mode 100644 xmake/actions/package/local/main.lua delete mode 100644 xmake/actions/package/localpkg/main.lua create mode 100644 xmake/actions/package/remote/main.lua diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua new file mode 100644 index 000000000..8118bff7a --- /dev/null +++ b/xmake/actions/package/local/main.lua @@ -0,0 +1,137 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file main.lua +-- + +-- imports +import("core.base.option") +import("core.base.task") +import("core.project.rule") +import("core.project.config") +import("core.project.project") + +-- do package target +function _do_package_target(target) + if target:is_phony() then + return + end +end + +-- package target +function _on_package_target(target) + local done = false + for _, r in ipairs(target:orderules()) do + local on_package = r:script("package") + if on_package then + on_package(target) + done = true + end + end + if done then return end + _do_package_target(target) +end + +-- package the given target +function _package_target(target) + + -- has been disabled? + if not target:is_enabled() then + return + end + + -- enter project directory + local oldir = os.cd(project.directory()) + + -- enter the environments of the target packages + local oldenvs = os.addenvs(target:pkgenvs()) + + -- the target scripts + local scripts = + { + target:script("package_before") + , function (target) + for _, r in ipairs(target:orderules()) do + local before_package = r:script("package_before") + if before_package then + before_package(target) + end + end + end + , target:script("package", _on_package_target) + , function (target) + for _, r in ipairs(target:orderules()) do + local after_package = r:script("package_after") + if after_package then + after_package(target) + end + end + end + , target:script("package_after") + } + + -- package the target scripts + for i = 1, 5 do + local script = scripts[i] + if script ~= nil then + script(target) + end + end + + -- leave the environments of the target packages + os.setenvs(oldenvs) + + -- leave project directory + os.cd(oldir) +end + +-- package the given targets +function _package_targets(targets) + for _, target in ipairs(targets) do + _package_target(target) + end +end + +-- main +function main() + + -- lock the whole project + project.lock() + + -- get the target name + local targetname = option.get("target") + + -- build it first + task.run("build", {target = targetname, all = option.get("all")}) + + -- package the given target? + if targetname then + local target = project.target(targetname) + _package_targets(target:orderdeps()) + _package_target(target) + else + -- package default or all targets + for _, target in ipairs(project.ordertargets()) do + if target:is_default() or option.get("all") then + _package_target(target) + end + end + end + + -- unlock the whole project + project.unlock() +end diff --git a/xmake/actions/package/localpkg/main.lua b/xmake/actions/package/localpkg/main.lua deleted file mode 100644 index 8118bff7a..000000000 --- a/xmake/actions/package/localpkg/main.lua +++ /dev/null @@ -1,137 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file main.lua --- - --- imports -import("core.base.option") -import("core.base.task") -import("core.project.rule") -import("core.project.config") -import("core.project.project") - --- do package target -function _do_package_target(target) - if target:is_phony() then - return - end -end - --- package target -function _on_package_target(target) - local done = false - for _, r in ipairs(target:orderules()) do - local on_package = r:script("package") - if on_package then - on_package(target) - done = true - end - end - if done then return end - _do_package_target(target) -end - --- package the given target -function _package_target(target) - - -- has been disabled? - if not target:is_enabled() then - return - end - - -- enter project directory - local oldir = os.cd(project.directory()) - - -- enter the environments of the target packages - local oldenvs = os.addenvs(target:pkgenvs()) - - -- the target scripts - local scripts = - { - target:script("package_before") - , function (target) - for _, r in ipairs(target:orderules()) do - local before_package = r:script("package_before") - if before_package then - before_package(target) - end - end - end - , target:script("package", _on_package_target) - , function (target) - for _, r in ipairs(target:orderules()) do - local after_package = r:script("package_after") - if after_package then - after_package(target) - end - end - end - , target:script("package_after") - } - - -- package the target scripts - for i = 1, 5 do - local script = scripts[i] - if script ~= nil then - script(target) - end - end - - -- leave the environments of the target packages - os.setenvs(oldenvs) - - -- leave project directory - os.cd(oldir) -end - --- package the given targets -function _package_targets(targets) - for _, target in ipairs(targets) do - _package_target(target) - end -end - --- main -function main() - - -- lock the whole project - project.lock() - - -- get the target name - local targetname = option.get("target") - - -- build it first - task.run("build", {target = targetname, all = option.get("all")}) - - -- package the given target? - if targetname then - local target = project.target(targetname) - _package_targets(target:orderdeps()) - _package_target(target) - else - -- package default or all targets - for _, target in ipairs(project.ordertargets()) do - if target:is_default() or option.get("all") then - _package_target(target) - end - end - end - - -- unlock the whole project - project.unlock() -end diff --git a/xmake/actions/package/remote/main.lua b/xmake/actions/package/remote/main.lua new file mode 100644 index 000000000..8118bff7a --- /dev/null +++ b/xmake/actions/package/remote/main.lua @@ -0,0 +1,137 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file main.lua +-- + +-- imports +import("core.base.option") +import("core.base.task") +import("core.project.rule") +import("core.project.config") +import("core.project.project") + +-- do package target +function _do_package_target(target) + if target:is_phony() then + return + end +end + +-- package target +function _on_package_target(target) + local done = false + for _, r in ipairs(target:orderules()) do + local on_package = r:script("package") + if on_package then + on_package(target) + done = true + end + end + if done then return end + _do_package_target(target) +end + +-- package the given target +function _package_target(target) + + -- has been disabled? + if not target:is_enabled() then + return + end + + -- enter project directory + local oldir = os.cd(project.directory()) + + -- enter the environments of the target packages + local oldenvs = os.addenvs(target:pkgenvs()) + + -- the target scripts + local scripts = + { + target:script("package_before") + , function (target) + for _, r in ipairs(target:orderules()) do + local before_package = r:script("package_before") + if before_package then + before_package(target) + end + end + end + , target:script("package", _on_package_target) + , function (target) + for _, r in ipairs(target:orderules()) do + local after_package = r:script("package_after") + if after_package then + after_package(target) + end + end + end + , target:script("package_after") + } + + -- package the target scripts + for i = 1, 5 do + local script = scripts[i] + if script ~= nil then + script(target) + end + end + + -- leave the environments of the target packages + os.setenvs(oldenvs) + + -- leave project directory + os.cd(oldir) +end + +-- package the given targets +function _package_targets(targets) + for _, target in ipairs(targets) do + _package_target(target) + end +end + +-- main +function main() + + -- lock the whole project + project.lock() + + -- get the target name + local targetname = option.get("target") + + -- build it first + task.run("build", {target = targetname, all = option.get("all")}) + + -- package the given target? + if targetname then + local target = project.target(targetname) + _package_targets(target:orderdeps()) + _package_target(target) + else + -- package default or all targets + for _, target in ipairs(project.ordertargets()) do + if target:is_default() or option.get("all") then + _package_target(target) + end + end + end + + -- unlock the whole project + project.unlock() +end diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua index 5fe7bf20d..0a757a1eb 100644 --- a/xmake/actions/package/xmake.lua +++ b/xmake/actions/package/xmake.lua @@ -26,15 +26,15 @@ task("package") description = "Package target.", shortname = 'p', options = { - {'o', "outputdir", "kv", nil, "Set the output directory."}, - {'a', "all", "k", nil, "Package all targets."}, - {'f', "format", "kv", "localpkg", "Set the package format.", - values = {"oldpkg", "localpkg"}}, + {'o', "outputdir", "kv", nil, "Set the output directory."}, + {'a', "all", "k", nil, "Package all targets."}, + {'f', "format", "kv", "local", "Set the package format.", + values = {"oldpkg", "local", "remote"}}, {}, - {nil, "target", "v", nil, "The target name. It will package all default targets if this parameter is not specified.", - values = function (complete, opt) - return import("private.utils.complete_helper.targets")(complete, opt) - end } + {nil, "target", "v", nil, "The target name. It will package all default targets if this parameter is not specified.", + values = function (complete, opt) + return import("private.utils.complete_helper.targets")(complete, opt) + end } } } -- cgit v1.3.1 From 3bfbab4917a5b396444c188e32bfa4846c6f5d3f Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 00:53:54 +0800 Subject: copy package files --- xmake/actions/package/local/main.lua | 89 +++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index 8118bff7a..4be7769eb 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -25,10 +25,95 @@ import("core.project.rule") import("core.project.config") import("core.project.project") +-- package binary +function _package_binary(target) + + -- get the output directory + local outputdir = option.get("outputdir") or config.buildir() + + -- generate xmake.lua + local packagename = target:name():lower() + local file = io.open(path.join(outputdir, "packages", packagename:sub(1, 1), packagename, "xmake.lua"), "w") + if file then + file:print("package(\"%s\")", packagename) + file:print(" set_description(\"%s\")", "The " .. packagename .. " package.") + file:print(" set_kind(\"binary\")") + file:print(" on_fetch(function (package, opt)") + file:print(" return {program = \"%s\"}", target:targetfile()) + file:print(" end)") + file:close() + end +end + +-- package library +function _package_library(target) + + -- get the output directory + local outputdir = option.get("outputdir") or config.buildir() + local packagename = target:name():lower() + local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) + local binarydir = path.join(packagedir, "bin", target:plat(), target:arch(), config.mode()) + local librarydir = path.join(packagedir, "lib", target:plat(), target:arch(), config.mode()) + + -- copy the library file to the output directory + local targetfile = target:targetfile() + if target:is_shared() and target:is_plat("windows", "mingw") then + os.mkdir(binarydir) + os.vcp(targetfile, binarydir) + os.trycp(target:symbolfile(), binarydir) + local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") + if os.isfile(targetfile_lib) then + os.mkdir(librarydir) + os.vcp(targetfile_lib, librarydir) + end + else + os.mkdir(librarydir) + os.vcp(targetfile, librarydir) + os.trycp(target:symbolfile(), librarydir) + end + + -- copy headers + local srcheaders, dstheaders = target:headerfiles(path.join(packagedir, "include")) + if srcheaders and dstheaders then + local i = 1 + for _, srcheader in ipairs(srcheaders) do + local dstheader = dstheaders[i] + if dstheader then + os.vcp(srcheader, dstheader) + end + i = i + 1 + end + end + + -- generate xmake.lua + local file = io.open(path.join(packagedir, "xmake.lua"), "w") + if file then + file:print("package(\"%s\")", packagename) + file:print(" set_description(\"%s\")", "The " .. packagename .. " package.") + file:print(" on_fetch(function (package, opt)") + file:print(" local result = {}") + file:print(" result.links = \"%s\"", target:linkname()) + if target:version() then + file:print(" result.version = \"%s\"", (target:version())) + end + file:print(" return result") + file:print(" end)") + file:close() + end +end + -- do package target function _do_package_target(target) - if target:is_phony() then - return + if not target:is_phony() then + local scripts = + { + binary = _package_binary + , static = _package_library + , shared = _package_library + } + local kind = target:kind() + assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) + scripts[kind](target) end end -- cgit v1.3.1 From 706a4d831c9a6346258f9b89533abb88a91bafbf Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 00:58:01 +0800 Subject: improve to generate local package --- xmake/actions/package/local/main.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index 4be7769eb..e479ebe6a 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -90,9 +90,27 @@ function _package_library(target) if file then file:print("package(\"%s\")", packagename) file:print(" set_description(\"%s\")", "The " .. packagename .. " package.") + if target:is_shared() and target:is_plat("windows", "mingw") then + file:print(" on_load(function (package)") + file:print(" package:addenv(\"PATH\", path.join(os.scriptdir(), \"bin\", package:plat(), package:arch(), package:mode()))") + file:print(" end)") + end file:print(" on_fetch(function (package, opt)") file:print(" local result = {}") + if target:is_shared() and target:is_plat("windows", "mingw") then + file:print(" local librarydir = path.join(os.scriptdir(), \"bin\", package:plat(), package:arch(), package:mode())") + else + file:print(" local librarydir = path.join(os.scriptdir(), \"lib\", package:plat(), package:arch(), package:mode())") + end + if target:is_shared() then + file:print(" result.shared = true") + else + file:print(" result.static = true") + end file:print(" result.links = \"%s\"", target:linkname()) + file:print(" result.linkdirs = librarydir") + file:print(" result.libfiles = os.files(path.join(librarydir, \"*\"))") + file:print(" result.includedirs = path.join(os.scriptdir(), \"include\")") if target:version() then file:print(" result.version = \"%s\"", (target:version())) end -- cgit v1.3.1 From 36e84d2eefe73bae41ac21f39b5e0138bff8649f Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 22:08:27 +0800 Subject: improve local package --- xmake/actions/package/local/main.lua | 99 ++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index e479ebe6a..9e6663db0 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -29,18 +29,35 @@ import("core.project.project") function _package_binary(target) -- get the output directory - local outputdir = option.get("outputdir") or config.buildir() + local outputdir = option.get("outputdir") or config.buildir() + local packagename = target:name():lower() + local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) + local binarydir = path.join(packagedir, "bin", target:plat(), target:arch(), config.mode()) + + -- copy the binary file to the output directory + local targetfile = target:targetfile() + os.mkdir(binarydir) + os.vcp(targetfile, binarydir) + os.trycp(target:symbolfile(), binarydir) -- generate xmake.lua - local packagename = target:name():lower() - local file = io.open(path.join(outputdir, "packages", packagename:sub(1, 1), packagename, "xmake.lua"), "w") + local file = io.open(path.join(packagedir, "xmake.lua"), "w") if file then - file:print("package(\"%s\")", packagename) - file:print(" set_description(\"%s\")", "The " .. packagename .. " package.") - file:print(" set_kind(\"binary\")") - file:print(" on_fetch(function (package, opt)") - file:print(" return {program = \"%s\"}", target:targetfile()) - file:print(" end)") + file:print([[package("%s") + set_kind("binary") + set_description("%s") + on_load("windows", "mingw", function (package) + if package:config("shared") then + package:addenv("PATH", path.join(os.scriptdir(), "bin", package:plat(), package:arch(), package:mode())) + end + end) + on_fetch(function (package) + local result = {} + result.program = path.join(os.scriptdir(), "bin", package:plat(), package:arch(), package:mode(), "%s") + return result + end)]], packagename, + "The " .. packagename .. " package", + path.filename(targetfile)) file:close() end end @@ -52,24 +69,18 @@ function _package_library(target) local outputdir = option.get("outputdir") or config.buildir() local packagename = target:name():lower() local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) - local binarydir = path.join(packagedir, "bin", target:plat(), target:arch(), config.mode()) local librarydir = path.join(packagedir, "lib", target:plat(), target:arch(), config.mode()) -- copy the library file to the output directory local targetfile = target:targetfile() + os.mkdir(librarydir) + os.vcp(targetfile, librarydir) + os.trycp(target:symbolfile(), librarydir) if target:is_shared() and target:is_plat("windows", "mingw") then - os.mkdir(binarydir) - os.vcp(targetfile, binarydir) - os.trycp(target:symbolfile(), binarydir) local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") if os.isfile(targetfile_lib) then - os.mkdir(librarydir) os.vcp(targetfile_lib, librarydir) end - else - os.mkdir(librarydir) - os.vcp(targetfile, librarydir) - os.trycp(target:symbolfile(), librarydir) end -- copy headers @@ -88,34 +99,32 @@ function _package_library(target) -- generate xmake.lua local file = io.open(path.join(packagedir, "xmake.lua"), "w") if file then - file:print("package(\"%s\")", packagename) - file:print(" set_description(\"%s\")", "The " .. packagename .. " package.") - if target:is_shared() and target:is_plat("windows", "mingw") then - file:print(" on_load(function (package)") - file:print(" package:addenv(\"PATH\", path.join(os.scriptdir(), \"bin\", package:plat(), package:arch(), package:mode()))") - file:print(" end)") - end - file:print(" on_fetch(function (package, opt)") - file:print(" local result = {}") - if target:is_shared() and target:is_plat("windows", "mingw") then - file:print(" local librarydir = path.join(os.scriptdir(), \"bin\", package:plat(), package:arch(), package:mode())") - else - file:print(" local librarydir = path.join(os.scriptdir(), \"lib\", package:plat(), package:arch(), package:mode())") - end - if target:is_shared() then - file:print(" result.shared = true") - else - file:print(" result.static = true") - end - file:print(" result.links = \"%s\"", target:linkname()) - file:print(" result.linkdirs = librarydir") - file:print(" result.libfiles = os.files(path.join(librarydir, \"*\"))") - file:print(" result.includedirs = path.join(os.scriptdir(), \"include\")") - if target:version() then - file:print(" result.version = \"%s\"", (target:version())) + file:print([[package("%s") + set_description("%s") + on_load(function (package) + if package:config("shared") then + local librarydir = path.join(os.scriptdir(), "lib", package:plat(), package:arch(), package:mode()) + if package:is_plat("windows", "mingw") then + package:addenv("PATH", librarydir) + elseif package:is_plat("macosx") then + package:addenv("DYLD_LIBRARY_PATH", librarydir) + else + package:addenv("LD_LIBRARY_PATH", librarydir) + end end - file:print(" return result") - file:print(" end)") + end) + on_fetch(function (package) + local result = {} + local librarydir = path.join(os.scriptdir(), "lib", package:plat(), package:arch(), package:mode()) + result.links = "%s" + result.linkdirs = librarydir + result.libfiles = path.join(librarydir, "%s") + result.includedirs = path.join(os.scriptdir(), "include") + return result + end)]], packagename, + "The " .. packagename .. " package", + target:linkname(), + path.filename(targetfile)) file:close() end end -- cgit v1.3.1 From 4223c60a70bf0220f15c18fe3ec4a5dda24b317a Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 22:40:12 +0800 Subject: improve localpackage --- xmake/actions/package/local/main.lua | 43 ++++++++++++++---------------------- xmake/core/package/package.lua | 19 +++++++++++----- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index 9e6663db0..d4b776a00 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -32,7 +32,7 @@ function _package_binary(target) local outputdir = option.get("outputdir") or config.buildir() local packagename = target:name():lower() local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) - local binarydir = path.join(packagedir, "bin", target:plat(), target:arch(), config.mode()) + local binarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "bin") -- copy the binary file to the output directory local targetfile = target:targetfile() @@ -46,15 +46,11 @@ function _package_binary(target) file:print([[package("%s") set_kind("binary") set_description("%s") - on_load("windows", "mingw", function (package) - if package:config("shared") then - package:addenv("PATH", path.join(os.scriptdir(), "bin", package:plat(), package:arch(), package:mode())) - end + on_load(function (package) + package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode())) end) on_fetch(function (package) - local result = {} - result.program = path.join(os.scriptdir(), "bin", package:plat(), package:arch(), package:mode(), "%s") - return result + return {program = path.join(package:installdir("bin"), "%s")} end)]], packagename, "The " .. packagename .. " package", path.filename(targetfile)) @@ -69,18 +65,24 @@ function _package_library(target) local outputdir = option.get("outputdir") or config.buildir() local packagename = target:name():lower() local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) - local librarydir = path.join(packagedir, "lib", target:plat(), target:arch(), config.mode()) + local binarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "bin") + local librarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "lib") -- copy the library file to the output directory local targetfile = target:targetfile() - os.mkdir(librarydir) - os.vcp(targetfile, librarydir) - os.trycp(target:symbolfile(), librarydir) if target:is_shared() and target:is_plat("windows", "mingw") then + os.mkdir(binarydir) + os.vcp(targetfile, binarydir) + os.trycp(target:symbolfile(), binarydir) local targetfile_lib = path.join(path.directory(targetfile), path.basename(targetfile) .. ".lib") if os.isfile(targetfile_lib) then + os.mkdir(librarydir) os.vcp(targetfile_lib, librarydir) end + else + os.mkdir(librarydir) + os.vcp(targetfile, librarydir) + os.trycp(target:symbolfile(), librarydir) end -- copy headers @@ -102,24 +104,13 @@ function _package_library(target) file:print([[package("%s") set_description("%s") on_load(function (package) - if package:config("shared") then - local librarydir = path.join(os.scriptdir(), "lib", package:plat(), package:arch(), package:mode()) - if package:is_plat("windows", "mingw") then - package:addenv("PATH", librarydir) - elseif package:is_plat("macosx") then - package:addenv("DYLD_LIBRARY_PATH", librarydir) - else - package:addenv("LD_LIBRARY_PATH", librarydir) - end - end + package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode())) end) on_fetch(function (package) local result = {} - local librarydir = path.join(os.scriptdir(), "lib", package:plat(), package:arch(), package:mode()) result.links = "%s" - result.linkdirs = librarydir - result.libfiles = path.join(librarydir, "%s") - result.includedirs = path.join(os.scriptdir(), "include") + result.linkdirs = package:installdir("lib") + result.includedirs = package:installdir("include") return result end)]], packagename, "The " .. packagename .. " package", diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index c53a43d38..72d8aa5f5 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -475,12 +475,20 @@ end -- get the installed directory of this package function _instance:installdir(...) - local name = self:name():lower():gsub("::", "_") - local dir = path.join(package.installdir(), name:sub(1, 1):lower(), name) - if self:version_str() then - dir = path.join(dir, self:version_str()) + local installdir = self._INSTALLDIR + if not installdir then + installdir = self:get("installdir") + if not installdir then + local name = self:name():lower():gsub("::", "_") + installdir = path.join(package.installdir(), name:sub(1, 1):lower(), name) + if self:version_str() then + installdir = path.join(installdir, self:version_str()) + end + installdir = path.join(installdir, self:buildhash()) + end + self._INSTALLDIR = installdir end - dir = path.join(dir, self:buildhash(), ...) + local dir = path.join(installdir, ...) if not os.isdir(dir) then os.mkdir(dir) end @@ -1646,6 +1654,7 @@ function package.apis() , "package.set_homepage" , "package.set_description" , "package.set_parallelize" + , "package.set_installdir" -- package.add_xxx , "package.add_deps" , "package.add_urls" -- cgit v1.3.1 From eee121636be554cdeef8907bd0d2fac6a23304a6 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 22:48:05 +0800 Subject: add localpkg test --- tests/actions/package/localpkg/bar/.gitignore | 8 ++++++++ tests/actions/package/localpkg/bar/src/main.cpp | 10 ++++++++++ tests/actions/package/localpkg/bar/xmake.lua | 11 +++++++++++ tests/actions/package/localpkg/libfoo/.gitignore | 8 ++++++++ tests/actions/package/localpkg/libfoo/src/interface.cpp | 6 ++++++ tests/actions/package/localpkg/libfoo/src/interface.h | 16 ++++++++++++++++ tests/actions/package/localpkg/libfoo/xmake.lua | 8 ++++++++ tests/actions/package/localpkg/test.lua | 8 ++++++++ xmake/actions/package/local/main.lua | 3 ++- xmake/modules/net/proxy.lua | 8 +++++--- 10 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 tests/actions/package/localpkg/bar/.gitignore create mode 100644 tests/actions/package/localpkg/bar/src/main.cpp create mode 100644 tests/actions/package/localpkg/bar/xmake.lua create mode 100644 tests/actions/package/localpkg/libfoo/.gitignore create mode 100644 tests/actions/package/localpkg/libfoo/src/interface.cpp create mode 100644 tests/actions/package/localpkg/libfoo/src/interface.h create mode 100644 tests/actions/package/localpkg/libfoo/xmake.lua create mode 100644 tests/actions/package/localpkg/test.lua diff --git a/tests/actions/package/localpkg/bar/.gitignore b/tests/actions/package/localpkg/bar/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/actions/package/localpkg/bar/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/actions/package/localpkg/bar/src/main.cpp b/tests/actions/package/localpkg/bar/src/main.cpp new file mode 100644 index 000000000..1bee1b2ad --- /dev/null +++ b/tests/actions/package/localpkg/bar/src/main.cpp @@ -0,0 +1,10 @@ +#include "interface.h" +#include + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "add(1, 2) = " << add(1, 2) << endl; + return 0; +} diff --git a/tests/actions/package/localpkg/bar/xmake.lua b/tests/actions/package/localpkg/bar/xmake.lua new file mode 100644 index 000000000..9024b2065 --- /dev/null +++ b/tests/actions/package/localpkg/bar/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.debug", "mode.release") + +add_repositories("local-repo build") +add_requires("foo") + +target("bar") + set_kind("binary") + add_files("src/*.cpp") + add_packages("foo") + + diff --git a/tests/actions/package/localpkg/libfoo/.gitignore b/tests/actions/package/localpkg/libfoo/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/actions/package/localpkg/libfoo/src/interface.cpp b/tests/actions/package/localpkg/libfoo/src/interface.cpp new file mode 100644 index 000000000..598d07560 --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/src/interface.cpp @@ -0,0 +1,6 @@ +#include "interface.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/tests/actions/package/localpkg/libfoo/src/interface.h b/tests/actions/package/localpkg/libfoo/src/interface.h new file mode 100644 index 000000000..62a39427c --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/src/interface.h @@ -0,0 +1,16 @@ +#ifdef __cplusplus +extern "C" { +#endif + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/actions/package/localpkg/libfoo/xmake.lua b/tests/actions/package/localpkg/libfoo/xmake.lua new file mode 100644 index 000000000..01419c241 --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + set_kind("static") + add_files("src/interface.cpp") + add_headerfiles("src/*.h") + + diff --git a/tests/actions/package/localpkg/test.lua b/tests/actions/package/localpkg/test.lua new file mode 100644 index 000000000..ae685d928 --- /dev/null +++ b/tests/actions/package/localpkg/test.lua @@ -0,0 +1,8 @@ +function main(t) + os.cd("libfoo") + os.exec("xmake package -vD -o ../bar/build") + os.cd("../bar") + os.exec("xmake f -c -vD") + os.exec("xmake -vD") + os.exec("xmake run") +end diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index d4b776a00..c2b3c556c 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -67,6 +67,7 @@ function _package_library(target) local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) local binarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "bin") local librarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "lib") + local headerdir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "include") -- copy the library file to the output directory local targetfile = target:targetfile() @@ -86,7 +87,7 @@ function _package_library(target) end -- copy headers - local srcheaders, dstheaders = target:headerfiles(path.join(packagedir, "include")) + local srcheaders, dstheaders = target:headerfiles(headerdir) if srcheaders and dstheaders then local i = 1 for _, srcheader in ipairs(srcheaders) do diff --git a/xmake/modules/net/proxy.lua b/xmake/modules/net/proxy.lua index 8259a07c9..6aac4af4c 100644 --- a/xmake/modules/net/proxy.lua +++ b/xmake/modules/net/proxy.lua @@ -108,7 +108,7 @@ function config(url) -- enable proxy for the given url and configuration pattern if url then - -- get proxy from the given hosts pattern + -- filter proxy host from the given hosts pattern local host = url:match("://(.-)/") or url:match("@(.-):") local proxy_hosts = _proxy_hosts() if host and proxy_hosts then @@ -121,11 +121,13 @@ function config(url) end end - -- get proxy from the pac file + -- filter proxy host from the pac file local proxy_pac = _proxy_pac() - if proxy_pac and _is_callable(proxy_pac) and proxy_pac(url, host) then + if proxy_pac and host and _is_callable(proxy_pac) and proxy_pac(url, host) then return global.get("proxy") end + + -- use global proxy if not proxy_pac and not proxy_hosts then return global.get("proxy") end -- cgit v1.3.1 From 16919177c72aa5934113d37932e0b60c8d4a52df Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 22:50:57 +0800 Subject: detect unicode target name --- xmake/actions/package/local/main.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index c2b3c556c..aa834eb79 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -24,6 +24,7 @@ import("core.base.task") import("core.project.rule") import("core.project.config") import("core.project.project") +import("lib.luajit.bit") -- package binary function _package_binary(target) @@ -31,6 +32,10 @@ function _package_binary(target) -- get the output directory local outputdir = option.get("outputdir") or config.buildir() local packagename = target:name():lower() + if bit.band(packagename:byte(2), 0xc0) == 0x80 then + wprint("package(%s): cannot generate package, becauese it contains unicode characters!", packagename) + return + end local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) local binarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "bin") @@ -64,6 +69,10 @@ function _package_library(target) -- get the output directory local outputdir = option.get("outputdir") or config.buildir() local packagename = target:name():lower() + if bit.band(packagename:byte(2), 0xc0) == 0x80 then + wprint("package(%s): cannot generate package, becauese it contains unicode characters!", packagename) + return + end local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) local binarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "bin") local librarydir = path.join(packagedir, target:plat(), target:arch(), config.mode(), "lib") -- cgit v1.3.1 From 8dda67ba52ed67cc3e6897849658872c2ef4ddcc Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 22:54:27 +0800 Subject: add deps for localpackages --- tests/actions/package/localpkg/bar/src/main.cpp | 4 ++-- tests/actions/package/localpkg/libfoo/src/add.cpp | 6 ++++++ tests/actions/package/localpkg/libfoo/src/add.h | 16 ++++++++++++++++ tests/actions/package/localpkg/libfoo/src/foo.cpp | 8 ++++++++ tests/actions/package/localpkg/libfoo/src/foo.h | 16 ++++++++++++++++ tests/actions/package/localpkg/libfoo/src/interface.cpp | 6 ------ tests/actions/package/localpkg/libfoo/src/interface.h | 16 ---------------- tests/actions/package/localpkg/libfoo/src/sub.cpp | 6 ++++++ tests/actions/package/localpkg/libfoo/src/sub.h | 16 ++++++++++++++++ tests/actions/package/localpkg/libfoo/xmake.lua | 16 +++++++++++++--- xmake/actions/package/local/main.lua | 6 ++++++ 11 files changed, 89 insertions(+), 27 deletions(-) create mode 100644 tests/actions/package/localpkg/libfoo/src/add.cpp create mode 100644 tests/actions/package/localpkg/libfoo/src/add.h create mode 100644 tests/actions/package/localpkg/libfoo/src/foo.cpp create mode 100644 tests/actions/package/localpkg/libfoo/src/foo.h delete mode 100644 tests/actions/package/localpkg/libfoo/src/interface.cpp delete mode 100644 tests/actions/package/localpkg/libfoo/src/interface.h create mode 100644 tests/actions/package/localpkg/libfoo/src/sub.cpp create mode 100644 tests/actions/package/localpkg/libfoo/src/sub.h diff --git a/tests/actions/package/localpkg/bar/src/main.cpp b/tests/actions/package/localpkg/bar/src/main.cpp index 1bee1b2ad..0102fba75 100644 --- a/tests/actions/package/localpkg/bar/src/main.cpp +++ b/tests/actions/package/localpkg/bar/src/main.cpp @@ -1,10 +1,10 @@ -#include "interface.h" +#include "foo.h" #include using namespace std; int main(int argc, char** argv) { - cout << "add(1, 2) = " << add(1, 2) << endl; + cout << "foo(1, 2) = " << foo(1, 2) << endl; return 0; } diff --git a/tests/actions/package/localpkg/libfoo/src/add.cpp b/tests/actions/package/localpkg/libfoo/src/add.cpp new file mode 100644 index 000000000..e73473e0f --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/src/add.cpp @@ -0,0 +1,6 @@ +#include "add.h" + +int add(int a, int b) +{ + return a + b; +} diff --git a/tests/actions/package/localpkg/libfoo/src/add.h b/tests/actions/package/localpkg/libfoo/src/add.h new file mode 100644 index 000000000..62a39427c --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/src/add.h @@ -0,0 +1,16 @@ +#ifdef __cplusplus +extern "C" { +#endif + +/*! calculate add(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/actions/package/localpkg/libfoo/src/foo.cpp b/tests/actions/package/localpkg/libfoo/src/foo.cpp new file mode 100644 index 000000000..b13e8e761 --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/src/foo.cpp @@ -0,0 +1,8 @@ +#include "add.h" +#include "sub.h" +#include "foo.h" + +int foo(int a, int b) +{ + return add(sub(a, b), sub(b, a)); +} diff --git a/tests/actions/package/localpkg/libfoo/src/foo.h b/tests/actions/package/localpkg/libfoo/src/foo.h new file mode 100644 index 000000000..d53be3150 --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/src/foo.h @@ -0,0 +1,16 @@ +#ifdef __cplusplus +extern "C" { +#endif + +/*! calculate foo(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int foo(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/actions/package/localpkg/libfoo/src/interface.cpp b/tests/actions/package/localpkg/libfoo/src/interface.cpp deleted file mode 100644 index 598d07560..000000000 --- a/tests/actions/package/localpkg/libfoo/src/interface.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "interface.h" - -int add(int a, int b) -{ - return a + b; -} diff --git a/tests/actions/package/localpkg/libfoo/src/interface.h b/tests/actions/package/localpkg/libfoo/src/interface.h deleted file mode 100644 index 62a39427c..000000000 --- a/tests/actions/package/localpkg/libfoo/src/interface.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -/*! calculate add(a, b) - * - * @param a the first argument - * @param b the second argument - * - * @return the result - */ -int add(int a, int b); - -#ifdef __cplusplus -} -#endif diff --git a/tests/actions/package/localpkg/libfoo/src/sub.cpp b/tests/actions/package/localpkg/libfoo/src/sub.cpp new file mode 100644 index 000000000..a65acd40f --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/src/sub.cpp @@ -0,0 +1,6 @@ +#include "sub.h" + +int sub(int a, int b) +{ + return a - b; +} diff --git a/tests/actions/package/localpkg/libfoo/src/sub.h b/tests/actions/package/localpkg/libfoo/src/sub.h new file mode 100644 index 000000000..1bda92bc5 --- /dev/null +++ b/tests/actions/package/localpkg/libfoo/src/sub.h @@ -0,0 +1,16 @@ +#ifdef __cplusplus +extern "C" { +#endif + +/*! calculate sub(a, b) + * + * @param a the first argument + * @param b the second argument + * + * @return the result + */ +int sub(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/actions/package/localpkg/libfoo/xmake.lua b/tests/actions/package/localpkg/libfoo/xmake.lua index 01419c241..1b1dd5a41 100644 --- a/tests/actions/package/localpkg/libfoo/xmake.lua +++ b/tests/actions/package/localpkg/libfoo/xmake.lua @@ -1,8 +1,18 @@ add_rules("mode.debug", "mode.release") -target("foo") +target("sub") + set_kind("static") + add_files("src/sub.cpp") + add_headerfiles("src/sub.h") + +target("add") set_kind("static") - add_files("src/interface.cpp") - add_headerfiles("src/*.h") + add_files("src/add.cpp") + add_headerfiles("src/add.h") +target("foo") + add_deps("add", "sub") + set_kind("static") + add_files("src/foo.cpp") + add_headerfiles("src/foo.h") diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index aa834eb79..b4114cb12 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -111,8 +111,13 @@ function _package_library(target) -- generate xmake.lua local file = io.open(path.join(packagedir, "xmake.lua"), "w") if file then + local deps = {} + for _, dep in ipairs(target:orderdeps()) do + table.insert(deps, dep:name()) + end file:print([[package("%s") set_description("%s") + %s on_load(function (package) package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode())) end) @@ -124,6 +129,7 @@ function _package_library(target) return result end)]], packagename, "The " .. packagename .. " package", + #deps > 0 and ("add_deps(\"" .. table.concat(deps, "\", \"") .. "\")") or "", target:linkname(), path.filename(targetfile)) file:close() -- cgit v1.3.1 From d40c47c3e8c2272af5f2a60b6d90a611d66035a7 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 22:55:06 +0800 Subject: improve test --- tests/actions/package/localpkg/test.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/actions/package/localpkg/test.lua b/tests/actions/package/localpkg/test.lua index ae685d928..9f581ddab 100644 --- a/tests/actions/package/localpkg/test.lua +++ b/tests/actions/package/localpkg/test.lua @@ -1,8 +1,10 @@ function main(t) + os.exec("xmake g --network=private") os.cd("libfoo") os.exec("xmake package -vD -o ../bar/build") os.cd("../bar") os.exec("xmake f -c -vD") os.exec("xmake -vD") os.exec("xmake run") + os.exec("xmake g --network=public") end -- cgit v1.3.1 From 03236a125416b8623f582144616069e5a5b0c4bb Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 22:55:23 +0800 Subject: add deps for local binary package --- xmake/actions/package/local/main.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index b4114cb12..7729d5b4a 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -48,9 +48,14 @@ function _package_binary(target) -- generate xmake.lua local file = io.open(path.join(packagedir, "xmake.lua"), "w") if file then + local deps = {} + for _, dep in ipairs(target:orderdeps()) do + table.insert(deps, dep:name()) + end file:print([[package("%s") set_kind("binary") set_description("%s") + %s on_load(function (package) package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode())) end) @@ -58,6 +63,7 @@ function _package_binary(target) return {program = path.join(package:installdir("bin"), "%s")} end)]], packagename, "The " .. packagename .. " package", + #deps > 0 and ("add_deps(\"" .. table.concat(deps, "\", \"") .. "\")") or "", path.filename(targetfile)) file:close() end -- cgit v1.3.1 From 4bbd7833ea104e2f754c608e2bad41659d4952fc Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 23:06:56 +0800 Subject: generate remote package --- xmake/actions/package/local/main.lua | 6 ++ xmake/actions/package/remote/main.lua | 127 +++++++++++++++------------------- 2 files changed, 63 insertions(+), 70 deletions(-) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index 7729d5b4a..aa6654fc1 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -67,6 +67,9 @@ function _package_binary(target) path.filename(targetfile)) file:close() end + + -- show tips + print("package(%s): %s generated", packagename, packagedir) end -- package library @@ -140,6 +143,9 @@ function _package_library(target) path.filename(targetfile)) file:close() end + + -- show tips + print("package(%s): %s generated", packagename, packagedir) end -- do package target diff --git a/xmake/actions/package/remote/main.lua b/xmake/actions/package/remote/main.lua index 8118bff7a..917d89226 100644 --- a/xmake/actions/package/remote/main.lua +++ b/xmake/actions/package/remote/main.lua @@ -24,79 +24,70 @@ import("core.base.task") import("core.project.rule") import("core.project.config") import("core.project.project") +import("lib.luajit.bit") --- do package target -function _do_package_target(target) - if target:is_phony() then - return - end -end +-- package remote +function _package_remote(target) --- package target -function _on_package_target(target) - local done = false - for _, r in ipairs(target:orderules()) do - local on_package = r:script("package") - if on_package then - on_package(target) - done = true - end - end - if done then return end - _do_package_target(target) -end - --- package the given target -function _package_target(target) - - -- has been disabled? - if not target:is_enabled() then + -- get the output directory + local outputdir = option.get("outputdir") or config.buildir() + local packagename = target:name():lower() + if bit.band(packagename:byte(2), 0xc0) == 0x80 then + wprint("package(%s): cannot generate package, becauese it contains unicode characters!", packagename) return end - - -- enter project directory - local oldir = os.cd(project.directory()) - - -- enter the environments of the target packages - local oldenvs = os.addenvs(target:pkgenvs()) - - -- the target scripts - local scripts = - { - target:script("package_before") - , function (target) - for _, r in ipairs(target:orderules()) do - local before_package = r:script("package_before") - if before_package then - before_package(target) - end - end - end - , target:script("package", _on_package_target) - , function (target) - for _, r in ipairs(target:orderules()) do - local after_package = r:script("package_after") - if after_package then - after_package(target) - end - end + local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) + + -- generate xmake.lua + local file = io.open(path.join(packagedir, "xmake.lua"), "w") + if file then + local deps = {} + for _, dep in ipairs(target:orderdeps()) do + table.insert(deps, dep:name()) end - , target:script("package_after") - } - - -- package the target scripts - for i = 1, 5 do - local script = scripts[i] - if script ~= nil then - script(target) + file:print([[package("%s") + %s + set_description("%s") + + add_urls("https://github.com/myrepo/foo.git") + add_versions("%s", "") + %s + on_install(function (package) + local configs = {} + if package:config("shared") then + configs.kind = "shared" end + import("package.tools.xmake").install(package, configs) + end) + + on_test(function (package) + -- TODO check includes and interfaces + -- assert(package:has_cfuncs("foo", {includes = "foo.h"}) + end)]], packagename, + target:is_binary() and "set_kind(\"binary\")" or "", + "The " .. packagename .. " package", + target:version() and (target:version()) or "1.0", + #deps > 0 and ("add_deps(\"" .. table.concat(deps, "\", \"") .. "\")") or "") + file:close() end - -- leave the environments of the target packages - os.setenvs(oldenvs) + -- show tips + print("package(%s): %s generated", packagename, packagedir) +end - -- leave project directory - os.cd(oldir) +-- package target +function _package_target(target) + if not target:is_phony() then + local scripts = + { + binary = _package_remote + , static = _package_remote + , shared = _package_remote + } + local kind = target:kind() + assert(scripts[kind], "this target(%s) with kind(%s) can not be packaged!", target:name(), kind) + scripts[kind](target) + end end -- package the given targets @@ -112,13 +103,8 @@ function main() -- lock the whole project project.lock() - -- get the target name - local targetname = option.get("target") - - -- build it first - task.run("build", {target = targetname, all = option.get("all")}) - -- package the given target? + local targetname = option.get("target") if targetname then local target = project.target(targetname) _package_targets(target:orderdeps()) @@ -135,3 +121,4 @@ function main() -- unlock the whole project project.unlock() end + -- cgit v1.3.1 From b3027461160d7e0462b8cfff417fa442444f0420 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 23:07:42 +0800 Subject: improve test --- tests/actions/package/localpkg/test.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/actions/package/localpkg/test.lua b/tests/actions/package/localpkg/test.lua index 9f581ddab..1256b1fa2 100644 --- a/tests/actions/package/localpkg/test.lua +++ b/tests/actions/package/localpkg/test.lua @@ -1,10 +1,10 @@ function main(t) - os.exec("xmake g --network=private") - os.cd("libfoo") - os.exec("xmake package -vD -o ../bar/build") - os.cd("../bar") - os.exec("xmake f -c -vD") - os.exec("xmake -vD") - os.exec("xmake run") - os.exec("xmake g --network=public") + if (os.subarch():startswith("x") or os.subarch() == "i386") and not is_host("bsd") then + os.cd("libfoo") + os.exec("xmake package -vD -o ../bar/build") + os.cd("../bar") + os.exec("xmake f -c -vD") + os.exec("xmake -vD") + os.exec("xmake run") + end end -- cgit v1.3.1 From 50a79cc6fcece9b826d60ccd54998176df5db43e Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 23:10:41 +0800 Subject: improve package content --- tests/actions/package/localpkg/libfoo/xmake.lua | 1 + xmake/actions/package/local/main.lua | 38 ++++++++++++++++--------- xmake/actions/package/remote/main.lua | 25 +++++++++------- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/tests/actions/package/localpkg/libfoo/xmake.lua b/tests/actions/package/localpkg/libfoo/xmake.lua index 1b1dd5a41..a6e5c7cb0 100644 --- a/tests/actions/package/localpkg/libfoo/xmake.lua +++ b/tests/actions/package/localpkg/libfoo/xmake.lua @@ -1,4 +1,5 @@ add_rules("mode.debug", "mode.release") +set_license("Apache-2.0") target("sub") set_kind("static") diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index aa6654fc1..33aed24b7 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -52,18 +52,23 @@ function _package_binary(target) for _, dep in ipairs(target:orderdeps()) do table.insert(deps, dep:name()) end - file:print([[package("%s") - set_kind("binary") - set_description("%s") - %s + file:print("package(\"%s\")", packagename) + file:print(" set_description(\"%s\")", "The " .. packagename .. " package") + if target:license() then + file:print(" set_license(\"%s\")", target:license()) + end + if #deps > 0 then + file:print(" set_deps(\"%s\")", table.concat(deps, "\", \"")) + end + file:print("") + file:print([[ on_load(function (package) package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode())) end) + on_fetch(function (package) return {program = path.join(package:installdir("bin"), "%s")} - end)]], packagename, - "The " .. packagename .. " package", - #deps > 0 and ("add_deps(\"" .. table.concat(deps, "\", \"") .. "\")") or "", + end)]], #deps > 0 and ("add_deps(\"" .. table.concat(deps, "\", \"") .. "\")") or "", path.filename(targetfile)) file:close() end @@ -124,22 +129,27 @@ function _package_library(target) for _, dep in ipairs(target:orderdeps()) do table.insert(deps, dep:name()) end - file:print([[package("%s") - set_description("%s") - %s + file:print("package(\"%s\")", packagename) + file:print(" set_description(\"%s\")", "The " .. packagename .. " package") + if target:license() then + file:print(" set_license(\"%s\")", target:license()) + end + if #deps > 0 then + file:print(" set_deps(\"%s\")", table.concat(deps, "\", \"")) + end + file:print("") + file:print([[ on_load(function (package) package:set("installdir", path.join(os.scriptdir(), package:plat(), package:arch(), package:mode())) end) + on_fetch(function (package) local result = {} result.links = "%s" result.linkdirs = package:installdir("lib") result.includedirs = package:installdir("include") return result - end)]], packagename, - "The " .. packagename .. " package", - #deps > 0 and ("add_deps(\"" .. table.concat(deps, "\", \"") .. "\")") or "", - target:linkname(), + end)]], target:linkname(), path.filename(targetfile)) file:close() end diff --git a/xmake/actions/package/remote/main.lua b/xmake/actions/package/remote/main.lua index 917d89226..3d46d10ba 100644 --- a/xmake/actions/package/remote/main.lua +++ b/xmake/actions/package/remote/main.lua @@ -45,13 +45,22 @@ function _package_remote(target) for _, dep in ipairs(target:orderdeps()) do table.insert(deps, dep:name()) end - file:print([[package("%s") - %s - set_description("%s") - + file:print("package(\"%s\")", packagename) + if target:is_binary() then + file:print(" set_kind(\"binary\")") + end + file:print(" set_description(\"%s\")", "The " .. packagename .. " package") + if target:license() then + file:print(" set_license(\"%s\")", target:license()) + end + if #deps > 0 then + file:print(" set_deps(\"%s\")", table.concat(deps, "\", \"")) + end + file:print("") + file:print([[ add_urls("https://github.com/myrepo/foo.git") add_versions("%s", "") - %s + on_install(function (package) local configs = {} if package:config("shared") then @@ -63,11 +72,7 @@ function _package_remote(target) on_test(function (package) -- TODO check includes and interfaces -- assert(package:has_cfuncs("foo", {includes = "foo.h"}) - end)]], packagename, - target:is_binary() and "set_kind(\"binary\")" or "", - "The " .. packagename .. " package", - target:version() and (target:version()) or "1.0", - #deps > 0 and ("add_deps(\"" .. table.concat(deps, "\", \"") .. "\")") or "") + end)]], target:version() and (target:version()) or "1.0") file:close() end -- cgit v1.3.1 From 76a7ac04e4a1a07347fd1fb6bc43374e2ff88dc6 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 23:16:24 +0800 Subject: add more package options --- xmake/actions/package/local/main.lua | 14 ++++++++++++-- xmake/actions/package/remote/main.lua | 18 +++++++++++++----- xmake/actions/package/xmake.lua | 6 ++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index 33aed24b7..28d235126 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -53,7 +53,12 @@ function _package_binary(target) table.insert(deps, dep:name()) end file:print("package(\"%s\")", packagename) - file:print(" set_description(\"%s\")", "The " .. packagename .. " package") + local homepage = option.get("homepage") + if homepage then + file:print(" set_homepage(\"%s\")", homepage) + end + local description = option.get("description") or ("The " .. packagename .. " package") + file:print(" set_description(\"%s\")", description) if target:license() then file:print(" set_license(\"%s\")", target:license()) end @@ -130,7 +135,12 @@ function _package_library(target) table.insert(deps, dep:name()) end file:print("package(\"%s\")", packagename) - file:print(" set_description(\"%s\")", "The " .. packagename .. " package") + local homepage = option.get("homepage") + if homepage then + file:print(" set_homepage(\"%s\")", homepage) + end + local description = option.get("description") or ("The " .. packagename .. " package") + file:print(" set_description(\"%s\")", description) if target:license() then file:print(" set_license(\"%s\")", target:license()) end diff --git a/xmake/actions/package/remote/main.lua b/xmake/actions/package/remote/main.lua index 3d46d10ba..6b108e60e 100644 --- a/xmake/actions/package/remote/main.lua +++ b/xmake/actions/package/remote/main.lua @@ -49,7 +49,12 @@ function _package_remote(target) if target:is_binary() then file:print(" set_kind(\"binary\")") end - file:print(" set_description(\"%s\")", "The " .. packagename .. " package") + local homepage = option.get("homepage") + if homepage then + file:print(" set_homepage(\"%s\")", homepage) + end + local description = option.get("description") or ("The " .. packagename .. " package") + file:print(" set_description(\"%s\")", description) if target:license() then file:print(" set_license(\"%s\")", target:license()) end @@ -57,10 +62,13 @@ function _package_remote(target) file:print(" set_deps(\"%s\")", table.concat(deps, "\", \"")) end file:print("") + local url = option.get("url") or "https://github.com/myrepo/foo.git" + local version = option.get("version") or target:version() and (target:version()) or "1.0" + local shasum = option.get("shasum") or "" + file:print(" add_urls(\"%s\")", url) + file:print(" add_versions(\"%s\", \"%s\")", version, shasum) + file:print("") file:print([[ - add_urls("https://github.com/myrepo/foo.git") - add_versions("%s", "") - on_install(function (package) local configs = {} if package:config("shared") then @@ -72,7 +80,7 @@ function _package_remote(target) on_test(function (package) -- TODO check includes and interfaces -- assert(package:has_cfuncs("foo", {includes = "foo.h"}) - end)]], target:version() and (target:version()) or "1.0") + end)]]) file:close() end diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua index 0a757a1eb..dd7b1846f 100644 --- a/xmake/actions/package/xmake.lua +++ b/xmake/actions/package/xmake.lua @@ -28,8 +28,14 @@ task("package") options = { {'o', "outputdir", "kv", nil, "Set the output directory."}, {'a', "all", "k", nil, "Package all targets."}, + {}, {'f', "format", "kv", "local", "Set the package format.", values = {"oldpkg", "local", "remote"}}, + {nil, "homepage", "kv", nil, "Set the homepage of package."}, + {nil, "description","kv", nil, "Set the description of package."}, + {nil, "url", "kv", nil, "Set the url of remote package."}, + {nil, "version", "kv", nil, "Set the version of remove package."}, + {nil, "shasum", "kv", nil, "Set the sha256 or commit of remote package."}, {}, {nil, "target", "v", nil, "The target name. It will package all default targets if this parameter is not specified.", values = function (complete, opt) -- cgit v1.3.1 From bccbaae0a466152fa648ed10156fb6295c862c37 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 23:33:26 +0800 Subject: fix fetch package --- xmake/actions/package/local/main.lua | 4 ++-- xmake/actions/package/remote/main.lua | 2 +- xmake/core/package/package.lua | 4 ++-- xmake/modules/private/action/require/impl/repository.lua | 8 -------- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index 28d235126..75c6b4d72 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -63,7 +63,7 @@ function _package_binary(target) file:print(" set_license(\"%s\")", target:license()) end if #deps > 0 then - file:print(" set_deps(\"%s\")", table.concat(deps, "\", \"")) + file:print(" add_deps(\"%s\")", table.concat(deps, "\", \"")) end file:print("") file:print([[ @@ -145,7 +145,7 @@ function _package_library(target) file:print(" set_license(\"%s\")", target:license()) end if #deps > 0 then - file:print(" set_deps(\"%s\")", table.concat(deps, "\", \"")) + file:print(" add_deps(\"%s\")", table.concat(deps, "\", \"")) end file:print("") file:print([[ diff --git a/xmake/actions/package/remote/main.lua b/xmake/actions/package/remote/main.lua index 6b108e60e..0e8383890 100644 --- a/xmake/actions/package/remote/main.lua +++ b/xmake/actions/package/remote/main.lua @@ -59,7 +59,7 @@ function _package_remote(target) file:print(" set_license(\"%s\")", target:license()) end if #deps > 0 then - file:print(" set_deps(\"%s\")", table.concat(deps, "\", \"")) + file:print(" add_deps(\"%s\")", table.concat(deps, "\", \"")) end file:print("") local url = option.get("url") or "https://github.com/myrepo/foo.git" diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 72d8aa5f5..d68bcff57 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -1234,7 +1234,7 @@ function _instance:fetch(opt) if self:is_binary() then -- only fetch it from the xmake repository first - if not fetchinfo and system ~= true and not self:is_thirdparty() and not self:is_fetchonly() then + if not fetchinfo and system ~= true and not self:is_thirdparty() then fetchinfo = self:_fetch_tool({require_version = self:version_str(), force = opt.force}) if fetchinfo then is_system = self._is_system @@ -1251,7 +1251,7 @@ function _instance:fetch(opt) else -- only fetch it from the xmake repository first - if not fetchinfo and system ~= true and not self:is_thirdparty() and not self:is_fetchonly() then + if not fetchinfo and system ~= true and not self:is_thirdparty() then fetchinfo = self:_fetch_library({require_version = self:version_str(), external = external, force = opt.force}) if fetchinfo then is_system = self._is_system diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua index 6a0471f8b..f997ee703 100644 --- a/xmake/modules/private/action/require/impl/repository.lua +++ b/xmake/modules/private/action/require/impl/repository.lua @@ -70,17 +70,9 @@ function packagedir(packagename, reponame) break end end - - -- found? if foundir then - - -- save package directory packagedirs[packagename] = foundir - - -- update cache _g._PACKAGEDIRS = packagedirs - - -- ok return foundir[1], foundir[2] end end -- cgit v1.3.1 From 2394ef36175e66ac6aa5e958f6e487263e0bd6c0 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 2 Jun 2021 23:51:06 +0800 Subject: improve test output --- tests/actions/package/localpkg/test.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/actions/package/localpkg/test.lua b/tests/actions/package/localpkg/test.lua index 1256b1fa2..a1f03b215 100644 --- a/tests/actions/package/localpkg/test.lua +++ b/tests/actions/package/localpkg/test.lua @@ -1,10 +1,10 @@ function main(t) if (os.subarch():startswith("x") or os.subarch() == "i386") and not is_host("bsd") then os.cd("libfoo") - os.exec("xmake package -vD -o ../bar/build") + os.exec("xmake package -D -o ../bar/build") os.cd("../bar") - os.exec("xmake f -c -vD") - os.exec("xmake -vD") + os.exec("xmake f -c -D") + os.exec("xmake -D") os.exec("xmake run") end end -- cgit v1.3.1