summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-11-10 23:57:35 +0800
committerruki <[email protected]>2017-11-10 17:45:33 +0800
commit64875f84837a3b447d95b38ccce29bcdb57f8dd5 (patch)
tree50cf88c7c730f3a179b61a1084e6297d42433d3c
parent24bdac45ba26a318fd07b2bad0baa6d1bdc28fa9 (diff)
add rules test
-rw-r--r--tests/apis/rules/src/empty.stub0
-rw-r--r--tests/apis/rules/src/index.md1
-rw-r--r--tests/apis/rules/src/main.c8
-rw-r--r--tests/apis/rules/src/man/man1.in1
-rw-r--r--tests/apis/rules/src/man/man2.in1
-rw-r--r--tests/apis/rules/src/man/man3.in1
-rw-r--r--tests/apis/rules/src/test.c.in4
-rw-r--r--tests/apis/rules/xmake.lua84
-rw-r--r--xmake/core/project/rule.lua20
9 files changed, 120 insertions, 0 deletions
diff --git a/tests/apis/rules/src/empty.stub b/tests/apis/rules/src/empty.stub
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/apis/rules/src/empty.stub
diff --git a/tests/apis/rules/src/index.md b/tests/apis/rules/src/index.md
new file mode 100644
index 000000000..a17df88c2
--- /dev/null
+++ b/tests/apis/rules/src/index.md
@@ -0,0 +1 @@
+## hello xmake
diff --git a/tests/apis/rules/src/main.c b/tests/apis/rules/src/main.c
new file mode 100644
index 000000000..b86c9ad8e
--- /dev/null
+++ b/tests/apis/rules/src/main.c
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+extern int test(int a, int b);
+int main(int argc, char** argv)
+{
+ printf("1 + 1 = %d\n", test(1, 1));
+ return 0;
+}
diff --git a/tests/apis/rules/src/man/man1.in b/tests/apis/rules/src/man/man1.in
new file mode 100644
index 000000000..2258f3ea3
--- /dev/null
+++ b/tests/apis/rules/src/man/man1.in
@@ -0,0 +1 @@
+hello [name]!
diff --git a/tests/apis/rules/src/man/man2.in b/tests/apis/rules/src/man/man2.in
new file mode 100644
index 000000000..2258f3ea3
--- /dev/null
+++ b/tests/apis/rules/src/man/man2.in
@@ -0,0 +1 @@
+hello [name]!
diff --git a/tests/apis/rules/src/man/man3.in b/tests/apis/rules/src/man/man3.in
new file mode 100644
index 000000000..2258f3ea3
--- /dev/null
+++ b/tests/apis/rules/src/man/man3.in
@@ -0,0 +1 @@
+hello [name]!
diff --git a/tests/apis/rules/src/test.c.in b/tests/apis/rules/src/test.c.in
new file mode 100644
index 000000000..5d7319804
--- /dev/null
+++ b/tests/apis/rules/src/test.c.in
@@ -0,0 +1,4 @@
+int test(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/apis/rules/xmake.lua b/tests/apis/rules/xmake.lua
new file mode 100644
index 000000000..d05d0eacc
--- /dev/null
+++ b/tests/apis/rules/xmake.lua
@@ -0,0 +1,84 @@
+
+-- define rule: markdown
+rule("markdown")
+ on_build(function (target, sourcefile)
+ print("compiling %s", sourcefile)
+ os.cp(sourcefile, path.join(target:objectdir(), path.basename(sourcefile) .. ".html"))
+ end)
+
+-- define rule: man
+rule("man")
+ add_imports("core.project.rule")
+ on_build_all(function (target, sourcefiles)
+ local vars = {name = "xmake"}
+ for _, sourcefile in ipairs(sourcefiles) do
+ print("generating %s", sourcefile)
+ io.gsub(sourcefile, "%[(.+)%]", function (name) return vars[name] end)
+ end
+ rule.build_all("markdown", target, sourcefiles)
+ end)
+
+-- define rule: c code
+rule("c code")
+ add_imports("core.tool.compiler")
+ on_build(function (target, sourcefile)
+ print("compiling %s", sourcefile)
+ local objectfile = os.tmpfile() .. ".o"
+ compiler.compile(sourcefile, objectfile, {sourcekind = "cc"})
+ table.insert(target:objectfiles(), objectfile)
+ end)
+
+-- define rule: stub
+rule("stub")
+ before_build(function (target, sourcefile)
+ print("before_build: %s", sourcefile)
+ end)
+ on_build(function (target, sourcefile)
+ print("on_build: %s", sourcefile)
+ end)
+ after_build(function (target, sourcefile)
+ print("after_build: %s", sourcefile)
+ end)
+
+ before_clean(function (target, sourcefile)
+ print("before_clean: %s", sourcefile)
+ end)
+ on_clean(function (target, sourcefile)
+ print("on_clean: %s", sourcefile)
+ end)
+ after_clean(function (target, sourcefile)
+ print("after_clean: %s", sourcefile)
+ end)
+
+ before_install(function (target, sourcefile)
+ print("before_install: %s", sourcefile)
+ end)
+ on_install(function (target, sourcefile)
+ print("on_install: %s", sourcefile)
+ end)
+ after_install(function (target, sourcefile)
+ print("after_install: %s", sourcefile)
+ end)
+
+ before_package(function (target, sourcefile)
+ print("before_package: %s", sourcefile)
+ end)
+ on_package(function (target, sourcefile)
+ print("on_package: %s", sourcefile)
+ end)
+ after_package(function (target, sourcefile)
+ print("after_package: %s", sourcefile)
+ end)
+
+-- define target
+target("test")
+
+ -- set kind
+ set_kind("binary")
+
+ -- add files
+ add_files("src/*.c")
+ add_files("src/man/*.in", {rule = "man"})
+ add_files("src/index.md", {rule = "markdown"})
+ add_files("src/test.c.in", {rule = "c code"})
+ add_files("src/empty.stub", {rule = "stub"})
diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua
index bd0a2af57..56d47c0ca 100644
--- a/xmake/core/project/rule.lua
+++ b/xmake/core/project/rule.lua
@@ -50,15 +50,35 @@ function rule.apis()
, "rule.on_install"
, "rule.on_uninstall"
-- rule.before_xxx
+ , "rule.before_build"
, "rule.before_clean"
, "rule.before_package"
, "rule.before_install"
, "rule.before_uninstall"
-- rule.after_xxx
+ , "rule.after_build"
, "rule.after_clean"
, "rule.after_package"
, "rule.after_install"
, "rule.after_uninstall"
+ -- rule.on_xxx_all
+ , "rule.on_build_all"
+ , "rule.on_clean_all"
+ , "rule.on_package_all"
+ , "rule.on_install_all"
+ , "rule.on_uninstall_all"
+ -- rule.before_xxx_all
+ , "rule.before_build_all"
+ , "rule.before_clean_all"
+ , "rule.before_package_all"
+ , "rule.before_install_all"
+ , "rule.before_uninstall_all"
+ -- rule.after_xxx_all
+ , "rule.after_build_all"
+ , "rule.after_clean_all"
+ , "rule.after_package_all"
+ , "rule.after_install_all"
+ , "rule.after_uninstall_all"
}
}
end