summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-04-13 22:32:17 +0800
committerruki <[email protected]>2018-04-13 09:13:43 +0800
commita5db969b72cd12419a6699ebd98f6fa5a9b85019 (patch)
tree0b72603f2a2df5fbfe06cc484180bf70e0ffb174
parentafcbad58716d9b766d77a70827f45695c9819099 (diff)
add other scripts for rule
-rw-r--r--tests/apis/rules/xmake.lua23
-rw-r--r--xmake/actions/build/builder.lua29
-rw-r--r--xmake/actions/clean/main.lua36
-rw-r--r--xmake/actions/install/install.lua36
-rw-r--r--xmake/actions/package/main.lua36
-rw-r--r--xmake/actions/run/main.lua31
-rw-r--r--xmake/actions/uninstall/uninstall.lua36
-rw-r--r--xmake/core/project/rule.lua13
8 files changed, 181 insertions, 59 deletions
diff --git a/tests/apis/rules/xmake.lua b/tests/apis/rules/xmake.lua
index 7afddab29..e447feb24 100644
--- a/tests/apis/rules/xmake.lua
+++ b/tests/apis/rules/xmake.lua
@@ -40,9 +40,6 @@ rule("stub2")
before_build(function (target)
print("rule(stub2): before_build")
end)
- on_build(function (target)
- print("rule(stub2): on_build")
- end)
after_build(function (target)
print("rule(stub2): after_build")
end)
@@ -57,21 +54,15 @@ rule("stub1")
before_build(function (target)
print("rule(stub1): before_build")
end)
- on_build(function (target)
- print("rule(stub1): on_build")
- end)
after_build(function (target)
print("rule(stub1): after_build")
end)
before_clean(function (target)
- print("rule(stub1): before_build")
- end)
- on_clean(function (target)
- print("rule(stub1): on_build")
+ print("rule(stub1): before_clean")
end)
after_clean(function (target)
- print("rule(stub1): after_build")
+ print("rule(stub1): after_clean")
end)
before_install(function (target)
@@ -104,6 +95,16 @@ rule("stub1")
print("rule(stub1): after_package")
end)
+ before_run(function (target)
+ print("rule(stub1): before_run")
+ end)
+ on_run(function (target)
+ print("rule(stub1): on_run")
+ end)
+ after_run(function (target)
+ print("rule(stub1): after_run")
+ end)
+
-- define target
target("test")
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua
index 056cc746e..e34067230 100644
--- a/xmake/actions/build/builder.lua
+++ b/xmake/actions/build/builder.lua
@@ -39,6 +39,17 @@ end
-- on build the given target
function _on_build_target(target)
+ -- build target with rules
+ local done = false
+ for _, r in ipairs(target:orderules()) do
+ local on_build = r:script("build")
+ if on_build then
+ on_build(target)
+ done = true
+ end
+ end
+ if done then return end
+
-- build target
if not target:isphony() then
import("kinds." .. target:targetkind()).build(target, _g)
@@ -52,7 +63,23 @@ function _build_target(target)
local scripts =
{
target:script("build_before")
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local before_build = r:script("build_before")
+ if before_build then
+ before_build(target)
+ end
+ end
+ end
, target:script("build", _on_build_target)
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local after_build = r:script("build_after")
+ if after_build then
+ after_build(target)
+ end
+ end
+ end
, target:script("build_after")
}
@@ -62,7 +89,7 @@ function _build_target(target)
end
-- run the target scripts
- for i = 1, 3 do
+ for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
diff --git a/xmake/actions/clean/main.lua b/xmake/actions/clean/main.lua
index 497acb43d..130458280 100644
--- a/xmake/actions/clean/main.lua
+++ b/xmake/actions/clean/main.lua
@@ -52,6 +52,17 @@ end
-- on clean target
function _on_clean_target(target)
+ -- build target with rules
+ local done = false
+ for _, r in ipairs(target:orderules()) do
+ local on_clean = r:script("clean")
+ if on_clean then
+ on_clean(target)
+ done = true
+ end
+ end
+ if done then return end
+
-- is phony target?
if target:isphony() then
return
@@ -89,13 +100,6 @@ 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
@@ -105,12 +109,28 @@ function _clean_target(target)
local scripts =
{
target:script("clean_before")
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local before_clean = r:script("clean_before")
+ if before_clean then
+ before_clean(target)
+ end
+ end
+ end
, target:script("clean", _on_clean_target)
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local after_clean = r:script("clean_after")
+ if after_clean then
+ after_clean(target)
+ end
+ end
+ end
, target:script("clean_after")
}
-- run the target scripts
- for i = 1, 3 do
+ for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua
index 92d13f279..3fffa2689 100644
--- a/xmake/actions/install/install.lua
+++ b/xmake/actions/install/install.lua
@@ -91,6 +91,17 @@ end
-- on install
function _on_install(target)
+ -- build target with rules
+ local done = false
+ for _, r in ipairs(target:orderules()) do
+ local on_install = r:script("install")
+ if on_install then
+ on_install(target)
+ done = true
+ end
+ end
+ if done then return end
+
-- the scripts
local scripts =
{
@@ -104,13 +115,6 @@ 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
@@ -123,12 +127,28 @@ function _install_target(target)
local scripts =
{
target:script("install_before")
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local before_install = r:script("install_before")
+ if before_install then
+ before_install(target)
+ end
+ end
+ end
, target:script("install", _on_install)
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local after_install = r:script("install_after")
+ if after_install then
+ after_install(target)
+ end
+ end
+ end
, target:script("install_after")
}
-- install the target scripts
- for i = 1, 3 do
+ for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
diff --git a/xmake/actions/package/main.lua b/xmake/actions/package/main.lua
index 05a788516..b0d82800c 100644
--- a/xmake/actions/package/main.lua
+++ b/xmake/actions/package/main.lua
@@ -116,6 +116,17 @@ end
-- package target
function _on_package(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
+
-- is phony target?
if target:isphony() then
return
@@ -137,13 +148,6 @@ function _on_package(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
@@ -156,12 +160,28 @@ function _package(target)
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)
+ , 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, 3 do
+ for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
diff --git a/xmake/actions/run/main.lua b/xmake/actions/run/main.lua
index 2ce6748ae..0fb0a578a 100644
--- a/xmake/actions/run/main.lua
+++ b/xmake/actions/run/main.lua
@@ -34,6 +34,17 @@ import("devel.debugger")
-- run target
function _on_run_target(target)
+ -- build target with rules
+ local done = false
+ for _, r in ipairs(target:orderules()) do
+ local on_run = r:script("run")
+ if on_run then
+ on_run(target)
+ done = true
+ end
+ end
+ if done then return end
+
-- get kind
if target:targetkind() == "binary" then
@@ -66,12 +77,28 @@ function _run(target)
local scripts =
{
target:script("run_before")
- , target:script("run") or _on_run_target
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local before_run = r:script("run_before")
+ if before_run then
+ before_run(target)
+ end
+ end
+ end
+ , target:script("run", _on_run_target)
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local after_run = r:script("run_after")
+ if after_run then
+ after_run(target)
+ end
+ end
+ end
, target:script("run_after")
}
-- run the target scripts
- for i = 1, 3 do
+ for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
diff --git a/xmake/actions/uninstall/uninstall.lua b/xmake/actions/uninstall/uninstall.lua
index 1d3c8ef48..adc7b9102 100644
--- a/xmake/actions/uninstall/uninstall.lua
+++ b/xmake/actions/uninstall/uninstall.lua
@@ -75,6 +75,17 @@ end
-- uninstall target
function _on_uninstall(target)
+ -- build target with rules
+ local done = false
+ for _, r in ipairs(target:orderules()) do
+ local on_uninstall = r:script("uninstall")
+ if on_uninstall then
+ on_uninstall(target)
+ done = true
+ end
+ end
+ if done then return end
+
-- the scripts
local scripts =
{
@@ -88,13 +99,6 @@ 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
@@ -107,12 +111,28 @@ function _uninstall_target(target)
local scripts =
{
target:script("uninstall_before")
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local before_uninstall = r:script("uninstall_before")
+ if before_uninstall then
+ before_uninstall(target)
+ end
+ end
+ end
, target:script("uninstall", _on_uninstall)
+ , function (target)
+ for _, r in ipairs(target:orderules()) do
+ local after_uninstall = r:script("uninstall_after")
+ if after_uninstall then
+ after_uninstall(target)
+ end
+ end
+ end
, target:script("uninstall_after")
}
-- uninstall the target scripts
- for i = 1, 3 do
+ for i = 1, 5 do
local script = scripts[i]
if script ~= nil then
script(target)
diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua
index 6648ec73e..9d27f22a0 100644
--- a/xmake/core/project/rule.lua
+++ b/xmake/core/project/rule.lua
@@ -153,22 +153,9 @@ function rule.apis()
-- rule.set_xxx
"rule.set_extensions"
, "rule.set_kind"
- , "rule.set_strip"
- , "rule.set_symbols"
- , "rule.set_warnings"
- , "rule.set_optimize"
- , "rule.set_languages"
-- rule.add_xxx
, "rule.add_deps"
, "rule.add_imports"
- , "rule.add_languages"
- , "rule.add_vectorexts"
- }
- , dictionary =
- {
- -- rule.set_xxx
- "rule.set_tools"
- , "rule.add_tools"
}
, script =
{