* [RFC PATCH v2 1/3] recipetool: Separate licenses with & operator
@ 2021-12-13 15:05 Stefan Herbrechtsmeier
2021-12-13 15:05 ` [RFC PATCH v2 2/3] selftest: recipetool: Add test for split_pkg_licenses function Stefan Herbrechtsmeier
2021-12-13 15:05 ` [RFC PATCH v2 3/3] selftest: recipetool: Add test for handle_license_vars function Stefan Herbrechtsmeier
0 siblings, 2 replies; 5+ messages in thread
From: Stefan Herbrechtsmeier @ 2021-12-13 15:05 UTC (permalink / raw)
To: openembedded-core; +Cc: Stefan Herbrechtsmeier
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Separate licenses with & operator since it should be satisfied most use
cases and it is a reasonable assumption that all the licenses apply.
Furthermore flat, split and sort the licenses to minimize license string
changes.
Separate package licenses with & operator:
-LICENSE:${PN} = "MIT ISC"
+LICENSE:${PN} = "ISC & MIT"
Respect | and brackets in LICENSE:
-LICENSE = "BSD-3-Clause & (ISC & | & MIT)"
+LICENSE = "BSD-3-Clause & (ISC | MIT)"
Sort licenses:
-LICENSE = "MIT & BSD-3-Clause & ISC"
+LICENSE = "BSD-3-Clause & ISC & MIT"
Remove duplicates:
-LICENSE = "MIT & ISC & MIT"
+LICENSE = "ISC & MIT"
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---
(no changes since v1)
meta/lib/oeqa/selftest/cases/recipetool.py | 4 +--
scripts/lib/recipetool/create.py | 39 +++++++++++++++++-----
2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index 439e41597c..95e4753976 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -426,7 +426,7 @@ class RecipetoolCreateTests(RecipetoolBase):
checkvars = {}
checkvars['SUMMARY'] = 'Node Server Example'
checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme'
- checkvars['LICENSE'] = set(['MIT', 'ISC', 'Unknown'])
+ checkvars['LICENSE'] = 'BSD-3-Clause & ISC & MIT & Unknown'
urls = []
urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}')
urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json')
@@ -483,7 +483,7 @@ class RecipetoolCreateTests(RecipetoolBase):
result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
self.assertTrue(os.path.isfile(recipefile))
checkvars = {}
- checkvars['LICENSE'] = set(['PSF', '&', 'BSD-3-Clause', 'GPL'])
+ checkvars['LICENSE'] = 'BSD-3-Clause & GPL & PSF'
checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING.txt;md5=35a23d42b615470583563132872c97d6'
checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/f4/5771e41fdf52aabebbadecc9381d11dea0fa34e4759b4071244fa094804c/docutils-${PV}.tar.gz'
checkvars['SRC_URI[md5sum]'] = 'c53768d63db3873b7d452833553469de'
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index 406c97f1c5..8e8a621b4f 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -919,6 +919,22 @@ def split_value(value):
else:
return value
+def fixup_license(value):
+ # Ensure licenses with OR starts and ends with brackets
+ if '|' in value:
+ return '(' + value + ')'
+ return value
+
+def tidy_licenses(value):
+ """Flat, split and sort licenses"""
+ from oe.license import flattened_licenses
+ def _choose(a, b):
+ str_a, str_b = sorted((" & ".join(a), " & ".join(b)), key=str.casefold)
+ return ["(%s | %s)" % (str_a, str_b)]
+ if not isinstance(value, str):
+ value = " & ".join(value)
+ return sorted(list(set(flattened_licenses(value, _choose))), key=str.casefold)
+
def handle_license_vars(srctree, lines_before, handled, extravalues, d):
lichandled = [x for x in handled if x[0] == 'license']
if lichandled:
@@ -932,10 +948,13 @@ def handle_license_vars(srctree, lines_before, handled, extravalues, d):
lines = []
if licvalues:
for licvalue in licvalues:
- if not licvalue[0] in licenses:
- licenses.append(licvalue[0])
+ license = licvalue[0]
+ lics = tidy_licenses(fixup_license(license))
+ lics = [lic for lic in lics if lic not in licenses]
+ if len(lics):
+ licenses.extend(lics)
lic_files_chksum.append('file://%s;md5=%s' % (licvalue[1], licvalue[2]))
- if licvalue[0] == 'Unknown':
+ if license == 'Unknown':
lic_unknown.append(licvalue[1])
if lic_unknown:
lines.append('#')
@@ -944,9 +963,7 @@ def handle_license_vars(srctree, lines_before, handled, extravalues, d):
for licfile in lic_unknown:
lines.append('# %s' % licfile)
- extra_license = split_value(extravalues.pop('LICENSE', []))
- if '&' in extra_license:
- extra_license.remove('&')
+ extra_license = tidy_licenses(extravalues.pop('LICENSE', ''))
if extra_license:
if licenses == ['Unknown']:
licenses = extra_license
@@ -987,7 +1004,7 @@ def handle_license_vars(srctree, lines_before, handled, extravalues, d):
lines.append('# instead of &. If there is any doubt, check the accompanying documentation')
lines.append('# to determine which situation is applicable.')
- lines.append('LICENSE = "%s"' % ' & '.join(licenses))
+ lines.append('LICENSE = "%s"' % ' & '.join(sorted(licenses, key=str.casefold)))
lines.append('LIC_FILES_CHKSUM = "%s"' % ' \\\n '.join(lic_files_chksum))
lines.append('')
@@ -1226,6 +1243,7 @@ def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=[], pn='
"""
pkglicenses = {pn: []}
for license, licpath, _ in licvalues:
+ license = fixup_license(license)
for pkgname, pkgpath in packages.items():
if licpath.startswith(pkgpath + '/'):
if pkgname in pkglicenses:
@@ -1238,11 +1256,14 @@ def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=[], pn='
pkglicenses[pn].append(license)
outlicenses = {}
for pkgname in packages:
- license = ' '.join(list(set(pkglicenses.get(pkgname, ['Unknown'])))) or 'Unknown'
+ # Assume AND operator between license files
+ license = ' & '.join(list(set(pkglicenses.get(pkgname, ['Unknown'])))) or 'Unknown'
if license == 'Unknown' and pkgname in fallback_licenses:
license = fallback_licenses[pkgname]
+ licenses = tidy_licenses(license)
+ license = ' & '.join(licenses)
outlines.append('LICENSE:%s = "%s"' % (pkgname, license))
- outlicenses[pkgname] = license.split()
+ outlicenses[pkgname] = licenses
return outlicenses
def read_pkgconfig_provides(d):
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [RFC PATCH v2 2/3] selftest: recipetool: Add test for split_pkg_licenses function
2021-12-13 15:05 [RFC PATCH v2 1/3] recipetool: Separate licenses with & operator Stefan Herbrechtsmeier
@ 2021-12-13 15:05 ` Stefan Herbrechtsmeier
2021-12-13 15:05 ` [RFC PATCH v2 3/3] selftest: recipetool: Add test for handle_license_vars function Stefan Herbrechtsmeier
1 sibling, 0 replies; 5+ messages in thread
From: Stefan Herbrechtsmeier @ 2021-12-13 15:05 UTC (permalink / raw)
To: openembedded-core; +Cc: Stefan Herbrechtsmeier
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---
(no changes since v1)
meta/lib/oeqa/selftest/cases/recipetool.py | 64 ++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index 95e4753976..1c73b2c5e0 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -541,9 +541,13 @@ class RecipetoolTests(RecipetoolBase):
@classmethod
def setUpClass(cls):
+ import sys
+
super(RecipetoolTests, cls).setUpClass()
bb_vars = get_bb_vars(['BBPATH'])
cls.bbpath = bb_vars['BBPATH']
+ libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'recipetool')
+ sys.path.insert(0, libpath)
def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
dstdir = basedstdir
@@ -588,6 +592,66 @@ class RecipetoolTests(RecipetoolBase):
with open(srcfile, 'w') as fh:
fh.writelines(plugincontent)
+ def test_recipetool_split_pkg_licenses(self):
+ from create import split_pkg_licenses
+ licvalues = [
+ # Duplicate licenses
+ ('BSD-2-Clause', 'x/COPYING', None),
+ ('BSD-2-Clause', 'x/LICENSE', None),
+ # Multiple licenses
+ ('MIT', 'x/a/LICENSE.MIT', None),
+ ('ISC', 'x/a/LICENSE.ISC', None),
+ # Alternative licenses
+ ('(MIT | ISC)', 'x/b/LICENSE', None),
+ # Alternative licenses without brackets
+ ('MIT | BSD-2-Clause', 'x/c/LICENSE', None),
+ # Multi licenses with alternatives
+ ('MIT', 'x/d/COPYING', None),
+ ('MIT | BSD-2-Clause', 'x/d/LICENSE', None),
+ # Multi licenses with alternatives and brackets
+ ('Apache-2.0 & ((MIT | ISC) & BSD-3-Clause)', 'x/e/LICENSE', None)
+ ]
+ packages = {
+ '${PN}': '',
+ 'a': 'x/a',
+ 'b': 'x/b',
+ 'c': 'x/c',
+ 'd': 'x/d',
+ 'e': 'x/e',
+ 'f': 'x/f',
+ 'g': 'x/g',
+ }
+ fallback_licenses = {
+ # Ignored
+ 'a': 'BSD-3-Clause',
+ # Used
+ 'f': 'BSD-3-Clause'
+ }
+ outlines = []
+ outlicenses = split_pkg_licenses(licvalues, packages, outlines, fallback_licenses)
+ expected_outlicenses = {
+ '${PN}': ['BSD-2-Clause'],
+ 'a': ['ISC', 'MIT'],
+ 'b': ['(ISC | MIT)'],
+ 'c': ['(BSD-2-Clause | MIT)'],
+ 'd': ['(BSD-2-Clause | MIT)', 'MIT'],
+ 'e': ['(ISC | MIT)', 'Apache-2.0', 'BSD-3-Clause'],
+ 'f': ['BSD-3-Clause'],
+ 'g': ['Unknown']
+ }
+ self.assertEqual(outlicenses, expected_outlicenses)
+ expected_outlines = [
+ 'LICENSE:${PN} = "BSD-2-Clause"',
+ 'LICENSE:a = "ISC & MIT"',
+ 'LICENSE:b = "(ISC | MIT)"',
+ 'LICENSE:c = "(BSD-2-Clause | MIT)"',
+ 'LICENSE:d = "(BSD-2-Clause | MIT) & MIT"',
+ 'LICENSE:e = "(ISC | MIT) & Apache-2.0 & BSD-3-Clause"',
+ 'LICENSE:f = "BSD-3-Clause"',
+ 'LICENSE:g = "Unknown"'
+ ]
+ self.assertEqual(outlines, expected_outlines)
+
class RecipetoolAppendsrcBase(RecipetoolBase):
def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [RFC PATCH v2 3/3] selftest: recipetool: Add test for handle_license_vars function
2021-12-13 15:05 [RFC PATCH v2 1/3] recipetool: Separate licenses with & operator Stefan Herbrechtsmeier
2021-12-13 15:05 ` [RFC PATCH v2 2/3] selftest: recipetool: Add test for split_pkg_licenses function Stefan Herbrechtsmeier
@ 2021-12-13 15:05 ` Stefan Herbrechtsmeier
2021-12-14 13:01 ` [OE-core] " Richard Purdie
1 sibling, 1 reply; 5+ messages in thread
From: Stefan Herbrechtsmeier @ 2021-12-13 15:05 UTC (permalink / raw)
To: openembedded-core; +Cc: Stefan Herbrechtsmeier
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---
(no changes since v1)
meta/lib/oeqa/selftest/cases/recipetool.py | 62 ++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index 1c73b2c5e0..5330d73cbf 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -592,6 +592,68 @@ class RecipetoolTests(RecipetoolBase):
with open(srcfile, 'w') as fh:
fh.writelines(plugincontent)
+ def test_recipetool_handle_license_vars(self):
+ from create import handle_license_vars
+ from unittest.mock import Mock
+
+ commonlicdir = get_bb_var('COMMON_LICENSE_DIR')
+
+ d = bb.tinfoil.TinfoilDataStoreConnector
+ d.getVar = Mock(return_value=commonlicdir)
+
+ srctree = tempfile.mkdtemp(prefix='recipetoolqa')
+ self.track_for_cleanup(srctree)
+
+ # Multiple licenses
+ licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0']
+ for licence in licenses:
+ shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence))
+ # Duplicate license
+ shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE'))
+
+ extravalues = {
+ # Duplicate and missing licenses
+ 'LICENSE': 'Zlib & BSD-2-Clause & Zlib',
+ 'LIC_FILES_CHKSUM': [
+ 'file://README.md;md5=0123456789abcdef0123456789abcd'
+ ]
+ }
+ lines_before = []
+ handled = []
+ licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d)
+ expected_lines_before = [
+ '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is',
+ '# your responsibility to verify that the values are complete and correct.',
+ '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib',
+ '#',
+ '# NOTE: multiple licenses have been detected; they have been separated with &',
+ '# in the LICENSE value for now since it is a reasonable assumption that all',
+ '# of the licenses apply. If instead there is a choice between the multiple',
+ '# licenses then you should change the value to separate the licenses with |',
+ '# instead of &. If there is any doubt, check the accompanying documentation',
+ '# to determine which situation is applicable.',
+ 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"',
+ 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
+ ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
+ ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n'
+ ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n'
+ ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n'
+ ' file://README.md;md5=0123456789abcdef0123456789abcd"',
+ ''
+ ]
+ self.assertEqual(lines_before, expected_lines_before)
+ expected_licvalues = [
+ ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'),
+ ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302'),
+ ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'),
+ ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'),
+ ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9')
+ ]
+ self.assertEqual(handled, [('license', expected_licvalues)])
+ self.assertEqual(extravalues, {})
+ self.assertEqual(licvalues, expected_licvalues)
+
+
def test_recipetool_split_pkg_licenses(self):
from create import split_pkg_licenses
licvalues = [
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [OE-core] [RFC PATCH v2 3/3] selftest: recipetool: Add test for handle_license_vars function
2021-12-13 15:05 ` [RFC PATCH v2 3/3] selftest: recipetool: Add test for handle_license_vars function Stefan Herbrechtsmeier
@ 2021-12-14 13:01 ` Richard Purdie
2021-12-14 15:30 ` Stefan Herbrechtsmeier
0 siblings, 1 reply; 5+ messages in thread
From: Richard Purdie @ 2021-12-14 13:01 UTC (permalink / raw)
To: Stefan Herbrechtsmeier, openembedded-core; +Cc: Stefan Herbrechtsmeier
On Mon, 2021-12-13 at 16:05 +0100, Stefan Herbrechtsmeier wrote:
> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
>
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> ---
>
> (no changes since v1)
>
> meta/lib/oeqa/selftest/cases/recipetool.py | 62 ++++++++++++++++++++++
> 1 file changed, 62 insertions(+)
>
> diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
> index 1c73b2c5e0..5330d73cbf 100644
> --- a/meta/lib/oeqa/selftest/cases/recipetool.py
> +++ b/meta/lib/oeqa/selftest/cases/recipetool.py
> @@ -592,6 +592,68 @@ class RecipetoolTests(RecipetoolBase):
> with open(srcfile, 'w') as fh:
> fh.writelines(plugincontent)
>
> + def test_recipetool_handle_license_vars(self):
> + from create import handle_license_vars
> + from unittest.mock import Mock
> +
> + commonlicdir = get_bb_var('COMMON_LICENSE_DIR')
> +
> + d = bb.tinfoil.TinfoilDataStoreConnector
> + d.getVar = Mock(return_value=commonlicdir)
> +
> + srctree = tempfile.mkdtemp(prefix='recipetoolqa')
> + self.track_for_cleanup(srctree)
> +
> + # Multiple licenses
> + licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0']
> + for licence in licenses:
> + shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence))
> + # Duplicate license
> + shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE'))
> +
> + extravalues = {
> + # Duplicate and missing licenses
> + 'LICENSE': 'Zlib & BSD-2-Clause & Zlib',
> + 'LIC_FILES_CHKSUM': [
> + 'file://README.md;md5=0123456789abcdef0123456789abcd'
> + ]
> + }
> + lines_before = []
> + handled = []
> + licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d)
> + expected_lines_before = [
> + '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is',
> + '# your responsibility to verify that the values are complete and correct.',
> + '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib',
> + '#',
> + '# NOTE: multiple licenses have been detected; they have been separated with &',
> + '# in the LICENSE value for now since it is a reasonable assumption that all',
> + '# of the licenses apply. If instead there is a choice between the multiple',
> + '# licenses then you should change the value to separate the licenses with |',
> + '# instead of &. If there is any doubt, check the accompanying documentation',
> + '# to determine which situation is applicable.',
> + 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"',
> + 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
> + ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
> + ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n'
> + ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n'
> + ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n'
> + ' file://README.md;md5=0123456789abcdef0123456789abcd"',
> + ''
> + ]
> + self.assertEqual(lines_before, expected_lines_before)
> + expected_licvalues = [
> + ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'),
> + ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302'),
> + ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'),
> + ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'),
> + ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9')
> + ]
> + self.assertEqual(handled, [('license', expected_licvalues)])
> + self.assertEqual(extravalues, {})
> + self.assertEqual(licvalues, expected_licvalues)
> +
> +
> def test_recipetool_split_pkg_licenses(self):
> from create import split_pkg_licenses
> licvalues = [
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#159642): https://lists.openembedded.org/g/openembedded-core/message/159642
> Mute This Topic: https://lists.openembedded.org/mt/87699203/1686473
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [richard.purdie@linuxfoundation.org]
> -=-=-=-=-=-=-=-=-=-=-=-
>
The test failed in testing:
https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/2956/steps/14/logs/stdio
Cheers,
Richard
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [OE-core] [RFC PATCH v2 3/3] selftest: recipetool: Add test for handle_license_vars function
2021-12-14 13:01 ` [OE-core] " Richard Purdie
@ 2021-12-14 15:30 ` Stefan Herbrechtsmeier
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Herbrechtsmeier @ 2021-12-14 15:30 UTC (permalink / raw)
To: Richard Purdie, openembedded-core; +Cc: Stefan Herbrechtsmeier
Hi Richard,
Am 14.12.2021 um 14:01 schrieb Richard Purdie:
> On Mon, 2021-12-13 at 16:05 +0100, Stefan Herbrechtsmeier wrote:
>> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
>>
>> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
>> ---
>>
>> (no changes since v1)
>>
>> meta/lib/oeqa/selftest/cases/recipetool.py | 62 ++++++++++++++++++++++
>> 1 file changed, 62 insertions(+)
>>
>> diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
>> index 1c73b2c5e0..5330d73cbf 100644
>> --- a/meta/lib/oeqa/selftest/cases/recipetool.py
>> +++ b/meta/lib/oeqa/selftest/cases/recipetool.py
>> @@ -592,6 +592,68 @@ class RecipetoolTests(RecipetoolBase):
>> with open(srcfile, 'w') as fh:
>> fh.writelines(plugincontent)
>>
>> + def test_recipetool_handle_license_vars(self):
>> + from create import handle_license_vars
>> + from unittest.mock import Mock
>> +
>> + commonlicdir = get_bb_var('COMMON_LICENSE_DIR')
>> +
>> + d = bb.tinfoil.TinfoilDataStoreConnector
>> + d.getVar = Mock(return_value=commonlicdir)
>> +
>> + srctree = tempfile.mkdtemp(prefix='recipetoolqa')
>> + self.track_for_cleanup(srctree)
>> +
>> + # Multiple licenses
>> + licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0']
>> + for licence in licenses:
>> + shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence))
>> + # Duplicate license
>> + shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE'))
>> +
>> + extravalues = {
>> + # Duplicate and missing licenses
>> + 'LICENSE': 'Zlib & BSD-2-Clause & Zlib',
>> + 'LIC_FILES_CHKSUM': [
>> + 'file://README.md;md5=0123456789abcdef0123456789abcd'
>> + ]
>> + }
>> + lines_before = []
>> + handled = []
>> + licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d)
>> + expected_lines_before = [
>> + '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is',
>> + '# your responsibility to verify that the values are complete and correct.',
>> + '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib',
>> + '#',
>> + '# NOTE: multiple licenses have been detected; they have been separated with &',
>> + '# in the LICENSE value for now since it is a reasonable assumption that all',
>> + '# of the licenses apply. If instead there is a choice between the multiple',
>> + '# licenses then you should change the value to separate the licenses with |',
>> + '# instead of &. If there is any doubt, check the accompanying documentation',
>> + '# to determine which situation is applicable.',
>> + 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"',
>> + 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
>> + ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
>> + ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n'
>> + ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n'
>> + ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n'
>> + ' file://README.md;md5=0123456789abcdef0123456789abcd"',
>> + ''
>> + ]
>> + self.assertEqual(lines_before, expected_lines_before)
>> + expected_licvalues = [
>> + ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'),
>> + ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302'),
>> + ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'),
>> + ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'),
>> + ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9')
>> + ]
>> + self.assertEqual(handled, [('license', expected_licvalues)])
>> + self.assertEqual(extravalues, {})
>> + self.assertEqual(licvalues, expected_licvalues)
>> +
>> +
>> def test_recipetool_split_pkg_licenses(self):
>> from create import split_pkg_licenses
>> licvalues = [
>> -=-=-=-=-=-=-=-=-=-=-=-
>> Links: You receive all messages sent to this group.
>> View/Reply Online (#159642): https://lists.openembedded.org/g/openembedded-core/message/159642
>> Mute This Topic: https://lists.openembedded.org/mt/87699203/1686473
>> Group Owner: openembedded-core+owner@lists.openembedded.org
>> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [richard.purdie@linuxfoundation.org]
>> -=-=-=-=-=-=-=-=-=-=-=-
>>
>
> The test failed in testing:
>
> https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/2956/steps/14/logs/stdio
I didn't know that os.walk() is not deterministic.
I will fix it.
Regards
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-12-14 15:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 15:05 [RFC PATCH v2 1/3] recipetool: Separate licenses with & operator Stefan Herbrechtsmeier
2021-12-13 15:05 ` [RFC PATCH v2 2/3] selftest: recipetool: Add test for split_pkg_licenses function Stefan Herbrechtsmeier
2021-12-13 15:05 ` [RFC PATCH v2 3/3] selftest: recipetool: Add test for handle_license_vars function Stefan Herbrechtsmeier
2021-12-14 13:01 ` [OE-core] " Richard Purdie
2021-12-14 15:30 ` Stefan Herbrechtsmeier
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.