summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-06-02 00:44:06 +0800
committerruki <[email protected]>2021-06-02 00:44:06 +0800
commitd721e17b252a7de7b601c829c56290587e5ef6ff (patch)
tree10f9694803b45f4d80e2a905127a658091a7fa5c
parent7400647d109b785f492c51c29fd217da3a76c928 (diff)
improve some code styles
-rw-r--r--xmake/actions/package/localpkg/main.lua89
-rw-r--r--xmake/actions/package/oldpkg/main.lua39
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