Philipp Wagner | 7f9a5bb | 2020-11-19 22:59:59 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright lowRISC contributors. |
| 3 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | r"""A helper used by Meson to write an environment file |
| 6 | |
| 7 | The environment file follows Docker's `.env` file structure with key=value |
| 8 | pairs. See https://docs.docker.com/compose/env-file/#syntax-rules for details. |
| 9 | """ |
| 10 | |
| 11 | import argparse |
| 12 | import sys |
| 13 | |
| 14 | |
| 15 | def main() -> int: |
| 16 | parser = argparse.ArgumentParser( |
| 17 | description=__doc__, |
| 18 | formatter_class=argparse.RawDescriptionHelpFormatter) |
| 19 | parser.add_argument('--out-file', |
| 20 | '-o', |
| 21 | required=False, |
| 22 | type=argparse.FileType('w'), |
| 23 | default="env.txt", |
| 24 | help="Output file (default: %(default)s)") |
| 25 | parser.add_argument('key_value_pairs', |
| 26 | nargs='+', |
| 27 | type=str, |
| 28 | metavar='NAME=VALUE') |
| 29 | args = parser.parse_args() |
| 30 | |
| 31 | for arg in args.key_value_pairs: |
| 32 | print(arg, file=args.out_file) |
| 33 | |
| 34 | print("Wrote environment configuration to {!r}.".format(args.out_file.name)) |
| 35 | |
| 36 | return 0 |
| 37 | |
| 38 | |
| 39 | if __name__ == "__main__": |
| 40 | sys.exit(main()) |