[libcxx-commits] [libcxx] [libc++] Stop using awk in transitive includes test (PR #110554)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Sep 30 14:20:14 PDT 2024
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/110554
>From 4e981c9dca56f41e1ebcf173838830b8bcf1ffeb Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 30 Sep 2024 14:51:11 -0400
Subject: [PATCH] [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.
---
libcxx/test/libcxx/transitive_includes.gen.py | 11 +++---
.../test/libcxx/transitive_includes/diff.py | 36 +++++++++++++++++++
.../libcxx/transitive_includes/expected.py | 35 ++++++++++++++++++
.../to_csv.py} | 0
4 files changed, 75 insertions(+), 7 deletions(-)
create mode 100755 libcxx/test/libcxx/transitive_includes/diff.py
create mode 100755 libcxx/test/libcxx/transitive_includes/expected.py
rename libcxx/test/libcxx/{transitive_includes_to_csv.py => transitive_includes/to_csv.py} (100%)
diff --git a/libcxx/test/libcxx/transitive_includes.gen.py b/libcxx/test/libcxx/transitive_includes.gen.py
index 22075364bf1b79..527ec7b234d0a7 100644
--- a/libcxx/test/libcxx/transitive_includes.gen.py
+++ b/libcxx/test/libcxx/transitive_includes.gen.py
@@ -55,7 +55,7 @@
print(
f"""\
-// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes_to_csv.py {' '.join(all_traces)} > %{{libcxx-dir}}/test/libcxx/transitive_includes/%{{cxx_std}}.csv
+// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/to_csv.py {' '.join(all_traces)} > %{{libcxx-dir}}/test/libcxx/transitive_includes/%{{cxx_std}}.csv
"""
)
@@ -64,9 +64,6 @@
if header.endswith(".h"): # Skip C compatibility or detail headers
continue
- # Escape slashes for the awk command below
- escaped_header = header.replace("/", "\\/")
-
print(
f"""\
//--- {header}.sh.cpp
@@ -92,9 +89,9 @@
// RUN: mkdir %t
// RUN: %{{cxx}} %s %{{flags}} %{{compile_flags}} --trace-includes -fshow-skipped-includes --preprocess > /dev/null 2> %t/trace-includes.txt
-// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes_to_csv.py %t/trace-includes.txt > %t/actual_transitive_includes.csv
-// RUN: cat %{{libcxx-dir}}/test/libcxx/transitive_includes/%{{cxx_std}}.csv | awk '/^{escaped_header} / {{ print }}' > %t/expected_transitive_includes.csv
-// RUN: diff -w %t/expected_transitive_includes.csv %t/actual_transitive_includes.csv
+// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/to_csv.py %t/trace-includes.txt > %t/actual_transitive_includes.csv
+// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/expected.py %{{cxx_std}} "{header}" > %t/expected_transitive_includes.csv
+// RUN: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/diff.py %t/expected_transitive_includes.csv %t/actual_transitive_includes.csv
#include <{header}>
"""
)
diff --git a/libcxx/test/libcxx/transitive_includes/diff.py b/libcxx/test/libcxx/transitive_includes/diff.py
new file mode 100755
index 00000000000000..c30a6a9841a31b
--- /dev/null
+++ b/libcxx/test/libcxx/transitive_includes/diff.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# ===----------------------------------------------------------------------===##
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+# ===----------------------------------------------------------------------===##
+
+import argparse
+import os
+import sys
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(
+ description="""Diff two files.""",
+ )
+ parser.add_argument("file1", default=None)
+ parser.add_argument("file2", default=None)
+ args = parser.parse_args()
+
+ def doread(f):
+ with open(f, 'r') as file:
+ content = file.read()
+ lines = [l.strip() for l in content.splitlines()]
+ return list(filter(None, lines))
+
+ content1 = doread(args.file1)
+ content2 = doread(args.file2)
+
+ for l1, l2 in zip(content1, content2):
+ if l1 != l2:
+ print("line not equal")
+ print(l1)
+ print(l2)
+ sys.exit(1)
diff --git a/libcxx/test/libcxx/transitive_includes/expected.py b/libcxx/test/libcxx/transitive_includes/expected.py
new file mode 100755
index 00000000000000..b2519f36b3974b
--- /dev/null
+++ b/libcxx/test/libcxx/transitive_includes/expected.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+# ===----------------------------------------------------------------------===##
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+# ===----------------------------------------------------------------------===##
+
+import argparse
+import os
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(
+ description="""Extract the list of expected transitive includes for the given Standard and header.""",
+ )
+ parser.add_argument(
+ "standard",
+ default=None,
+ choices=["cxx03", "cxx11", "cxx14", "cxx20", "cxx23", "cxx26"],
+ )
+ parser.add_argument(
+ "header",
+ default=None,
+ help="The header to extract the expected transitive includes for."
+ )
+ args = parser.parse_args()
+
+ CSV_ROOT = os.path.dirname(__file__)
+ filename = os.path.join(CSV_ROOT, f"{args.standard}.csv")
+ with open(filename, 'r') as f:
+ for line in f.readlines():
+ if line.startswith(args.header + ' '):
+ print(line, end='') # lines already end in newline
diff --git a/libcxx/test/libcxx/transitive_includes_to_csv.py b/libcxx/test/libcxx/transitive_includes/to_csv.py
similarity index 100%
rename from libcxx/test/libcxx/transitive_includes_to_csv.py
rename to libcxx/test/libcxx/transitive_includes/to_csv.py
More information about the libcxx-commits
mailing list