[libcxx-commits] [libcxx] [llvm] [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:07:30 PDT 2024
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/110554
>From 78d67e13a83c3a0e899c9a318fe3b8dff647c018 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 1/3] [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 | 9 ++---
.../libcxx/transitive_includes/expected.py | 35 +++++++++++++++++++
.../to_csv.py} | 0
3 files changed, 38 insertions(+), 6 deletions(-)
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..f9a868128c6c83 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,8 +89,8 @@
// 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: %{{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: diff -w %t/expected_transitive_includes.csv %t/actual_transitive_includes.csv
#include <{header}>
"""
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
>From 27370baf43d66b436ede791dcf7d55dc19a0633b Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 30 Sep 2024 14:57:28 -0400
Subject: [PATCH 2/3] TMP: Try running job on Github-hosted runner to surface
the issue
---
.github/workflows/libcxx-build-and-test.yaml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml
index b5e60781e00064..831db85ca8e5c2 100644
--- a/.github/workflows/libcxx-build-and-test.yaml
+++ b/.github/workflows/libcxx-build-and-test.yaml
@@ -49,7 +49,9 @@ env:
jobs:
stage1:
if: github.repository_owner == 'llvm'
- runs-on: libcxx-runners-8-set
+ runs-on: ubuntu-latest
+ container:
+ image: ghcr.io/libcxx/actions-builder:fozzie-live
continue-on-error: false
strategy:
fail-fast: false
>From bbeecef199346c6be5c656fc9e06e9d890cf8c38 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 30 Sep 2024 15:23:20 -0400
Subject: [PATCH 3/3] Shot in the dark: is the problem that we're reading the
expcted file concurrently?
---
.github/workflows/libcxx-build-and-test.yaml | 6 ----
libcxx/test/libcxx/transitive_includes.gen.py | 2 +-
.../test/libcxx/transitive_includes/diff.py | 36 +++++++++++++++++++
libcxx/utils/ci/run-buildbot | 1 +
4 files changed, 38 insertions(+), 7 deletions(-)
create mode 100755 libcxx/test/libcxx/transitive_includes/diff.py
diff --git a/.github/workflows/libcxx-build-and-test.yaml b/.github/workflows/libcxx-build-and-test.yaml
index 831db85ca8e5c2..d82298f8505f8b 100644
--- a/.github/workflows/libcxx-build-and-test.yaml
+++ b/.github/workflows/libcxx-build-and-test.yaml
@@ -58,15 +58,9 @@ jobs:
matrix:
config: [
'generic-cxx03',
- 'generic-cxx26',
- 'generic-modules'
]
cc: [ 'clang-19' ]
cxx: [ 'clang++-19' ]
- include:
- - config: 'generic-gcc'
- cc: 'gcc-14'
- cxx: 'g++-14'
steps:
- uses: actions/checkout at v4
- name: ${{ matrix.config }}.${{ matrix.cxx }}
diff --git a/libcxx/test/libcxx/transitive_includes.gen.py b/libcxx/test/libcxx/transitive_includes.gen.py
index f9a868128c6c83..527ec7b234d0a7 100644
--- a/libcxx/test/libcxx/transitive_includes.gen.py
+++ b/libcxx/test/libcxx/transitive_includes.gen.py
@@ -91,7 +91,7 @@
// 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: %{{python}} %{{libcxx-dir}}/test/libcxx/transitive_includes/expected.py %{{cxx_std}} "{header}" > %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/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/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index b0533cb9a49c93..fee9b6d5946ea8 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -267,6 +267,7 @@ check-generated-output)
generic-cxx03)
clean
generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-cxx03.cmake"
+ ${MONOREPO_ROOT}/libcxx/utils/libcxx-lit "${BUILD_DIR}" --show-all libcxx/test/libcxx/transitive_includes.gen.py
check-runtimes
check-abi-list
;;
More information about the libcxx-commits
mailing list