Skip to content

Commit 4e981c9

Browse files
committed
[libc++] Stop using awk in transitive includes test
For some reason, that doesn't work as expected on Github-hosted runners and in Docker-in-Docker setups.
1 parent df3f291 commit 4e981c9

File tree

4 files changed

+75
-7
lines changed

4 files changed

+75
-7
lines changed

libcxx/test/libcxx/transitive_includes.gen.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
print(
5757
f"""\
58-
// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes_to_csv.py {' '.join(all_traces)} > %{{libcxx-dir}}/test/libcxx/transitive_includes/%{{cxx_std}}.csv
58+
// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/to_csv.py {' '.join(all_traces)} > %{{libcxx-dir}}/test/libcxx/transitive_includes/%{{cxx_std}}.csv
5959
"""
6060
)
6161

@@ -64,9 +64,6 @@
6464
if header.endswith(".h"): # Skip C compatibility or detail headers
6565
continue
6666

67-
# Escape slashes for the awk command below
68-
escaped_header = header.replace("/", "\\/")
69-
7067
print(
7168
f"""\
7269
//--- {header}.sh.cpp
@@ -92,9 +89,9 @@
9289
9390
// RUN: mkdir %t
9491
// RUN: %{{cxx}} %s %{{flags}} %{{compile_flags}} --trace-includes -fshow-skipped-includes --preprocess > /dev/null 2> %t/trace-includes.txt
95-
// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes_to_csv.py %t/trace-includes.txt > %t/actual_transitive_includes.csv
96-
// RUN: cat %{{libcxx-dir}}/test/libcxx/transitive_includes/%{{cxx_std}}.csv | awk '/^{escaped_header} / {{ print }}' > %t/expected_transitive_includes.csv
97-
// RUN: diff -w %t/expected_transitive_includes.csv %t/actual_transitive_includes.csv
92+
// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/to_csv.py %t/trace-includes.txt > %t/actual_transitive_includes.csv
93+
// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/expected.py %{{cxx_std}} "{header}" > %t/expected_transitive_includes.csv
94+
// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/diff.py %t/expected_transitive_includes.csv %t/actual_transitive_includes.csv
9895
#include <{header}>
9996
"""
10097
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
# ===----------------------------------------------------------------------===##
3+
#
4+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
# See https://llvm.org/LICENSE.txt for license information.
6+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
#
8+
# ===----------------------------------------------------------------------===##
9+
10+
import argparse
11+
import os
12+
import sys
13+
14+
if __name__ == "__main__":
15+
parser = argparse.ArgumentParser(
16+
description="""Diff two files.""",
17+
)
18+
parser.add_argument("file1", default=None)
19+
parser.add_argument("file2", default=None)
20+
args = parser.parse_args()
21+
22+
def doread(f):
23+
with open(f, 'r') as file:
24+
content = file.read()
25+
lines = [l.strip() for l in content.splitlines()]
26+
return list(filter(None, lines))
27+
28+
content1 = doread(args.file1)
29+
content2 = doread(args.file2)
30+
31+
for l1, l2 in zip(content1, content2):
32+
if l1 != l2:
33+
print("line not equal")
34+
print(l1)
35+
print(l2)
36+
sys.exit(1)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
# ===----------------------------------------------------------------------===##
3+
#
4+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
# See https://llvm.org/LICENSE.txt for license information.
6+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
#
8+
# ===----------------------------------------------------------------------===##
9+
10+
import argparse
11+
import os
12+
13+
14+
if __name__ == "__main__":
15+
parser = argparse.ArgumentParser(
16+
description="""Extract the list of expected transitive includes for the given Standard and header.""",
17+
)
18+
parser.add_argument(
19+
"standard",
20+
default=None,
21+
choices=["cxx03", "cxx11", "cxx14", "cxx20", "cxx23", "cxx26"],
22+
)
23+
parser.add_argument(
24+
"header",
25+
default=None,
26+
help="The header to extract the expected transitive includes for."
27+
)
28+
args = parser.parse_args()
29+
30+
CSV_ROOT = os.path.dirname(__file__)
31+
filename = os.path.join(CSV_ROOT, f"{args.standard}.csv")
32+
with open(filename, 'r') as f:
33+
for line in f.readlines():
34+
if line.startswith(args.header + ' '):
35+
print(line, end='') # lines already end in newline

0 commit comments

Comments
 (0)