1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2021 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 optparse 18import os 19import sys 20import json 21 22sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) 23from scripts.util import build_utils # noqa: E402 24 25 26def parse_args(args): 27 parser = optparse.OptionParser() 28 29 parser.add_option( 30 '--generated-build-file', 31 help='path to generated platform build file') 32 parser.add_option( 33 '--required-build-file', help='path to required platform build file') 34 parser.add_option( 35 '--optional-build-file', help='path to optional platform build file') 36 parser.add_option( 37 '--stub-build-file', help='path to stub platform build file') 38 39 options, _ = parser.parse_args(args) 40 return options 41 42 43def do_merge(required_build_file, optional_build_file, stub_build_file, 44 generated_build_file): 45 with open(required_build_file, 'r') as required_f: 46 required = json.load(required_f) 47 with open(optional_build_file, 'r') as optional_f: 48 optional = json.load(optional_f) 49 with open(stub_build_file, 'r') as stub_f: 50 stub = json.load(stub_f) 51 52 parts = required.get('parts') + optional.get('parts') 53 stub_parts = list(set(stub.get('stub_parts')) - set(parts)) 54 55 if not os.path.exists(generated_build_file): 56 build_utils.touch(generated_build_file) 57 build_utils.write_json({ 58 'parts': parts, 59 'stub_parts': stub_parts, 60 }, 61 generated_build_file, 62 only_if_changed=True) 63 64 65def main(args): 66 options = parse_args(args) 67 do_merge(options.required_build_file, options.optional_build_file, 68 options.stub_build_file, options.generated_build_file) 69 70 71if __name__ == '__main__': 72 sys.exit(main(sys.argv[1:])) 73