[libcxx-commits] [PATCH] D129428: [libcxx] [test] Fix the transitive_includes test on Windows

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jul 9 13:58:26 PDT 2022


mstorsjo created this revision.
mstorsjo added a reviewer: ldionne.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

The binary-mode writing to stdout can probably be written in different
ways - even though it's not as elegant as the original.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129428

Files:
  libcxx/test/libcxx/transitive_includes.sanitize.py
  libcxx/test/libcxx/transitive_includes.sh.cpp


Index: libcxx/test/libcxx/transitive_includes.sh.cpp
===================================================================
--- libcxx/test/libcxx/transitive_includes.sh.cpp
+++ libcxx/test/libcxx/transitive_includes.sh.cpp
@@ -31,8 +31,8 @@
 // This test uses --trace-includes, which is not supported by GCC.
 // UNSUPPORTED: gcc
 
-// This test doesn't work on AIX or Windows, but it should. Needs investigation.
-// XFAIL: buildhost=aix, buildhost=windows
+// This test doesn't work on AIX, but it should. Needs investigation.
+// XFAIL: buildhost=aix
 
 // This test is not supported when we remove the transitive includes provided for backwards
 // compatibility. When we bulk-remove them, we'll adjust the includes that are expected by
Index: libcxx/test/libcxx/transitive_includes.sanitize.py
===================================================================
--- libcxx/test/libcxx/transitive_includes.sanitize.py
+++ libcxx/test/libcxx/transitive_includes.sanitize.py
@@ -17,11 +17,16 @@
 
 headers = []
 for line in sys.stdin.readlines():
-  match = re.search('c\+\+/v[0-9]+/(.+)', line)
+  # On Windows, the path separators can either be forward slash or backslash.
+  # If it is a backslash, Clang prints it escaped as two consecutive
+  # backslashes, and they need to be escaped in the RE. (Use a raw string for
+  # the pattern to avoid needing another level of escaping on the Python string
+  # literal level.)
+  match = re.search(r'c\+\+(/|\\\\)v[0-9]+(/|\\\\)(.+)', line)
   if not match:
     continue
 
-  header = match.group(1)
+  header = match.group(3)
   if os.path.basename(header).endswith('.h'): # Skip C headers
     continue
 
@@ -30,4 +35,7 @@
 
   headers.append(header)
 
-print('\n'.join(sorted(set(headers))))
+# Write the output to stdout in binary mode, with '\n' linebreaks on all
+# platforms.
+sys.stdout.buffer.write(bytes('\n'.join(sorted(set(headers))), 'ascii'))
+sys.stdout.buffer.write(b'\n')


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129428.443458.patch
Type: text/x-patch
Size: 1939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220709/12669373/attachment.bin>


More information about the libcxx-commits mailing list