7 if __name__== '__main__':
8 parser = argparse.ArgumentParser()
9 parser.add_argument('input')
10 parser.add_argument('output')
11 parser.add_argument('buildroot')
13 args = parser.parse_known_args()
15 # c_args might contain things that are essential for crosscompilation, but
16 # are not included in cc.cmd_array(), so we have to look them up ourselves
18 buildroot = args[0].buildroot
19 with open(os.path.join(buildroot, 'meson-info', 'intro-buildoptions.json')) as json_file:
20 bopts = json.load(json_file)
22 if opt['name'] == 'c_args' and opt['section'] == 'compiler' and opt['machine'] == 'host':
23 host_cargs = opt['value']
27 cpp_args = [i for i in host_cargs + [args[0].input] if not i.startswith('-g')]
28 ret = subprocess.run(cpp + cpp_args, stdout=subprocess.PIPE, check=True)
30 stdout = ret.stdout.decode('utf8')
32 with open(args[0].output, 'w') as out:
34 for l in stdout.split('\n'):
36 if l.startswith('CUT_OUT_BEGIN'):
40 stripped = re.sub('^\s+', '', l)
41 stripped = re.sub('\s*,\s*', ',', stripped)
42 if not stripped.isspace() and stripped:
43 out.write('%s\n' % stripped)
45 if l.startswith('CUT_OUT_END'):