diff options
| author | ruki <[email protected]> | 2021-06-02 23:06:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-06-02 23:06:56 +0800 |
| commit | 4bbd7833ea104e2f754c608e2bad41659d4952fc (patch) | |
| tree | 367210b0cc072f182e134c95db24502144f3f876 | |
| parent | 03236a125416b8623f582144616069e5a5b0c4bb (diff) | |
generate remote package
| -rw-r--r-- | xmake/actions/package/local/main.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/package/remote/main.lua | 123 |
2 files changed, 61 insertions, 68 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 + local packagedir = path.join(outputdir, "packages", packagename:sub(1, 1), packagename) - -- 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 + -- 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", _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") - } + file:print([[package("%s") + %s + set_description("%s") - -- package the target scripts - for i = 1, 5 do - local script = scripts[i] - if script ~= nil then - script(target) + add_urls("https://github.com/myrepo/foo.git") + add_versions("%s", "<shasum256 or gitcommit>") + %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 + |
