summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-11-08 11:07:41 +0800
committerruki <[email protected]>2020-11-08 11:07:41 +0800
commitea6afc015b3c3f391761ba13a03c966daedd6db4 (patch)
tree5ad9183da6470ba09542bd8b6634d149a9647fb0
parent8b032f72b8f3972fe702b6f3f20d07d2d1696739 (diff)
add check_licenses
-rw-r--r--xmake/actions/require/install.lua34
-rw-r--r--xmake/core/project/requireinfo.lua15
-rw-r--r--xmake/rules/c++/xmake.lua3
-rw-r--r--xmake/rules/utils/check_licenses/check_licenses.lua42
-rw-r--r--xmake/rules/utils/check_licenses/xmake.lua24
-rw-r--r--xmake/rules/utils/check_targets/check_targets.lua2
6 files changed, 99 insertions, 21 deletions
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua
index 4d250293f..75da17097 100644
--- a/xmake/actions/require/install.lua
+++ b/xmake/actions/require/install.lua
@@ -29,6 +29,7 @@ import("impl.environment")
import("impl.utils.get_requires")
-- register required package environments
+-- envs: bin path for *.dll, program ..
function _register_required_package_envs(instance, envs)
for name, values in pairs(instance:envs()) do
if name == "PATH" or name == "LD_LIBRARY_PATH" then
@@ -47,9 +48,27 @@ function _register_required_package_envs(instance, envs)
end
end
--- register required package info
-function _register_required_package_info(instance, requireinfo)
- requireinfo:add((instance:fetch()))
+-- register required package libraries
+-- libs: includedirs, links, linkdirs ...
+function _register_required_package_libs(instance, requireinfo, is_deps)
+ if instance:kind() ~= "binary" then
+ local fetchinfo = instance:fetch()
+ if fetchinfo then
+ fetchinfo.name = nil
+ if is_deps then
+ -- we need only reserve license for root package
+ --
+ -- @note the license compatibility between the root package and
+ -- its dependent packages is guaranteed by the root package itself
+ --
+ fetchinfo.license = nil
+
+ -- we need only root package version
+ fetchinfo.version = nil
+ end
+ requireinfo:add(fetchinfo)
+ end
+ end
end
-- register the required local package
@@ -62,9 +81,9 @@ function _register_required_package(instance, requireinfo)
-- clear require info first
requireinfo:clear()
- -- add include, links and envs for all dependent packages
+ -- add packages info with all dependencies
local envs = {}
- _register_required_package_info(instance, requireinfo)
+ _register_required_package_libs(instance, requireinfo)
_register_required_package_envs(instance, envs)
local orderdeps = instance:orderdeps()
if orderdeps then
@@ -72,7 +91,7 @@ function _register_required_package(instance, requireinfo)
for idx, _ in ipairs(orderdeps) do
local dep = orderdeps[total + 1 - idx]
if dep then
- _register_required_package_info(dep, requireinfo)
+ _register_required_package_libs(dep, requireinfo, true)
_register_required_package_envs(dep, envs)
end
end
@@ -81,9 +100,6 @@ function _register_required_package(instance, requireinfo)
requireinfo:add({envs = envs})
end
- -- save this package version
- requireinfo:version_set(instance:version_str())
-
-- enable this require info
requireinfo:enable(true)
end
diff --git a/xmake/core/project/requireinfo.lua b/xmake/core/project/requireinfo.lua
index 2290b4f44..2ae0a8650 100644
--- a/xmake/core/project/requireinfo.lua
+++ b/xmake/core/project/requireinfo.lua
@@ -109,22 +109,17 @@ function requireinfo:version()
-- get version
local version = nil
- local verstr = self:get("__version")
+ local verstr = self:get("version")
if verstr then
version = semver.new(verstr)
end
-
- -- save to cache
self._VERSION = version or false
-
- -- done
return version
end
--- set the package version
-function requireinfo:version_set(version)
- self._VERSION = nil
- self:set("__version", version)
+-- get the package license
+function requireinfo:license()
+ return self:get("license")
end
-- get the require string
@@ -202,8 +197,6 @@ function requireinfo.load(name)
local instance = table.inherit(requireinfo)
instance._INFO = info
instance._NAME = name
-
- -- ok
return instance
end
diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua
index 5a68ab3e8..51b5d355f 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -60,3 +60,6 @@ rule("c++")
-- check targets
add_deps("utils.check.targets")
+
+ -- check licenses
+ add_deps("utils.check.licenses")
diff --git a/xmake/rules/utils/check_licenses/check_licenses.lua b/xmake/rules/utils/check_licenses/check_licenses.lua
new file mode 100644
index 000000000..2d356f61a
--- /dev/null
+++ b/xmake/rules/utils/check_licenses/check_licenses.lua
@@ -0,0 +1,42 @@
+--!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_licenses.lua
+--
+
+-- check licenses
+function _check_licenses_for_package(target_name, target_license, package_name, package_licenses)
+ -- TODO
+end
+
+-- check licenses for all dependent packages
+--
+-- @see https://github.com/xmake-io/xmake/issues/1016
+--
+function _check_licenses_for_packages(target)
+ local target_license = target:get("license")
+ if target_license then
+ for _, pkg in ipairs(target:orderpkgs()) do
+ _check_licenses_for_package(target:name(), target_license, pkg:name(), pkg:get("license"))
+ end
+ end
+end
+
+-- main entry
+function main(target)
+ _check_licenses_for_packages(target)
+end
diff --git a/xmake/rules/utils/check_licenses/xmake.lua b/xmake/rules/utils/check_licenses/xmake.lua
new file mode 100644
index 000000000..c007e07d9
--- /dev/null
+++ b/xmake/rules/utils/check_licenses/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.licenses
+rule("utils.check.licenses")
+ before_build("check_licenses")
+
diff --git a/xmake/rules/utils/check_targets/check_targets.lua b/xmake/rules/utils/check_targets/check_targets.lua
index d92345faf..a01899ba7 100644
--- a/xmake/rules/utils/check_targets/check_targets.lua
+++ b/xmake/rules/utils/check_targets/check_targets.lua
@@ -32,7 +32,7 @@ function main(target)
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}${text.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)
+ wprint("%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