1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2023 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16 17import argparse 18import os 19import sys 20import json 21 22from scripts.util import build_utils # noqa: E402 23 24 25def parse_args(args): 26 parser = argparse.ArgumentParser() 27 parser.add_argument( 28 '--generated-build-file', 29 help='path to generated platform build file') 30 parser.add_argument( 31 '--required-build-file', help='path to required platform build file') 32 parser.add_argument( 33 '--optional-build-file', help='path to optional platform build file') 34 parser.add_argument( 35 '--stub-build-file', help='path to stub platform build file') 36 options = parser.parse_args(args) 37 return options 38 39 40def do_merge(required_build_file, optional_build_file, stub_build_file, 41 generated_build_file): 42 with open(required_build_file, 'r') as required_f: 43 required = json.load(required_f) 44 with open(optional_build_file, 'r') as optional_f: 45 optional = json.load(optional_f) 46 with open(stub_build_file, 'r') as stub_f: 47 stub = json.load(stub_f) 48 49 parts = required.get('parts') + optional.get('parts') 50 stub_parts = list(set(stub.get('stub_parts')) - set(parts)) 51 52 if not os.path.exists(generated_build_file): 53 build_utils.touch(generated_build_file) 54 build_utils.write_json({ 55 'parts': parts, 56 'stub_parts': stub_parts, 57 }, 58 generated_build_file, 59 only_if_changed=True) 60 61 62def main(args): 63 options = parse_args(args) 64 do_merge(options.required_build_file, options.optional_build_file, 65 options.stub_build_file, options.generated_build_file) 66 67 68if __name__ == '__main__': 69 sys.exit(main(sys.argv[1:])) 70