diff options
| author | ruki <[email protected]> | 2020-11-08 19:18:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-11-08 19:18:52 +0800 |
| commit | da3c6af9d6584593311313c2ced57c1a39fff5ae (patch) | |
| tree | 9226e6b74b8a7e7f1a68804e3c29d9f6b8f36cff /xmake/modules/core/base/license.lua | |
| parent | ea6afc015b3c3f391761ba13a03c966daedd6db4 (diff) | |
add license checking
Diffstat (limited to 'xmake/modules/core/base/license.lua')
| -rw-r--r-- | xmake/modules/core/base/license.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/xmake/modules/core/base/license.lua b/xmake/modules/core/base/license.lua new file mode 100644 index 000000000..ca1c80eef --- /dev/null +++ b/xmake/modules/core/base/license.lua @@ -0,0 +1,75 @@ +--!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 license.lua +-- + +-- imports +import("core.base.object") +import("core.base.hashset") + +-- get licenses +function _licenses() + local licenses = _g.licenses + if not licenses then + licenses = hashset.from({"Apache-2.0", + "MIT", + "Public Domain", + "LGPL-2.0", "LGPL-2.1", "LGPL-3.0", + "GPL-2.0", "GPL-3.0", "GPL-3.0", + "BSD-2-Clause", "BSD-3-Clause"}) + _g.licenses = licenses + end + return licenses +end + +-- get all licenses list +function list() + return _licenses():to_array() +end + +-- normalize license +function normalize(license) + -- TODO parse and convert license strings in other formats + return license +end + +-- check if the license is compatible +-- @see https://github.com/xmake-io/xmake/issues/1016 +-- +function compatible(target_license, library_license, opt) + opt = opt or {} + library_license = normalize(library_license) + if library_license then + target_license = normalize(target_license) + if library_license:startswith("GPL-") then + return target_license and target_license:startswith("GPL-") + elseif library_license:startswith("LGPL-") then + if target_license and target_license:startswith("LGPL-") then + return true + elseif opt.library_kind and opt.library_kind == "shared" then + -- we can only use shared library with LGPL-x + return true + else + return false, string.format("we can use shared libraries with %s or use set_license()/set_policy() to modify/disable license", library_license) + end + else + -- TODO maybe we need handle more licenses + end + end + return true +end |
