blob: 75420d980854307fb037694de2222b7903437053 [file] [log] [blame]
Philipp Wagner7f9a5bb2020-11-19 22:59:59 +00001#!/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
5r"""A helper used by Meson to write an environment file
6
7The environment file follows Docker's `.env` file structure with key=value
8pairs. See https://docs.docker.com/compose/env-file/#syntax-rules for details.
9"""
10
11import argparse
12import sys
13
14
15def 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
39if __name__ == "__main__":
40 sys.exit(main())