Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions classes/licenses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
metaEnvironment:
PKG_LICENSE: "$(pkg_license)"

privateEnvironment:
PKG_LICENSE_PATH: "$(pkg_license_paths)"

buildVars: [PKG_LICENSE, PKG_LICENSE_PATH]
buildScript: |
if [ -z ${PKG_LICENSE:-} ]; then
echo "PKG_LICENSE is missing!" 1>&2
exit 1
fi
mkdir -p .bob
if [[ ${PKG_LICENSE} == LicenseRef* ]]; then
ID=${PKG_LICENSE#LicenseRef-}
if [[ $ID =~ ^[A-Za-z0-9.\-]+$ ]]; then
mkdir -p .bob/licenses/$ID
else
echo "LicenseRef contains invalid characters: ${PKG_LICENSE}"
false
fi
while read -r lic; do
_path=""
_file=${lic}
if [[ ${lic} == *:* ]]; then
IFS=: read -r _path _file <<< ${lic}
fi
mkdir -p .bob/licenses/$ID/${_path:-}
cp $1/$_file .bob/licenses/$ID/${_path:-}
done <<< ${PKG_LICENSE_PATH}
else
echo "${PKG_LICENSE}" >> .bob/license
fi

packageScript: |
cp -r $1/.bob .
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ plugins:
- vsenv
- msbuild
- config
- licenses
83 changes: 83 additions & 0 deletions plugins/licenses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Defines the "License" recipe key that can be used to describe the package license.
# If the package uses a vanilla license with a known spdx.id the license can be specified as:
#
# License: "GPL-3.0"
#
# and for custom licenses with a license file:
#
# License:
# Id: "devel.m4"
# Paths: "COPYING"
#
# The plugin also offers string functions to get these information back into the environment
# to be used by the licenses class.

# To enable the validation check of the license expression the license-expression module must be
# installed. (e.g. 'pip install license-expression').

from bob.errors import ParseError
from bob.input import PluginState, PluginProperty
from bob.tty import Warn
import schema

def expression_check(license):
try:
get_spdx_licensing().parse(license, validate=True, strict=True)
except ExpressionError as e:
# a raised exception message is not shown (?)
print(e)
return False
else:
return True

def dummyCheck (license):
return True

try:
from license_expression import get_spdx_licensing, ExpressionError
except ImportError as e:
Warn ("Unable to import license_expression module. License expressions will not be checked!").warn()
license_check = dummyCheck
else:
license_check = expression_check

LICENSE_SHEMA = schema.Schema(schema.Or(str, schema.Schema({'Id' : str, 'Paths' : str})))

class LicenseProperty(PluginProperty):
@staticmethod
def validate(data):
try:
lic = LICENSE_SHEMA.validate(data)
except schema.SchemaError as e:
print(e)
return False
if isinstance(lic, str):
return license_check(lic)
return True

def pkgLicense(args, env, recipe, **kwargs):
lic = recipe.getPluginProperties().get('License').getValue()
if lic is not None:
if isinstance(lic, str):
return lic
else:
return "LicenseRef-"+lic.get('Id')
return "UNSET"
#raise ParseError(f"{recipe.getName()} has no LICENSE")

def pkgLicensePaths(args, env, recipe, **kwargs):
lic = recipe.getPluginProperties().get('License').getValue()
if lic and isinstance(lic, dict):
return lic.get('Paths', "")
return ""

manifest = {
'apiVersion' : "1.1",
'properties' : {
'License' : LicenseProperty,
},
'stringFunctions' : {
'pkg_license' : pkgLicense,
'pkg_license_paths' : pkgLicensePaths
}
}
2 changes: 2 additions & 0 deletions recipes/devel/m4.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
inherit: [autotools, patch]

License: "GPL-3.0"

metaEnvironment:
PKG_VERSION: "1.4.20"

Expand Down