diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-05-30 17:29:21 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-05-31 15:17:20 +0200 |
commit | a39ae9975fbf7e85ea01ad41f3bed822281a0f74 (patch) | |
tree | c567abfe4726472ee5e9a15058488f319a5bf732 /src | |
parent | f42f5c1957e9c6ff8a61ef295b63dccead9b0ae8 (diff) | |
download | hydrilla-builder-a39ae9975fbf7e85ea01ad41f3bed822281a0f74.tar.gz hydrilla-builder-a39ae9975fbf7e85ea01ad41f3bed822281a0f74.zip |
add tests for features from version 2 of source package JSON schema
Diffstat (limited to 'src')
-rw-r--r-- | src/hydrilla/builder/build.py | 80 | ||||
-rw-r--r-- | src/hydrilla/builder/local_apt.py | 2 | ||||
-rw-r--r-- | src/hydrilla/builder/piggybacking.py | 12 | ||||
m--------- | src/hydrilla/schemas/2.x | 0 |
4 files changed, 70 insertions, 24 deletions
diff --git a/src/hydrilla/builder/build.py b/src/hydrilla/builder/build.py index 5de9351..33838f3 100644 --- a/src/hydrilla/builder/build.py +++ b/src/hydrilla/builder/build.py @@ -152,7 +152,6 @@ class Build: """ self.srcdir = srcdir.resolve() self.piggyback_files = piggyback_files - # TODO: the piggyback files we set are ignored for now; use them if piggyback_files is None: piggyback_default_path = \ srcdir.parent / f'{srcdir.name}.foreign-packages' @@ -265,20 +264,22 @@ class Build: return sha256(self.source_zip_contents).digest().hex() - def _process_item(self, item_def: dict, piggybacked: Piggybacked): + def _process_item(self, as_what: str, item_def: dict, + piggybacked: Piggybacked): """ - Process 'item_def' as definition of a resource/mapping and store in - memory its processed form and files used by it. + Process 'item_def' as definition of a resource or mapping (determined by + 'as_what' param) and store in memory its processed form and files used + by it. Return a minimal item reference suitable for using in source description. """ - copy_props = ['type', 'identifier', 'long_name', 'description'] - for prop in ('comment', 'uuid'): - if prop in item_def: - copy_props.append(prop) + resulting_schema_version = [1] - if item_def['type'] == 'resource': + copy_props = ['identifier', 'long_name', 'description', + *filter(lambda p: p in item_def, ('comment', 'uuid'))] + + if as_what == 'resource': item_list = self.resource_list copy_props.append('revision') @@ -290,7 +291,7 @@ class Build: for res_ref in item_def.get('dependencies', [])] new_item_obj = { - 'dependencies': [*piggybacked.package_must_depend, *deps], + 'dependencies': [*piggybacked.resource_must_depend, *deps], 'scripts': script_file_refs } else: @@ -304,13 +305,52 @@ class Build: 'payloads': payloads } - new_item_obj.update([(p, item_def[p]) for p in copy_props]) - new_item_obj['version'] = util.normalize_version(item_def['version']) - new_item_obj['$schema'] = f'{schemas_root}/api_{item_def["type"]}_description-1.schema.json' + + if as_what == 'mapping' and item_def['type'] == "mapping_and_resource": + new_item_obj['version'].append(item_def['revision']) + + if self.source_schema_ver >= [2]: + # handle 'required_mappings' field + required = [{'identifier': map_ref['identifier']} + for map_ref in item_def.get('required_mappings', [])] + if required: + resulting_schema_version = max(resulting_schema_version, [2]) + new_item_obj['required_mappings'] = required + + # handle 'permissions' field + permissions = item_def.get('permissions', {}) + processed_permissions = {} + + if permissions.get('cors_bypass'): + processed_permissions['cors_bypass'] = True + + if processed_permissions: + new_item_obj['permissions'] = processed_permissions + resulting_schema_version = max(resulting_schema_version, [2]) + + # handle '{min,max}_haketilo_version' fields + for minmax, default in ('min', [1]), ('max', [65536]): + constraint = item_def.get(f'{minmax}_haketilo_version') + if constraint in (None, default): + continue + + copy_props.append(f'{minmax}_haketilo_version') + resulting_schema_version = max(resulting_schema_version, [2]) + + new_item_obj.update((p, item_def[p]) for p in copy_props) + + new_item_obj['$schema'] = ''.join([ + schemas_root, + f'/api_{as_what}_description', + '-', + util.version_string(resulting_schema_version), + '.schema.json' + ]) + new_item_obj['type'] = as_what new_item_obj['source_copyright'] = self.copyright_file_refs - new_item_obj['source_name'] = self.source_name - new_item_obj['generated_by'] = generated_by + new_item_obj['source_name'] = self.source_name + new_item_obj['generated_by'] = generated_by item_list.append(new_item_obj) @@ -361,8 +401,14 @@ class Build: if generate_spdx and not spdx_ref.include_in_distribution: raise FileReferenceError(_('report_spdx_not_in_copyright_list')) - item_refs = [self._process_item(d, piggybacked) - for d in index_obj['definitions']] + item_refs = [] + for item_def in index_obj['definitions']: + if 'mapping' in item_def['type']: + ref = self._process_item('mapping', item_def, piggybacked) + item_refs.append(ref) + if 'resource' in item_def['type']: + ref = self._process_item('resource', item_def, piggybacked) + item_refs.append(ref) for file_ref in index_obj.get('additional_files', []): self._process_file(file_ref['file'], piggybacked, diff --git a/src/hydrilla/builder/local_apt.py b/src/hydrilla/builder/local_apt.py index 3bec08b..0301da2 100644 --- a/src/hydrilla/builder/local_apt.py +++ b/src/hydrilla/builder/local_apt.py @@ -428,5 +428,5 @@ def piggybacked_system(piggyback_def: dict, foreign_packages: Optional[Path]) \ archives={'apt': archives}, roots={'.apt-root': root}, package_license_files=copyright_paths, - package_must_depend=must_depend + resource_must_depend=must_depend ) diff --git a/src/hydrilla/builder/piggybacking.py b/src/hydrilla/builder/piggybacking.py index 799422d..7c03946 100644 --- a/src/hydrilla/builder/piggybacking.py +++ b/src/hydrilla/builder/piggybacking.py @@ -47,12 +47,12 @@ class Piggybacked: Store information about foreign resources in use. Public attributes: - 'package_must_depend' (read-only) + 'resource_must_depend' (read-only) 'package_license_files' (read-only) """ def __init__(self, archives: dict[str, Path]={}, roots: dict[str, Path]={}, package_license_files: list[PurePosixPath]=[], - package_must_depend: list[dict]=[]): + resource_must_depend: list[dict]=[]): """ Initialize this Piggybacked object. @@ -69,14 +69,14 @@ class Piggybacked: included with the Haketilo package that will be produced. The paths are to be resolved using 'roots' dictionary. - 'package_must_depend' lists names of Haketilo packages that the produced - package will additionally depend on. This is meant to help distribute - common licenses with a separate Haketilo package. + 'resource_must_depend' lists names of Haketilo packages that the + produced resources will additionally depend on. This is meant to help + distribute common licenses with a separate Haketilo package. """ self.archives = archives self.roots = roots self.package_license_files = package_license_files - self.package_must_depend = package_must_depend + self.resource_must_depend = resource_must_depend def resolve_file(self, file_ref_name: PurePosixPath) -> Optional[Path]: """ diff --git a/src/hydrilla/schemas/2.x b/src/hydrilla/schemas/2.x -Subproject 6b6ae219929dc1d47e1dff2a780784b78bd825b +Subproject 7f1fb9e0b68fa39c68e988b177b684d31474580 |