1*1d3556b8SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*1d3556b8SAndroid Build Coastguard Worker# 3*1d3556b8SAndroid Build Coastguard Worker# Copyright (C) 2020 The Android Open Source Project 4*1d3556b8SAndroid Build Coastguard Worker# 5*1d3556b8SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*1d3556b8SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*1d3556b8SAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*1d3556b8SAndroid Build Coastguard Worker# 9*1d3556b8SAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*1d3556b8SAndroid Build Coastguard Worker# 11*1d3556b8SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*1d3556b8SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*1d3556b8SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*1d3556b8SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*1d3556b8SAndroid Build Coastguard Worker# limitations under the License. 16*1d3556b8SAndroid Build Coastguard Worker# 17*1d3556b8SAndroid Build Coastguard Worker 18*1d3556b8SAndroid Build Coastguard Worker""" 19*1d3556b8SAndroid Build Coastguard WorkerCreates new kernel configs for the next compatibility matrix. 20*1d3556b8SAndroid Build Coastguard Worker""" 21*1d3556b8SAndroid Build Coastguard Worker 22*1d3556b8SAndroid Build Coastguard Workerimport argparse 23*1d3556b8SAndroid Build Coastguard Workerimport datetime 24*1d3556b8SAndroid Build Coastguard Workerimport os 25*1d3556b8SAndroid Build Coastguard Workerimport shutil 26*1d3556b8SAndroid Build Coastguard Workerimport subprocess 27*1d3556b8SAndroid Build Coastguard Worker 28*1d3556b8SAndroid Build Coastguard Workerdef check_call(*args, **kwargs): 29*1d3556b8SAndroid Build Coastguard Worker print(args[0]) 30*1d3556b8SAndroid Build Coastguard Worker subprocess.check_call(*args, **kwargs) 31*1d3556b8SAndroid Build Coastguard Worker 32*1d3556b8SAndroid Build Coastguard Workerdef replace_configs_module_name(current_release, new_release, file_path): 33*1d3556b8SAndroid Build Coastguard Worker # TODO(b/355580919): Remove the pattern '[0-9]+\\.next' by replacing the 34*1d3556b8SAndroid Build Coastguard Worker # version placeholder with 'next'. 35*1d3556b8SAndroid Build Coastguard Worker check_call("sed -i'' -E 's/\"kernel_config_{}_([0-9]+\\.[0-9]+|[0-9]+\\.next|next)\"/\"kernel_config_{}_\\1\"/g' {}" 36*1d3556b8SAndroid Build Coastguard Worker .format(current_release, new_release, file_path), shell=True) 37*1d3556b8SAndroid Build Coastguard Worker 38*1d3556b8SAndroid Build Coastguard Workerclass Bump(object): 39*1d3556b8SAndroid Build Coastguard Worker def __init__(self, cmdline_args): 40*1d3556b8SAndroid Build Coastguard Worker top = os.environ["ANDROID_BUILD_TOP"] 41*1d3556b8SAndroid Build Coastguard Worker self.current_release = cmdline_args.current 42*1d3556b8SAndroid Build Coastguard Worker self.new_release = cmdline_args.next 43*1d3556b8SAndroid Build Coastguard Worker self.configs_dir = os.path.join(top, "kernel/configs") 44*1d3556b8SAndroid Build Coastguard Worker self.current_release_dir = os.path.join(self.configs_dir, self.current_release) 45*1d3556b8SAndroid Build Coastguard Worker self.new_release_dir = os.path.join(self.configs_dir, self.new_release) 46*1d3556b8SAndroid Build Coastguard Worker self.versions = [e for e in os.listdir(self.current_release_dir) if e.startswith("android-")] 47*1d3556b8SAndroid Build Coastguard Worker 48*1d3556b8SAndroid Build Coastguard Worker def run(self): 49*1d3556b8SAndroid Build Coastguard Worker shutil.copytree(self.current_release_dir, self.new_release_dir) 50*1d3556b8SAndroid Build Coastguard Worker for version in self.versions: 51*1d3556b8SAndroid Build Coastguard Worker dst = os.path.join(self.new_release_dir, version) 52*1d3556b8SAndroid Build Coastguard Worker for file_name in os.listdir(dst): 53*1d3556b8SAndroid Build Coastguard Worker abs_path = os.path.join(dst, file_name) 54*1d3556b8SAndroid Build Coastguard Worker if not os.path.isfile(abs_path): 55*1d3556b8SAndroid Build Coastguard Worker continue 56*1d3556b8SAndroid Build Coastguard Worker year = datetime.datetime.now().year 57*1d3556b8SAndroid Build Coastguard Worker check_call("sed -i'' -E 's/Copyright \\(C\\) [0-9]{{4,}}/Copyright (C) {}/g' {}".format(year, abs_path), shell=True) 58*1d3556b8SAndroid Build Coastguard Worker replace_configs_module_name(self.current_release, self.new_release, abs_path) 59*1d3556b8SAndroid Build Coastguard Worker if os.path.basename(abs_path) == "Android.bp": 60*1d3556b8SAndroid Build Coastguard Worker if shutil.which("bpfmt") is not None: 61*1d3556b8SAndroid Build Coastguard Worker check_call("bpfmt -w {}".format(abs_path), shell=True) 62*1d3556b8SAndroid Build Coastguard Worker else: 63*1d3556b8SAndroid Build Coastguard Worker print("bpfmt is not available so {} is not being formatted. Try `m bpfmt` first".format(abs_path)) 64*1d3556b8SAndroid Build Coastguard Worker 65*1d3556b8SAndroid Build Coastguard Workerdef main(): 66*1d3556b8SAndroid Build Coastguard Worker parser = argparse.ArgumentParser(description=__doc__) 67*1d3556b8SAndroid Build Coastguard Worker parser.add_argument('current', type=str, help='name of the current version (e.g. v)') 68*1d3556b8SAndroid Build Coastguard Worker parser.add_argument('next', type=str, help='name of the next version (e.g. w)') 69*1d3556b8SAndroid Build Coastguard Worker cmdline_args = parser.parse_args() 70*1d3556b8SAndroid Build Coastguard Worker 71*1d3556b8SAndroid Build Coastguard Worker Bump(cmdline_args).run() 72*1d3556b8SAndroid Build Coastguard Worker 73*1d3556b8SAndroid Build Coastguard Workerif __name__ == '__main__': 74*1d3556b8SAndroid Build Coastguard Worker main() 75