blob: d1a47fe2cef7be9863516d281a3ad55d83c58504 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright (c) 2023 Project CHIP Authors
#
# 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.
import argparse
import json
import platform
_LIST_OF_PACKAGES_TO_EXCLUDE = ['fuchsia/third_party/rust/']
def include_package(package: dict) -> bool:
if 'path' in package:
path = package['path']
exclusion_match = any(
path.startswith(package_to_exclude)
for package_to_exclude in _LIST_OF_PACKAGES_TO_EXCLUDE
)
if exclusion_match:
return False
return True
def generate_new_cipd_package_json(input, output, extra):
with open(input) as ins:
packages = json.load(ins)
file_packages = packages.get('packages')
new_file_packages = [x for x in file_packages if include_package(x)]
# Extra is a list of platform:json.
# Filter it for the given platform and append any resulting packages
my_platform = platform.system().lower()
for item in extra:
inject_platform, path = item.split(':', 1)
if inject_platform.lower() != my_platform:
continue
with open(path) as ins:
for package in json.load(ins).get('packages'):
new_file_packages.append(package)
new_packages = {'packages': new_file_packages}
with open(output, 'w') as f:
json.dump(new_packages, f, indent=2)
def main():
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
'--input', '-i', required=True
)
parser.add_argument(
'--output', '-o', required=True
)
parser.add_argument(
'--extra', '-e', nargs='*', default=[],
help="Inject extra packages for specific platforms. Format is <platform>:<path_to_json>"
)
generate_new_cipd_package_json(**vars(parser.parse_args()))
if __name__ == '__main__':
main()