| #!/usr/bin/env python3 |
| |
| # Copyright 2023 Google LLC |
| # |
| # 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 |
| # |
| # https://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. |
| |
| """Build kernel config for EdgeOS""" |
| import argparse |
| import os |
| import sys |
| |
| |
| def readconfig(filename): |
| config = {} |
| with open(filename) as f: |
| line = f.readline() |
| while line: |
| if not line.startswith('#') and '=' in line: |
| split = line.split('=') |
| config[split[0]] = split[1][:-1] # Remove newline |
| line = f.readline() |
| return config |
| |
| |
| def main(): |
| parser = argparse.ArgumentParser(description='Generate a kernel config') |
| parser.add_argument('--base', help='Base kernel config.', required=True) |
| parser.add_argument( |
| '--verify', |
| help='Verify all requested arguments appear in given file.', |
| default='', |
| ) |
| parser.add_argument( |
| 'dirs', |
| help='Directories to search for additional .config files', nargs='*' |
| ) |
| |
| args = parser.parse_args() |
| config = readconfig(args.base) |
| for d in args.dirs: |
| for root, _, files in os.walk(d): |
| for f in sorted(files): |
| if f.endswith('.config'): |
| config.update(readconfig(os.path.join(root, f))) |
| config = {k: v for k, v in config.items() if v != 'n'} |
| if args.verify: |
| verify_config = readconfig(args.verify) |
| missing = len(config) - len(verify_config) |
| if missing > 0: |
| print('Desired kernel configs missing in final config:') |
| print(missing) |
| sys.exit(1) |
| else: |
| for k, v in sorted(config.items()): |
| print('%s=%s' % (k, v)) |
| |
| |
| if __name__ == '__main__': |
| main() |