Skip to content

Commit 941a449

Browse files
authored
Merge pull request #8268 from erg/swiftenv-fixes
swiftenv-script: Fix some issues with swiftenvs.
2 parents c896600 + 351a515 commit 941a449

File tree

5 files changed

+29
-111
lines changed

5 files changed

+29
-111
lines changed

utils/build-script

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,6 @@ class BuildScriptInvocation(object):
611611
"--darwin-deployment-version-watchos=%s" % (
612612
args.darwin_deployment_version_watchos),
613613
"--cmake", toolchain.cmake,
614-
"--cmake-c-compiler", toolchain.cc,
615-
"--cmake-cxx-compiler", toolchain.cxx,
616614
"--cmark-build-type", args.cmark_build_variant,
617615
"--llvm-build-type", args.llvm_build_variant,
618616
"--swift-build-type", args.swift_build_variant,
@@ -1062,10 +1060,6 @@ def handle_swiftenv_args(args):
10621060
sys.exit(2) # 2 is the same as `argparse` error exit code.
10631061

10641062
if args.swiftenv_path is not None:
1065-
# mkdir the swiftenv_path
1066-
if not os.path.exists(args.swiftenv_path):
1067-
os.makedirs(args.swiftenv_path)
1068-
10691063
# Only use swiftenv_make/swiftenv_script if one is provided
10701064
# utils/swiftenv-make is default
10711065
if args.swiftenv_make is None:
@@ -2046,19 +2040,6 @@ iterations with -O",
20462040
"directory.".format(android.adb.commands.DEVICE_TEMP_DIR),
20472041
default=android.adb.commands.DEVICE_TEMP_DIR,
20482042
metavar="PATH")
2049-
2050-
parser.add_argument(
2051-
"--cmake-c-compiler",
2052-
help="the absolute path to CC, the 'clang' compiler for the host "
2053-
"platform. Default is auto detected.",
2054-
type=arguments.type.executable,
2055-
metavar="PATH")
2056-
parser.add_argument(
2057-
"--cmake-cxx-compiler",
2058-
help="the absolute path to CXX, the 'clang++' compiler for the host "
2059-
"platform. Default is auto detected.",
2060-
type=arguments.type.executable,
2061-
metavar="PATH")
20622043
parser.add_argument(
20632044
"--swiftenv-path",
20642045
help="the absolute path to a directory containing replacement compiler commands")
@@ -2247,19 +2228,6 @@ iterations with -O",
22472228
# Abstracted swiftenv_args for --preset and not
22482229
handle_swiftenv_args(args)
22492230

2250-
# Let args.cmake_c_compiler win over swiftenv's cc/cxx
2251-
if args.cmake_c_compiler is None and args.swiftenv_path is not None:
2252-
if os.path.exists(args.swiftenv_path + "/clang"):
2253-
args.cmake_c_compiler = args.swiftenv_path + "/clang"
2254-
if args.cmake_cxx_compiler is None and args.swiftenv_path is not None:
2255-
if os.path.exists(args.swiftenv_path + "/clang++"):
2256-
args.cmake_cxx_compiler = args.swiftenv_path + "/clang++"
2257-
2258-
if args.cmake_c_compiler is not None:
2259-
toolchain.cc = args.cmake_c_compiler
2260-
if args.cmake_cxx_compiler is not None:
2261-
toolchain.cxx = args.cmake_cxx_compiler
2262-
22632231
if args.cmake is not None:
22642232
toolchain.cmake = args.cmake
22652233

utils/build-script-impl

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,15 +1081,15 @@ check_swiftenv_args
10811081
# If we are using a swiftenv, do this next block
10821082
if [ "${SWIFTENV_PATH}" ]; then
10831083

1084-
if [[ ! -d "${SWIFTENV_PATH}" ]]; then
1084+
if [ ! -d "${SWIFTENV_PATH}" ]; then
10851085
echo "${COMMAND_NAME}: SWIFTENV_PATH does not exist, it will be created"
10861086
fi
10871087
if [[ "${SWIFTENV_RECREATE}" ]]; then
10881088
echo "${COMMAND_NAME}: SWIFTENV_PATH will be recreated because SWIFTENV_RECREATE is true"
10891089
fi
10901090

10911091
# redo the swiftenv by deleting, mkdir, and running the SWIFTENV_MAKE script
1092-
if [[ ! -d "${SWIFTENV_PATH}" ]] || [[ "${SWIFTENV_RECREATE}" ]]; then
1092+
if [ ! -d "${SWIFTENV_PATH}" ] || [[ "${SWIFTENV_RECREATE}" ]]; then
10931093
if [ ! -f "${SWIFTENV_MAKE}" ]; then
10941094
echo "${COMMAND_NAME} error: SWIFTENV_MAKE is not set."
10951095
exit 2
@@ -1099,17 +1099,10 @@ if [ "${SWIFTENV_PATH}" ]; then
10991099
exit 2
11001100
fi
11011101

1102-
if [[ -d "${SWIFTENV_PATH}" ]] && [[ "${SWIFTENV_RECREATE}" ]]; then
1103-
echo "${COMMAND_NAME}: SWIFTENV_PATH does exists, it will be deleted and recreated"
1104-
call rm -rf "${SWIFTENV_PATH}"
1105-
echo "${COMMAND_NAME}: Calling mkdir on SWIFTENV_PATH: ${SWIFTENV_PATH}"
1106-
call mkdir -p "${SWIFTENV_PATH}"
1107-
echo "${COMMAND_NAME}: Calling \"${SWIFTENV_MAKE}\" \"${SWIFTENV_PATH}\" \"${SWIFTENV_SCRIPT}\""
1108-
call "${SWIFTENV_MAKE}" "${SWIFTENV_PATH}" "${SWIFTENV_SCRIPT}"
1109-
fi
1110-
1111-
else
1112-
echo "${COMMAND_NAME}: SWIFTENV_PATH exists, not recreating the SWIFTENV"
1102+
call rm -rf "${SWIFTENV_PATH}"
1103+
call mkdir -p "${SWIFTENV_PATH}"
1104+
echo "${COMMAND_NAME}: Calling \"${SWIFTENV_MAKE}\" \"${SWIFTENV_PATH}\" \"${SWIFTENV_SCRIPT}\""
1105+
call "${SWIFTENV_MAKE}" "${SWIFTENV_PATH}" "${SWIFTENV_SCRIPT}"
11131106
fi
11141107
fi
11151108

@@ -1186,8 +1179,10 @@ function set_cmake_tools {
11861179
if [ "${CMAKE_C_COMPILER}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_C_COMPILER:PATH="${CMAKE_C_COMPILER}"); fi
11871180
if [ "${CMAKE_CXX_COMPILER}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_CXX_COMPILER:PATH="${CMAKE_CXX_COMPILER}"); fi
11881181
if [ "${CMAKE_AR}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_AR:PATH="${CMAKE_AR}"); fi
1182+
if [ "${CMAKE_LD}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_LD:PATH="${CMAKE_LD}"); fi
11891183
if [ "${CMAKE_RANLIB}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_RANLIB:PATH="${CMAKE_RANLIB}"); fi
11901184
if [ "${CMAKE_LIPO}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_LIPO:PATH="${CMAKE_LIPO}"); fi
1185+
if [ "${CMAKE_LIBTOOL}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_LIBTOOL:PATH="${CMAKE_LIBTOOL}"); fi
11911186
if [ "${CMAKE_INSTALL_NAME_TOOL}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_INSTALL_NAME_TOOL:PATH="${CMAKE_INSTALL_NAME_TOOL}"); fi
11921187
if [ "${CMAKE_CODESIGN}" ]; then cmake_options=( "${cmake_options[@]}" -DCMAKE_CODESIGN:PATH="${CMAKE_CODESIGN}"); fi
11931188
if [ "${CMAKE_PYTHON}" ]; then cmake_options=( "${cmake_options[@]}" -DPYTHON_EXECUTABLE:PATH="${CMAKE_PYTHON}"); fi
@@ -2112,12 +2107,7 @@ for host in "${ALL_HOSTS[@]}"; do
21122107
build_targets=(llvm-tblgen clang-headers)
21132108
fi
21142109

2115-
if [ "${CMAKE_LIBTOOL}" ] ; then
2116-
cmake_options=(
2117-
"${cmake_options[@]}"
2118-
-DCMAKE_LIBTOOL:PATH="${CMAKE_LIBTOOL}"
2119-
)
2120-
fi
2110+
set_cmake_tools
21212111

21222112
# Note: we set the variable:
21232113
#

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,6 @@ def common_options(self):
9898
if args.export_compile_commands:
9999
define("CMAKE_EXPORT_COMPILE_COMMANDS", "ON")
100100

101-
if args.distcc:
102-
define("CMAKE_C_COMPILER:PATH", toolchain.distcc)
103-
define("CMAKE_C_COMPILER_ARG1", toolchain.cc)
104-
define("CMAKE_CXX_COMPILER:PATH", toolchain.distcc)
105-
define("CMAKE_CXX_COMPILER_ARG1", toolchain.cxx)
106-
else:
107-
define("CMAKE_C_COMPILER:PATH", toolchain.cc)
108-
define("CMAKE_CXX_COMPILER:PATH", toolchain.cxx)
109-
110101
if args.cmake_generator == 'Xcode':
111102
define("CMAKE_CONFIGURATION_TYPES",
112103
"Debug;Release;MinSizeRel;RelWithDebInfo")

utils/swift_build_support/tests/test_cmake.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def mock_distcc_path(self):
2828
def default_args(self):
2929
"""Return new args object with default values
3030
"""
31-
return Namespace(cmake_c_compiler="/path/to/clang",
32-
cmake_cxx_compiler="/path/to/clang++",
33-
enable_asan=False,
31+
return Namespace(enable_asan=False,
3432
enable_ubsan=False,
3533
enable_tsan=False,
3634
export_compile_commands=False,
@@ -54,8 +52,6 @@ def cmake(self, args):
5452
"""Return new CMake object initialized with given args
5553
"""
5654
toolchain = host_toolchain()
57-
toolchain.cc = args.cmake_c_compiler
58-
toolchain.cxx = args.cmake_cxx_compiler
5955
if args.distcc:
6056
toolchain.distcc = self.mock_distcc_path()
6157
toolchain.ninja = self.which_ninja(args)
@@ -67,8 +63,6 @@ def test_common_options_defaults(self):
6763
self.assertEqual(
6864
list(cmake.common_options()),
6965
["-G", "Ninja",
70-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
71-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
7266
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
7367

7468
def test_common_options_asan(self):
@@ -79,8 +73,6 @@ def test_common_options_asan(self):
7973
list(cmake.common_options()),
8074
["-G", "Ninja",
8175
"-DLLVM_USE_SANITIZER=Address",
82-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
83-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
8476
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
8577

8678
def test_common_options_ubsan(self):
@@ -91,8 +83,6 @@ def test_common_options_ubsan(self):
9183
list(cmake.common_options()),
9284
["-G", "Ninja",
9385
"-DLLVM_USE_SANITIZER=Undefined",
94-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
95-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
9686
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
9787

9888
def test_common_options_tsan(self):
@@ -103,8 +93,6 @@ def test_common_options_tsan(self):
10393
list(cmake.common_options()),
10494
["-G", "Ninja",
10595
"-DLLVM_USE_SANITIZER=Thread",
106-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
107-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
10896
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
10997

11098
def test_common_options_asan_ubsan(self):
@@ -116,8 +104,6 @@ def test_common_options_asan_ubsan(self):
116104
list(cmake.common_options()),
117105
["-G", "Ninja",
118106
"-DLLVM_USE_SANITIZER=Address;Undefined",
119-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
120-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
121107
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
122108

123109
def test_common_options_ubsan_tsan(self):
@@ -129,8 +115,6 @@ def test_common_options_ubsan_tsan(self):
129115
list(cmake.common_options()),
130116
["-G", "Ninja",
131117
"-DLLVM_USE_SANITIZER=Undefined;Thread",
132-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
133-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
134118
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
135119

136120
def test_common_options_asan_ubsan_tsan(self):
@@ -143,8 +127,6 @@ def test_common_options_asan_ubsan_tsan(self):
143127
list(cmake.common_options()),
144128
["-G", "Ninja",
145129
"-DLLVM_USE_SANITIZER=Address;Undefined;Thread",
146-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
147-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
148130
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
149131

150132
def test_common_options_export_compile_commands(self):
@@ -155,8 +137,6 @@ def test_common_options_export_compile_commands(self):
155137
list(cmake.common_options()),
156138
["-G", "Ninja",
157139
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
158-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
159-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
160140
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
161141

162142
def test_common_options_distcc(self):
@@ -166,10 +146,6 @@ def test_common_options_distcc(self):
166146
self.assertEqual(
167147
list(cmake.common_options()),
168148
["-G", "Ninja",
169-
"-DCMAKE_C_COMPILER:PATH=" + self.mock_distcc_path(),
170-
"-DCMAKE_C_COMPILER_ARG1=/path/to/clang",
171-
"-DCMAKE_CXX_COMPILER:PATH=" + self.mock_distcc_path(),
172-
"-DCMAKE_CXX_COMPILER_ARG1=/path/to/clang++",
173149
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
174150

175151
def test_common_options_xcode(self):
@@ -179,8 +155,6 @@ def test_common_options_xcode(self):
179155
self.assertEqual(
180156
list(cmake.common_options()),
181157
["-G", "Xcode",
182-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
183-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
184158
"-DCMAKE_CONFIGURATION_TYPES=" +
185159
"Debug;Release;MinSizeRel;RelWithDebInfo"])
186160

@@ -193,8 +167,6 @@ def test_common_options_clang_compiler_version(self):
193167
self.assertEqual(
194168
list(cmake.common_options()),
195169
["-G", "Ninja",
196-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
197-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
198170
"-DLLVM_VERSION_MAJOR:STRING=3",
199171
"-DLLVM_VERSION_MINOR:STRING=8",
200172
"-DLLVM_VERSION_PATCH:STRING=0",
@@ -207,8 +179,6 @@ def test_common_options_build_ninja(self):
207179
self.assertEqual(
208180
list(cmake.common_options()),
209181
["-G", "Ninja",
210-
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
211-
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
212182
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])
213183

214184
def test_common_options_full(self):
@@ -228,10 +198,6 @@ def test_common_options_full(self):
228198
["-G", "Xcode",
229199
"-DLLVM_USE_SANITIZER=Address;Undefined",
230200
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON",
231-
"-DCMAKE_C_COMPILER:PATH=" + self.mock_distcc_path(),
232-
"-DCMAKE_C_COMPILER_ARG1=/path/to/clang",
233-
"-DCMAKE_CXX_COMPILER:PATH=" + self.mock_distcc_path(),
234-
"-DCMAKE_CXX_COMPILER_ARG1=/path/to/clang++",
235201
"-DCMAKE_CONFIGURATION_TYPES=" +
236202
"Debug;Release;MinSizeRel;RelWithDebInfo",
237203
"-DLLVM_VERSION_MAJOR:STRING=3",

utils/swiftenv-script

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function find_real_command {
2727
fi
2828
case "$command_name" in
2929
clang|clang++|ld|swift|swiftc|lipo|ar|codesign|dsymutil|libtool|ranlib|strip|llvm-tblgen|python) "${find_util}" "${command_name}";;
30-
*) echo "${command_name}";;
30+
*) echo "$1";;
3131
esac
3232
}
3333
function find_o_target { # last -o wins, can short circuit for faster compiles
@@ -41,32 +41,35 @@ function find_o_target { # last -o wins, can short circuit for faster compiles
4141
esac; done
4242
echo "${o_target}"
4343
}
44-
function find_module_target {
44+
function find_swift_targets {
4545
while test $# -gt 0; do
4646
case "$1" in
47-
-emit-module-path) echo "$2"; break;;
47+
-o)
48+
local out="$2";
49+
outfiles=("${outfiles[@]}" "${out}")
50+
if [[ "$2" == *.swiftmodule ]]; then
51+
outfiles=("${outfiles[@]}" "${out:0:${#out}-12}.swiftdoc")
52+
fi
53+
shift; shift;;
54+
-output-file-map)
55+
outfiles=("${outfiles[@]}" "$2"); shift; shift;;
56+
-emit-module-path)
57+
local module_path="$2";
58+
outfiles=("${outfiles[@]}" "${module_path}")
59+
outfiles=("${outfiles[@]}" "${module_path:0:${#module_path}-12}.swiftdoc")
60+
shift; shift;;
61+
-emit-objc-header-path)
62+
outfiles=("${outfiles[@]}" "$2"); shift; shift;;
4863
*) shift;;
4964
esac; done
5065
}
51-
function emit_module_p { #emit -o's arg + swiftmodule
52-
while test $# -gt 0; do
53-
case "$1" in
54-
-emit-module) return 0;;
55-
*) shift;;
56-
esac; done; return 1
57-
}
5866
function find_command_targets { # sets: outfiles
5967
local name="$1"
6068
local args=("${@:2}")
6169
case "$name" in
6270
clang|clang++|ld|libtool|clang-tblgen|llvm-tblgen|lipo|gyb)
6371
outfiles=("${outfiles[@]}" $(find_o_target "${args[@]}"));;
64-
swift|swiftc)
65-
outfiles=("${outfiles[@]}" $(find_o_target "${args[@]}"));
66-
if emit_module_p "${args[@]}" ; then
67-
local last_outfile; last_outfile=("${outfiles[@]: -1}")
68-
outfiles=("${outfiles[@]}" "${last_outfile:0:${#last_outfile}-12}.swiftdoc"); fi
69-
find_module_target "${args[@]}";;
72+
swift|swiftc) find_swift_targets "${args[@]}";;
7073
ranlib) outfiles=("${outfiles[@]}" $(first "${args[@]}"));;
7174
ar) outfiles=("${outfiles[@]}" $(second "${args[@]}"));;
7275
codesign|dsymutil|install_name_tool|strip) outfiles=("${outfiles[@]}" $(last "${args[@]}"));;

0 commit comments

Comments
 (0)