diff options
| author | ruki <[email protected]> | 2017-11-11 21:06:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-11-11 21:06:54 +0800 |
| commit | d8c3db4f8bd8a63eb1748bf1e0fd90001e318668 (patch) | |
| tree | 96c1d3c5d7e1070b517661366432d31c29f684f6 | |
| parent | bc63208869cc865be6ce6ec60d22c9d128d9d65e (diff) | |
impl other rules
| -rw-r--r-- | tests/apis/rules/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/actions/clean/main.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/install/install.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/package/main.lua | 14 | ||||
| -rw-r--r-- | xmake/actions/uninstall/uninstall.lua | 8 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 92 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/rule.lua | 64 |
7 files changed, 194 insertions, 3 deletions
diff --git a/tests/apis/rules/xmake.lua b/tests/apis/rules/xmake.lua index d97890552..af4486428 100644 --- a/tests/apis/rules/xmake.lua +++ b/tests/apis/rules/xmake.lua @@ -34,6 +34,9 @@ rule("stub") on_install(function (target, sourcefile) print("on_install: %s", sourcefile) end) + on_uninstall(function (target, sourcefile) + print("on_uninstall: %s", sourcefile) + end) on_package(function (target, sourcefile) print("on_package: %s", sourcefile) end) diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua index fbc9adc40..e2536531f 100644 --- a/xmake/actions/clean/main.lua +++ b/xmake/actions/clean/main.lua @@ -25,6 +25,7 @@ -- imports import("core.base.option") import("core.base.task") +import("core.project.rule") import("core.project.config") import("core.base.global") import("core.project.project") @@ -88,6 +89,13 @@ function _on_clean_target(target) -- remove the config.h file _remove(target:configheader()) end + + -- clean files with the custom + for sourcekind, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.rulename then + rule.clean(sourcebatch.rulename, target, sourcebatch.sourcefiles) + end + end end -- clean the given target files diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua index b640be7d2..120b6d17d 100644 --- a/xmake/actions/install/install.lua +++ b/xmake/actions/install/install.lua @@ -24,6 +24,7 @@ -- imports import("core.base.task") +import("core.project.rule") import("core.project.project") -- install binary @@ -103,6 +104,13 @@ function _on_install(target) if script then script(target) end + + -- install files with the custom + for sourcekind, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.rulename then + rule.install(sourcebatch.rulename, target, sourcebatch.sourcefiles) + end + end end -- install the given target diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua index 17c51526a..7c20d46ca 100644 --- a/xmake/actions/package/main.lua +++ b/xmake/actions/package/main.lua @@ -25,8 +25,9 @@ -- imports import("core.base.option") import("core.base.task") -import("core.project.config") import("core.base.global") +import("core.project.rule") +import("core.project.config") import("core.project.project") import("core.platform.platform") @@ -113,7 +114,7 @@ option("[targetname]") end -- package target -function _on_package_target(target) +function _on_package(target) -- is phony target? if target:isphony() then @@ -136,6 +137,13 @@ function _on_package_target(target) -- package it scripts[kind](target) + + -- package files with the custom + for sourcekind, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.rulename then + rule.package(sourcebatch.rulename, target, sourcebatch.sourcefiles) + end + end end -- package the given target @@ -148,7 +156,7 @@ function _package(target) local scripts = { target:script("package_before") - , target:script("package", _on_package_target) + , target:script("package", _on_package) , target:script("package_after") } diff --git a/xmake/actions/uninstall/uninstall.lua b/xmake/actions/uninstall/uninstall.lua index 16cb84db9..454dc1293 100644 --- a/xmake/actions/uninstall/uninstall.lua +++ b/xmake/actions/uninstall/uninstall.lua @@ -24,6 +24,7 @@ -- imports import("core.base.task") +import("core.project.rule") import("core.project.project") -- uninstall binary @@ -87,6 +88,13 @@ function _on_uninstall(target) if script then script(target) end + + -- uninstall files with the custom + for sourcekind, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.rulename then + rule.uninstall(sourcebatch.rulename, target, sourcebatch.sourcefiles) + end + end end -- uninstall the given target diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 4d9a9df7e..31d53d753 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -109,6 +109,98 @@ function rule:build(target, sourcefiles) return true end +-- clean files +function rule:clean(target, sourcefiles) + + -- clean all? + local clean_all = self:script("clean_all") + if clean_all then + return sandbox.load(clean_all, target, sourcefiles) + else + local clean = self:script("clean") + if clean then + for _, sourcefile in ipairs(table.wrap(sourcefiles)) do + local ok, errors = sandbox.load(clean, target, sourcefile) + if not ok then + return false, errors + end + end + end + end + + -- ok + return true +end + +-- install files +function rule:install(target, sourcefiles) + + -- install all? + local install_all = self:script("install_all") + if install_all then + return sandbox.load(install_all, target, sourcefiles) + else + local install = self:script("install") + if install then + for _, sourcefile in ipairs(table.wrap(sourcefiles)) do + local ok, errors = sandbox.load(install, target, sourcefile) + if not ok then + return false, errors + end + end + end + end + + -- ok + return true +end + +-- uninstall files +function rule:uninstall(target, sourcefiles) + + -- uninstall all? + local uninstall_all = self:script("uninstall_all") + if uninstall_all then + return sandbox.load(uninstall_all, target, sourcefiles) + else + local uninstall = self:script("uninstall") + if uninstall then + for _, sourcefile in ipairs(table.wrap(sourcefiles)) do + local ok, errors = sandbox.load(uninstall, target, sourcefile) + if not ok then + return false, errors + end + end + end + end + + -- ok + return true +end + +-- package files +function rule:package(target, sourcefiles) + + -- package all? + local package_all = self:script("package_all") + if package_all then + return sandbox.load(package_all, target, sourcefiles) + else + local package = self:script("package") + if package then + for _, sourcefile in ipairs(table.wrap(sourcefiles)) do + local ok, errors = sandbox.load(package, target, sourcefile) + if not ok then + return false, errors + end + end + end + end + + -- ok + return true +end + -- get xxx_script function rule:script(name, generic) diff --git a/xmake/core/sandbox/modules/import/core/project/rule.lua b/xmake/core/sandbox/modules/import/core/project/rule.lua index 75d88a26a..77ac8b0cc 100644 --- a/xmake/core/sandbox/modules/import/core/project/rule.lua +++ b/xmake/core/sandbox/modules/import/core/project/rule.lua @@ -48,5 +48,69 @@ function sandbox_core_project_rule.build(rulename, target, sourcefiles) end end +-- clean files +function sandbox_core_project_rule.clean(rulename, target, sourcefiles) + + -- get rule + local rule = project.rule(rulename) + if not rule then + raise("unknown rule: %s", rulename) + end + + -- do clean + local ok, errors = rule:clean(target, sourcefiles) + if not ok then + raise(errors) + end +end + +-- install files +function sandbox_core_project_rule.install(rulename, target, sourcefiles) + + -- get rule + local rule = project.rule(rulename) + if not rule then + raise("unknown rule: %s", rulename) + end + + -- do install + local ok, errors = rule:install(target, sourcefiles) + if not ok then + raise(errors) + end +end + +-- uninstall files +function sandbox_core_project_rule.uninstall(rulename, target, sourcefiles) + + -- get rule + local rule = project.rule(rulename) + if not rule then + raise("unknown rule: %s", rulename) + end + + -- do uninstall + local ok, errors = rule:uninstall(target, sourcefiles) + if not ok then + raise(errors) + end +end + +-- package files +function sandbox_core_project_rule.package(rulename, target, sourcefiles) + + -- get rule + local rule = project.rule(rulename) + if not rule then + raise("unknown rule: %s", rulename) + end + + -- do package + local ok, errors = rule:package(target, sourcefiles) + if not ok then + raise(errors) + end +end + -- return module return sandbox_core_project_rule |
