Skip to content

Commit adc995f

Browse files
authored
Merge pull request #80106 from etcwilde/ewilde/stdlib-resync-refactor
[CMake] Refactor resync script individual file copying
2 parents c74c2d6 + 960779f commit adc995f

File tree

1 file changed

+68
-108
lines changed

1 file changed

+68
-108
lines changed

Runtimes/Resync.cmake

+68-108
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,67 @@ cmake_minimum_required(VERSION 3.21)
88
# Where the standard library lives today
99
set(StdlibSources "${CMAKE_CURRENT_LIST_DIR}/../stdlib")
1010

11-
message(STATUS "Source dir: ${StdlibSources}")
12-
13-
# Copy the files under the "name" directory in the standard library into the new
14-
# location under Runtimes
15-
function(copy_library_sources name from_prefix to_prefix)
16-
message(STATUS "${name}[${StdlibSources}/${from_prefix}/${name}] -> ${to_prefix}/${name} ")
11+
# Copy a list of files
12+
function(copy_files from_prefix to_prefix)
13+
cmake_parse_arguments(ARG "" "ROOT" "FILES" ${ARGN})
14+
if(NOT ARG_ROOT)
15+
set(ARG_ROOT ${StdlibSources})
16+
endif()
1717

1818
set(full_to_prefix "${CMAKE_CURRENT_LIST_DIR}/${to_prefix}")
1919

20-
file(GLOB_RECURSE filenames
21-
FOLLOW_SYMLINKS
22-
LIST_DIRECTORIES FALSE
23-
RELATIVE "${StdlibSources}/${from_prefix}"
24-
"${StdlibSources}/${from_prefix}/${name}/*.swift"
25-
"${StdlibSources}/${from_prefix}/${name}/*.h"
26-
"${StdlibSources}/${from_prefix}/${name}/*.cpp"
27-
"${StdlibSources}/${from_prefix}/${name}/*.c"
28-
"${StdlibSources}/${from_prefix}/${name}/*.mm"
29-
"${StdlibSources}/${from_prefix}/${name}/*.m"
30-
"${StdlibSources}/${from_prefix}/${name}/*.def"
31-
"${StdlibSources}/${from_prefix}/${name}/*.gyb"
32-
"${StdlibSources}/${from_prefix}/${name}/*.apinotes"
33-
"${StdlibSources}/${from_prefix}/${name}/*.yaml"
34-
"${StdlibSources}/${from_prefix}/${name}/*.inc"
35-
"${StdlibSources}/${from_prefix}/${name}/*.modulemap"
36-
"${StdlibSources}/${from_prefix}/${name}/*.json")
37-
38-
foreach(file ${filenames})
20+
foreach(file ${ARG_FILES})
3921
# Get and create the directory
4022
get_filename_component(dirname ${file} DIRECTORY)
4123
file(MAKE_DIRECTORY "${full_to_prefix}/${dirname}")
4224
file(COPY_FILE
43-
"${StdlibSources}/${from_prefix}/${file}" # From
25+
"${ARG_ROOT}/${from_prefix}/${file}" # From
4426
"${full_to_prefix}/${file}" # To
4527
RESULT _output
4628
ONLY_IF_DIFFERENT)
4729
if(_output)
4830
message(SEND_ERROR
49-
"Copy ${from_prefix}/${file} -> ${full_to_prefix}/${file} Failed: ${_output}")
31+
"Copy ${ARG_ROOT}/${from_prefix}/${file} -> ${full_to_prefix}/${file} Failed: ${_output}")
5032
endif()
5133
endforeach()
5234
endfunction()
5335

36+
# Copy the files under the "name" directory in the standard library into the new
37+
# location under Runtimes
38+
function(copy_library_sources name from_prefix to_prefix)
39+
cmake_parse_arguments(ARG "" "ROOT" "" ${ARGN})
40+
41+
if(NOT ARG_ROOT)
42+
set(ARG_ROOT ${StdlibSources})
43+
endif()
44+
45+
message(STATUS "${name}[${ARG_ROOT}/${from_prefix}/${name}] -> ${to_prefix}/${name} ")
46+
47+
set(full_to_prefix "${CMAKE_CURRENT_LIST_DIR}/${to_prefix}")
48+
49+
file(GLOB_RECURSE filenames
50+
FOLLOW_SYMLINKS
51+
LIST_DIRECTORIES FALSE
52+
RELATIVE "${ARG_ROOT}/${from_prefix}"
53+
"${ARG_ROOT}/${from_prefix}/${name}/*.swift"
54+
"${ARG_ROOT}/${from_prefix}/${name}/*.h"
55+
"${ARG_ROOT}/${from_prefix}/${name}/*.cpp"
56+
"${ARG_ROOT}/${from_prefix}/${name}/*.c"
57+
"${ARG_ROOT}/${from_prefix}/${name}/*.mm"
58+
"${ARG_ROOT}/${from_prefix}/${name}/*.m"
59+
"${ARG_ROOT}/${from_prefix}/${name}/*.def"
60+
"${ARG_ROOT}/${from_prefix}/${name}/*.gyb"
61+
"${ARG_ROOT}/${from_prefix}/${name}/*.apinotes"
62+
"${ARG_ROOT}/${from_prefix}/${name}/*.yaml"
63+
"${ARG_ROOT}/${from_prefix}/${name}/*.inc"
64+
"${ARG_ROOT}/${from_prefix}/${name}/*.modulemap"
65+
"${ARG_ROOT}/${from_prefix}/${name}/*.json")
66+
67+
copy_files("${from_prefix}" "${to_prefix}"
68+
ROOT "${ARG_ROOT}"
69+
FILES ${filenames})
70+
endfunction()
71+
5472
# Directories in the existing standard library that make up the Core project
5573

5674
# Copy shared core headers
@@ -59,63 +77,6 @@ copy_library_sources(include "" "Core")
5977
# Copy magic linker symbols
6078
copy_library_sources("linker-support" "" "Core")
6179

62-
# Copy Plist
63-
message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Core/Info.plist.in")
64-
file(COPY_FILE
65-
"${StdlibSources}/Info.plist.in" # From
66-
"${CMAKE_CURRENT_LIST_DIR}/Core/Info.plist.in" # To
67-
RESULT _output
68-
ONLY_IF_DIFFERENT)
69-
if(_output)
70-
message(SEND_ERROR
71-
"Copy ${StdlibSources}/Info.plist.in] -> Core/Info.plist.in Failed: ${_output}")
72-
endif()
73-
74-
# Copy Windows clang overlays
75-
message(STATUS "modulemap[${StdlibSources}/Windows/ucrt.modulemap] -> Overlay/Windows/clang")
76-
file(COPY_FILE
77-
"${StdlibSources}/public/Platform/ucrt.modulemap" # From
78-
"${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang/ucrt.modulemap" # To
79-
RESULT _output
80-
ONLY_IF_DIFFERENT)
81-
if(_output)
82-
message(SEND_ERROR
83-
"Copy ${StdlibSources}/public/Platform/ucrt.modulemap -> Overlay/Windows/clang/ucrt.modulemap Failed: ${_output}")
84-
endif()
85-
86-
message(STATUS "modulemap[${StdlibSources}/Windows/winsdk.modulemap] -> Overlay/Windows/clang")
87-
file(COPY_FILE
88-
"${StdlibSources}/public/Platform/winsdk.modulemap" # From
89-
"${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang/winsdk.modulemap" # To
90-
RESULT _output
91-
ONLY_IF_DIFFERENT)
92-
if(_output)
93-
message(SEND_ERROR
94-
"Copy ${StdlibSources}/public/Platform/winsdk.modulemap -> Overlay/Windows/clang/winsdk.modulemap Failed: ${_output}")
95-
endif()
96-
97-
message(STATUS "modulemap[${StdlibSources}/Windows/vcruntime.modulemap] -> Overlay/Windows/clang")
98-
file(COPY_FILE
99-
"${StdlibSources}/public/Platform/vcruntime.modulemap" # From
100-
"${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang/vcruntime.modulemap" # To
101-
RESULT _output
102-
ONLY_IF_DIFFERENT)
103-
if(_output)
104-
message(SEND_ERROR
105-
"Copy ${StdlibSources}/public/Platform/vcruntime.modulemap -> Overlay/Windows/clang/vcruntime.modulemap Failed: ${_output}")
106-
endif()
107-
108-
message(STATUS "APINotes[${StdlibSources}/Windows/vcruntime.apinotes] -> Overlay/Windows/clang")
109-
file(COPY_FILE
110-
"${StdlibSources}/public/Platform/vcruntime.apinotes" # From
111-
"${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang/vcruntime.apinotes" # To
112-
RESULT _output
113-
ONLY_IF_DIFFERENT)
114-
if(_output)
115-
message(SEND_ERROR
116-
"Copy ${StdlibSources}/public/Platform/vcruntime.apinotes -> Overlay/Windows/clang/vcruntime.modulemap Failed: ${_output}")
117-
endif()
118-
11980
set(CoreLibs
12081
LLVMSupport
12182
SwiftShims
@@ -128,36 +89,35 @@ set(CoreLibs
12889
Concurrency
12990
Concurrency/InternalShims)
13091

131-
# Add these as we get them building
132-
# Demangling
133-
13492
foreach(library ${CoreLibs})
13593
copy_library_sources(${library} "public" "Core")
13694
endforeach()
13795

138-
message(STATUS "CRT[${StdlibSources}/public/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/CRT")
139-
foreach(file ucrt.swift Platform.swift POSIXError.swift TiocConstants.swift tgmath.swift.gyb)
140-
file(COPY_FILE
141-
"${StdlibSources}/public/Platform/${file}"
142-
"${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/CRT/${file}"
143-
RESULT _output
144-
ONLY_IF_DIFFERENT)
145-
if(_output)
146-
message(SEND_ERROR
147-
"Copy Platform/${file} -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/CRT/${file} Failed: ${_output}")
148-
endif()
149-
endforeach()
96+
message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Core/Info.plist.in")
97+
copy_files("" "Core" FILES "Info.plist.in")
15098

99+
# Platform Overlays
100+
101+
# Windows Overlay
151102
message(STATUS "WinSDK[${StdlibSources}/public/Windows] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/WinSDK")
152-
file(COPY_FILE
153-
"${StdlibSources}/public/Windows/WinSDK.swift"
154-
"${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/WinSDK/WinSDK.swift"
155-
RESULT _output
156-
ONLY_IF_DIFFERENT)
157-
if(_output)
158-
message(SEND_ERROR
159-
"Copy Windows/WinSDK.swift -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/WinSDK/WinSDK.swift Failed: ${_output}")
160-
endif()
103+
copy_files(public/Windows Overlay/Windows/WinSDK FILES WinSDK.swift)
104+
105+
message(STATUS "Windows Modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang")
106+
copy_files(public/Platform Overlay/Windows/clang
107+
FILES
108+
ucrt.modulemap
109+
winsdk.modulemap
110+
vcruntime.modulemap
111+
vcruntime.apinotes)
112+
113+
message(STATUS "CRT[${StdlibSources}/public/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/CRT")
114+
copy_files(public/Platform Overlay/Windows/CRT
115+
FILES
116+
ucrt.swift
117+
Platform.swift
118+
POSIXError.swift
119+
TiocConstants.swift
120+
tgmath.swift.gyb)
161121

162122
# TODO: Add source directories for the platform overlays, supplemental
163123
# libraries, and test support libraries.

0 commit comments

Comments
 (0)