Files
swift-mirror/test/CrossImport/Inputs/rewrite-module-triples.py
Daniel Rodríguez Troitiño 2a7a3eb436 [windows] Use extended length paths for os.walk invocation.
In the Windows VS 2017 CI machines, the path for certain tests end up
being very long. rewrite-module-triples.py was aware and was using
extended length paths for the copy and remove operations in Windows
but it was not using it for the os.walk invocation, so when a folder
that was longer than MAX_PATH was encountered, the walk stopped
drilling into it, missing some module-triple-here substitutions and
making some test fail.

The changes remove the special treatment of the copy and remove
operations and move it into os.walk, which carries the prefix to
every path.

This should fix the problems seen in the SourceKit test in the
Windows VS 2017 machine:

- SourceKit/InterfaceGen/gen_swift_module_cross_import_common.swift
- SourceKit/DocSupport/doc_cross_import_common.swift
- SourceKit/CursorInfo/cursor_info_cross_import_common_case.swift

PD: Misc/stats_dir_profiler.swift is something else. It seems as if
an glob was not being expanded by lit for some reason.
2020-10-10 13:34:24 -07:00

51 lines
1.2 KiB
Python

#!/usr/bin/env python
"""
Renames files or directories with "module-triple-here" in their names to use
the indicated module triples instead.
"""
from __future__ import print_function
import os
import platform
import shutil
import sys
if len(sys.argv) < 3:
print('Too few args to ' + sys.argv[0])
print('Usage: rewrite-module-triples.py <root-dir> <module-triple>...')
sys.exit(1)
root_dir = sys.argv[1]
if platform.system() == 'Windows':
root_dir = "\\\\?\\" + os.path.abspath(root_dir)
triples = sys.argv[2:]
def rewritten_names(name):
if 'module-triple-here' not in name:
return []
return [name.replace('module-triple-here', triple) for triple in triples]
def rewrite(parent, names, copy_fn, rm_fn):
for name in names:
new_names = rewritten_names(name)
if not new_names:
continue
path = os.path.join(parent, name)
for new_name in new_names:
new_path = os.path.join(parent, new_name)
copy_fn(path, new_path)
rm_fn(path)
for parent, dirs, files in os.walk(root_dir, topdown=False):
rewrite(parent, dirs, shutil.copytree, shutil.rmtree)
rewrite(parent, files, shutil.copyfile, os.remove)