summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-28 22:58:52 +0800
committerruki <[email protected]>2020-04-28 11:53:15 +0800
commit46db0ae216d4581b8db54c23e678f0cf50169569 (patch)
tree99141fd38cbd57f42c4f4155976217a585341fb4
parente711f0074cfae91f75a0a20acd6ebea8c610fb98 (diff)
check includedirs, linkdirs and etc
-rw-r--r--xmake/rules/c++/xmake.lua3
-rw-r--r--xmake/rules/objc++/xmake.lua3
-rw-r--r--xmake/rules/swift/xmake.lua10
-rw-r--r--xmake/rules/utils/check_targets/check_targets.lua61
-rw-r--r--xmake/rules/utils/check_targets/xmake.lua24
5 files changed, 100 insertions, 1 deletions
diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua
index 869d50b60..3cc3aaea7 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -57,3 +57,6 @@ rule("c++")
-- we attempt to extract symbols to the independent file and
-- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled
add_deps("utils.symbols.extract")
+
+ -- check targets
+ add_deps("utils.check.targets")
diff --git a/xmake/rules/objc++/xmake.lua b/xmake/rules/objc++/xmake.lua
index e54aa869c..ca027b9d6 100644
--- a/xmake/rules/objc++/xmake.lua
+++ b/xmake/rules/objc++/xmake.lua
@@ -65,3 +65,6 @@ rule("objc++")
-- we attempt to extract symbols to the independent file and
-- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled
add_deps("utils.symbols.extract")
+
+ -- check targets
+ add_deps("utils.check.targets")
diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua
index 158a001e3..87957ad93 100644
--- a/xmake/rules/swift/xmake.lua
+++ b/xmake/rules/swift/xmake.lua
@@ -25,4 +25,12 @@ rule("swift.build")
-- define rule: swift
rule("swift")
- add_deps("swift.build", "utils.merge.object")
+
+ -- add build rules
+ add_deps("swift.build")
+
+ -- support `add_files("src/*.o")` to merge object files to target
+ add_deps("utils.merge.object")
+
+ -- check targets
+ add_deps("utils.check.targets")
diff --git a/xmake/rules/utils/check_targets/check_targets.lua b/xmake/rules/utils/check_targets/check_targets.lua
new file mode 100644
index 000000000..3c9b992fd
--- /dev/null
+++ b/xmake/rules/utils/check_targets/check_targets.lua
@@ -0,0 +1,61 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check_targets.lua
+--
+
+-- add values from target options
+function _add_values_from_targetopts(values, target, name)
+ for _, opt in ipairs(target:orderopts()) do
+ table.join2(values, table.wrap(opt:get(name)))
+ end
+end
+
+-- add values from target packages
+function _add_values_from_targetpkgs(values, target, name)
+ for _, pkg in ipairs(target:orderpkgs()) do
+ -- uses them instead of the builtin configs if exists extra package config
+ -- e.g. `add_packages("xxx", {links = "xxx"})`
+ local configinfo = target:pkgconfig(pkg:name())
+ if configinfo and configinfo[name] then
+ table.join2(values, configinfo[name])
+ else
+ -- uses the builtin package configs
+ table.join2(values, pkg:get(name))
+ end
+ end
+end
+
+-- get values from target
+function _get_values_from_target(target, name)
+ local values = table.wrap(target:get(name))
+ _add_values_from_targetopts(values, target, name)
+ _add_values_from_targetpkgs(values, target, name)
+ return values
+end
+
+-- main entry
+function main(target)
+ for _, name in ipairs({"includedirs", "frameworkdirs", "linkdirs"}) do
+ for _, value in ipairs(_get_values_from_target(target, name)) do
+ if not os.isdir(value) then
+ local sourceinfo = (target:get("__sourceinfo_" .. name) or {})[value] or {}
+ cprint("${color.warning}%s(%s).add_%s(\"%s\"): path not found at %s:%d", target:type(), target:name(), name, value, sourceinfo.file or "", sourceinfo.line or -1)
+ end
+ end
+ end
+end
diff --git a/xmake/rules/utils/check_targets/xmake.lua b/xmake/rules/utils/check_targets/xmake.lua
new file mode 100644
index 000000000..74ae8b34f
--- /dev/null
+++ b/xmake/rules/utils/check_targets/xmake.lua
@@ -0,0 +1,24 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define rule: utils.check.targets
+rule("utils.check.targets")
+ before_build("check_targets")
+