summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-03-09 00:30:13 +0800
committerruki <[email protected]>2019-03-08 21:01:21 +0800
commit7a68e6ad25e28c1b1c375147bb0f543ef3a47862 (patch)
treeed73c0d33c51f6a6f753a90166f58653978ef955
parentbc397edd2f7bb1ce6a40b3967878f682973351ca (diff)
improve target:get
-rw-r--r--README.md2
-rw-r--r--README_zh.md2
-rw-r--r--tests/apis/add_deps/xmake.lua8
-rw-r--r--xmake/core/base/scopeinfo.lua39
-rw-r--r--xmake/core/project/target.lua108
-rw-r--r--xmake/core/sandbox/modules/import/lib/luajit/bit.lua26
-rw-r--r--xmake/core/tool/builder.lua29
7 files changed, 172 insertions, 42 deletions
diff --git a/README.md b/README.md
index 65af85ecb..551107acf 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
<div align="center">
- <a href="http://xmake.io">
+ <a href="https://xmake.io">
<img width="200" heigth="200" src="https://tboox.org/static/img/xmake/logo256c.png">
</a>
diff --git a/README_zh.md b/README_zh.md
index 8b7d84559..95e155ee1 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -1,5 +1,5 @@
<div align="center">
- <a href="http://xmake.io/cn">
+ <a href="https://xmake.io/cn">
<img width="200" heigth="200" src="https://tboox.org/static/img/xmake/logo256c.png">
</a>
diff --git a/tests/apis/add_deps/xmake.lua b/tests/apis/add_deps/xmake.lua
index b2b9b663b..c19821bb6 100644
--- a/tests/apis/add_deps/xmake.lua
+++ b/tests/apis/add_deps/xmake.lua
@@ -16,6 +16,14 @@ target("dep2")
print(target:extraconf("includedirs"))
print(target:extraconf("defines", "TEST2"))
print(target:extraconf("defines", "TEST2", "interface"))
+ print(target:get("files"))
+ print(target:get("files", {private = true}))
+ print(target:get("files", {public = true}))
+ print(target:get("files", {interface = true}))
+ print(target:get("defines"))
+ print(target:get("defines", {private = true}))
+ print(target:get("defines", {public = true}))
+ print(target:get("defines", {interface = true}))
end)
target("dep3")
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index 49f333428..351572dfa 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -512,6 +512,45 @@ function _instance:apival_del(name, ...)
end
end
+-- get the extra configuration
+--
+-- e.g.
+--
+-- add_includedirs("inc", {public = true})
+--
+-- function (target)
+-- _instance:extraconf("includedirs", "inc", "public") -> true
+-- _instance:extraconf("includedirs", "inc") -> {public = true}
+-- _instance:extraconf("includedirs") -> {["inc"] = {public = true}}
+-- end
+--
+function _instance:extraconf(name, item, key)
+
+ -- get extra configurations
+ local extraconfs = self._EXTRACONFS
+ if not extraconfs then
+ extraconfs = {}
+ self._EXTRACONFS = extraconfs
+ end
+
+ -- get configuration
+ local extraconf = extraconfs[name]
+ if not extraconf then
+ extraconf = self:get("__extra_" .. name)
+ extraconfs[name] = extraconf
+ end
+
+ -- get configuration value
+ local value = extraconf
+ if item then
+ value = extraconf and extraconf[item] or nil
+ if value and key then
+ value = value[key]
+ end
+ end
+ return value
+end
+
-- new an scope instance
function scopeinfo.new(...)
return _instance.new(...)
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index b29f044b7..3dd17258d 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -27,6 +27,7 @@ local target = target or {}
local _instance = _instance or {}
-- load modules
+local bit = require("bit")
local os = require("base/os")
local path = require("base/path")
local utils = require("base/utils")
@@ -208,9 +209,73 @@ function _instance:_copiedfiles(filetype, outputdir, pathfilter)
return srcfiles, dstfiles, fileinfos
end
+-- get the visibility, private: 1, interface: 2, public: 3 = 1 | 2
+function _instance:_visibility(opt)
+ local visibility = 1
+ if opt then
+ if opt.interface then
+ visibility = 2
+ elseif opt.public then
+ visibility = 3
+ end
+ end
+ return visibility
+end
+
-- get the target info
-function _instance:get(name)
- return self._INFO:get(name)
+--
+-- e.g.
+--
+-- default: get private
+-- - target:get("cflags")
+-- - target:get("cflags", {private = true})
+--
+-- get private and interface
+-- - target:get("cflags", {public = true})
+--
+-- get interface
+-- - target:get("cflags", {interface = true})
+--
+function _instance:get(name, opt)
+
+ -- get values
+ local values = self._INFO:get(name)
+
+ -- get thr required visibility
+ local vs_private = 1
+ local vs_interface = 2
+ local vs_public = 3 -- all
+ local vs_required = self:_visibility(opt)
+
+ -- get all values? (private and interface)
+ if vs_required == vs_public then
+ return values
+ end
+
+ -- get the extra configuration
+ local extraconf = self._INFO:extraconf(name)
+ if extraconf then
+ -- filter values for public, private or interface if be not dictionary
+ if not table.is_dictionary(values) then
+ local results = {}
+ for _, value in ipairs(table.wrap(values)) do
+ local vs_conf = self:_visibility(extraconf[value])
+ if bit.band(vs_required, vs_conf) ~= 0 then
+ table.insert(results, value)
+ end
+ end
+ if #results > 0 then
+ return table.unwrap(results)
+ end
+ else
+ return values
+ end
+ else
+ -- only get thr private values
+ if bit.band(vs_required, vs_private) ~= 0 then
+ return values
+ end
+ end
end
-- set the value to the target info
@@ -229,45 +294,8 @@ function _instance:del(name, ...)
end
-- get the extra configuration
---
--- e.g.
---
--- add_includedirs("inc", {public = true})
---
--- function (target)
--- target:extraconf("includedirs", "inc", "public") -> true
--- target:extraconf("includedirs", "inc") -> {public = true}
--- target:extraconf("includedirs") -> {["inc"] = {public = true}}
--- end
---
function _instance:extraconf(name, item, key)
-
- -- get extra configurations
- local extraconfs = self._EXTRACONFS
- if not extraconfs then
- extraconfs = {}
- self._EXTRACONFS = extraconfs
- end
-
- -- get configuration
- local extraconf = extraconfs[name]
- if not extraconf then
- extraconf = {}
- for k, v in pairs(table.wrap(self:get("__extra_" .. name))) do
- extraconf[k] = v
- end
- extraconfs[name] = extraconf
- end
-
- -- get configuration value
- local value = extraconf
- if item then
- value = extraconf[item]
- if value and key then
- value = value[key]
- end
- end
- return value
+ return self._INFO:extraconf(name, item, key)
end
-- get user private data
diff --git a/xmake/core/sandbox/modules/import/lib/luajit/bit.lua b/xmake/core/sandbox/modules/import/lib/luajit/bit.lua
new file mode 100644
index 000000000..1c351bc39
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/luajit/bit.lua
@@ -0,0 +1,26 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file bit.lua
+--
+
+-- return module
+return require("bit")
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 8c6a3a105..a7b664b4c 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -212,6 +212,35 @@ function builder:_inherit_from_targetdeps(results, target, flagname)
end
end
+--[[
+-- inherts from target deps
+function builder:_inherit_from_targetdeps(results, target, flagname)
+
+ -- for all target deps
+ local orderdeps = target:orderdeps()
+ local total = #orderdeps
+ for idx, _ in ipairs(orderdeps) do
+
+ -- reverse deps order for links
+ local dep = orderdeps[total + 1 - idx]
+
+ -- inherit this dep target?
+ local depinherit = target:extraconfig("deps", dep:name(), "inherit")
+ if (depinherit == nil or depinherit) then
+
+ dep:extraconf(flagname, "")
+ table.join2(values, dep:get(name))
+
+ if dep:type() == "target" then
+ for _, opt in ipairs(dep:orderopts()) do
+ table.join2(values, opt:get(name))
+ end
+ self:_inherit_from_targetpkgs(values, dep, name)
+ end
+ end
+ end
+end]]
+
-- add flags from the configure
function builder:_addflags_from_config(flags)
for _, flagkind in ipairs(self:_flagkinds()) do