mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 21:54:33 +02:00
Merge branch 'bugfix/lic_header_checker' into 'master'
Tools: Allow all combinations of supported licenses in the header See merge request espressif/esp-idf!16280
This commit is contained in:
@@ -307,7 +307,7 @@ def has_valid_copyright(file_name: str, mime: str, is_on_ignore: bool, config_se
|
|||||||
if detected_licenses:
|
if detected_licenses:
|
||||||
for detected_license, line_number in detected_licenses:
|
for detected_license, line_number in detected_licenses:
|
||||||
allowed_licenses = ast.literal_eval(config_section['allowed_licenses'])
|
allowed_licenses = ast.literal_eval(config_section['allowed_licenses'])
|
||||||
if detected_license not in allowed_licenses:
|
if not allowed_license_combination(detected_license, allowed_licenses):
|
||||||
valid = False
|
valid = False
|
||||||
print(f'{TERMINAL_RED}{file_name}:{line_number} License "{detected_license}" is not allowed! Allowed licenses: {allowed_licenses}.')
|
print(f'{TERMINAL_RED}{file_name}:{line_number} License "{detected_license}" is not allowed! Allowed licenses: {allowed_licenses}.')
|
||||||
|
|
||||||
@@ -523,6 +523,22 @@ def debug_output(args: argparse.Namespace, config: configparser.ConfigParser) ->
|
|||||||
print(f' {key}: "{config[section][key]}"')
|
print(f' {key}: "{config[section][key]}"')
|
||||||
|
|
||||||
|
|
||||||
|
def allowed_license_combination(license_to_match: str, all_licenses: List[str]) -> bool:
|
||||||
|
"""
|
||||||
|
Licenses can be combined together with the OR keyword. Therefore, a simple "in" lookup in a list is not enough.
|
||||||
|
For example, if "A" and "B" are supported then "A OR B" and "B OR A" should be supported as well.
|
||||||
|
"""
|
||||||
|
if license_to_match in all_licenses:
|
||||||
|
# This is the simple case, for example, when "A" is used from the list ["A", "B"]
|
||||||
|
return True
|
||||||
|
|
||||||
|
# for example, if license_to_match is "A OR B" then the following split will be ["A", "B"]
|
||||||
|
split_list = [sp for sp in map(str.strip, license_to_match.split(' OR ')) if len(sp) > 0]
|
||||||
|
|
||||||
|
# for example, "A" and "B" needs to be in the supported list in order to match "A OR B".
|
||||||
|
return all(i in all_licenses for i in split_list)
|
||||||
|
|
||||||
|
|
||||||
def verify_config(config: configparser.ConfigParser) -> None:
|
def verify_config(config: configparser.ConfigParser) -> None:
|
||||||
fail = False
|
fail = False
|
||||||
for section in config:
|
for section in config:
|
||||||
@@ -530,7 +546,7 @@ def verify_config(config: configparser.ConfigParser) -> None:
|
|||||||
|
|
||||||
# configparser stores all values as strings
|
# configparser stores all values as strings
|
||||||
allowed_licenses = ast.literal_eval(config[section]['allowed_licenses'])
|
allowed_licenses = ast.literal_eval(config[section]['allowed_licenses'])
|
||||||
if license_for_new_files not in allowed_licenses:
|
if not allowed_license_combination(license_for_new_files, allowed_licenses):
|
||||||
print(f'Invalid config, section "{section}":\nDefault license for new files '
|
print(f'Invalid config, section "{section}":\nDefault license for new files '
|
||||||
f'({license_for_new_files}) is not on the allowed licenses list {allowed_licenses}.')
|
f'({license_for_new_files}) is not on the allowed licenses list {allowed_licenses}.')
|
||||||
fail = True
|
fail = True
|
||||||
|
@@ -53,7 +53,8 @@ examples_and_unit_tests:
|
|||||||
- 'components/**/test/**'
|
- 'components/**/test/**'
|
||||||
allowed_licenses:
|
allowed_licenses:
|
||||||
- Apache-2.0
|
- Apache-2.0
|
||||||
- Unlicense OR CC0-1.0
|
- Unlicense
|
||||||
|
- CC0-1.0
|
||||||
license_for_new_files: Unlicense OR CC0-1.0
|
license_for_new_files: Unlicense OR CC0-1.0
|
||||||
|
|
||||||
# files matching this section do not perform the check
|
# files matching this section do not perform the check
|
||||||
|
Reference in New Issue
Block a user