4 # Copyright (c) 2021 Project CHIP Authors
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
24 GN_SPECIAL_CHARACTERS = r'(["$\\])'
26 '-fno-asynchronous-unwind-tables',
29 '-fno-reorder-functions',
30 '-ffunction-sections',
37 def escape_strings(gn_args):
38 return [[key, re.sub(GN_SPECIAL_CHARACTERS, r'\\\1', value)] for key, value in gn_args]
40 def write_gn_args(args):
42 sys.stdout.write('import("{}")\n'.format(args.module))
44 for key, value in args.arg:
45 sys.stdout.write('{} = {}\n'.format(key, value))
47 for key, value in args.arg_string:
48 sys.stdout.write('{} = "{}"\n'.format(key, value))
50 cflag_excludes = ', '.join(['"{}"'.format(exclude) for exclude in GN_CFLAG_EXCLUDES])
52 for key, value in args.arg_cflags:
53 sys.stdout.write('{} = filter_exclude(string_split("{}"), [{}])\n'.format(key, value, cflag_excludes))
56 parser = argparse.ArgumentParser()
57 parser.add_argument('--module', action='store')
58 parser.add_argument('--arg', action='append', nargs=2, default=[])
59 parser.add_argument('--arg-string', action='append', nargs=2, default=[])
60 parser.add_argument('--arg-cflags', action='append', nargs=2, default=[])
61 args = parser.parse_args()
62 args.arg_string = escape_strings(args.arg_string)
63 args.arg_cflags = escape_strings(args.arg_cflags)
66 if __name__ == "__main__":