xref: /xnu-12377.41.6/tests/unit/tools/quote_defines.py (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1#!/usr/bin/env python3
2import sys
3
4# read a .CFLAGS file and print the appropriately quoted clang command line arguments
5def main():
6    in_path = sys.argv[1]
7    line = open(in_path).read()
8    # split by " -" (with space) to avoid issue with paths that contain dashes
9    dash_split = line.split(' -')
10    output = []
11    # change ' -DX=y z' to ' -DX="y z"'
12    for i, s in enumerate(dash_split):
13        if i == 0:
14            continue # skip the clang executable
15        if '=' in s:
16            st = s.strip()
17            eq_sp = st.split('=')
18            if ' ' in eq_sp[1]:
19                output.append(f'-{eq_sp[0]}="{eq_sp[1]}"')
20                continue
21
22        output.append(f"-{s}")
23    print(" ".join(output))
24
25
26if __name__ == "__main__":
27    sys.exit(main())
28