Skip to content

Commit b39445f

Browse files
committed
auto merge of #17890 : pnkfelix/rust/fsk-fix-issue-17887, r=alexcrichton
Fixes `config.mk` so that it should not contain multiple inconsistent entries for the same option. Used aforementioned variants to extract options that have explicit `putvar` calls associated with them in the subsequent code. When the explicit `putvar` call was conditional on some potentially complex condition, moved the `putvar` call out to the main control flow of the script so that it always runs if necessary. ---- As a driveby fix, captured the error exit when doing the test run of `rustc --version` from `CFG_LOCAL_RUST_ROOT`, and signal explicit configure failure when it did not run successfully. (If we cannot run `rustc`, we really shouldn't try to keep going.) ---- Fix #17887.
2 parents f037452 + b354c32 commit b39445f

File tree

1 file changed

+93
-31
lines changed

1 file changed

+93
-31
lines changed

configure

Lines changed: 93 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,22 @@ validate_opt () {
151151
done
152152
}
153153

154-
valopt() {
155-
VAL_OPTIONS="$VAL_OPTIONS $1"
154+
# `valopt OPTION_NAME DEFAULT DOC` extracts a string-valued option
155+
# from command line, using provided default value for the option if
156+
# not present, and saves it to the generated config.mk.
157+
#
158+
# `valopt_nosave` is much the same, except that it does not save the
159+
# result to config.mk (instead the script should use `putvar` itself
160+
# later on to save it). `valopt_core` is the core upon which the
161+
# other two are built.
162+
163+
valopt_core() {
164+
VAL_OPTIONS="$VAL_OPTIONS $2"
156165

157-
local OP=$1
158-
local DEFAULT=$2
166+
local SAVE=$1
167+
local OP=$2
168+
local DEFAULT=$3
169+
shift
159170
shift
160171
shift
161172
local DOC="$*"
@@ -172,7 +183,10 @@ valopt() {
172183
eval $V=$val
173184
fi
174185
done
175-
putvar $V
186+
if [ "$SAVE" = "save" ]
187+
then
188+
putvar $V
189+
fi
176190
else
177191
if [ -z "$DEFAULT" ]
178192
then
@@ -183,11 +197,30 @@ valopt() {
183197
fi
184198
}
185199

186-
opt() {
187-
BOOL_OPTIONS="$BOOL_OPTIONS $1"
200+
valopt_nosave() {
201+
valopt_core nosave "$@"
202+
}
188203

189-
local OP=$1
190-
local DEFAULT=$2
204+
valopt() {
205+
valopt_core save "$@"
206+
}
207+
208+
# `opt OPTION_NAME DEFAULT DOC` extracts a boolean-valued option from
209+
# command line, using the provided default value (0/1) for the option
210+
# if not present, and saves it to the generated config.mk.
211+
#
212+
# `opt_nosave` is much the same, except that it does not save the
213+
# result to config.mk (instead the script should use `putvar` itself
214+
# later on to save it). `opt_core` is the core upon which the other
215+
# two are built.
216+
217+
opt_core() {
218+
BOOL_OPTIONS="$BOOL_OPTIONS $2"
219+
220+
local SAVE=$1
221+
local OP=$2
222+
local DEFAULT=$3
223+
shift
191224
shift
192225
shift
193226
local DOC="$*"
@@ -211,7 +244,10 @@ opt() {
211244
FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
212245
local V="CFG_${FLAG}_${OP}"
213246
eval $V=1
214-
putvar $V
247+
if [ "$SAVE" = "save" ]
248+
then
249+
putvar $V
250+
fi
215251
fi
216252
done
217253
else
@@ -223,6 +259,14 @@ opt() {
223259
fi
224260
}
225261

262+
opt_nosave() {
263+
opt_core nosave "$@"
264+
}
265+
266+
opt() {
267+
opt_core save "$@"
268+
}
269+
226270
envopt() {
227271
local NAME=$1
228272
local V="CFG_${NAME}"
@@ -422,38 +466,41 @@ opt llvm-assertions 1 "build LLVM with assertions"
422466
opt debug 1 "build with extra debug fun"
423467
opt ratchet-bench 0 "ratchet benchmarks"
424468
opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
425-
opt manage-submodules 1 "let the build manage the git submodules"
426469
opt mingw-cross 0 "cross-compile for win32 using mingw"
427-
opt clang 0 "prefer clang to gcc for building the runtime"
428470
opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
429471
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
430-
opt inject-std-version 1 "inject the current compiler version of libstd into programs"
431472
opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
432473
opt rpath 0 "build rpaths into rustc itself"
433474
opt nightly 0 "build nightly packages"
434475
opt verify-install 1 "verify installed binaries work"
435-
opt jemalloc 1 "build liballoc with jemalloc"
436476
# This is used by the automation to produce single-target nightlies
437477
opt dist-host-only 0 "only install bins for the host architecture"
438-
valopt prefix "/usr/local" "set installation prefix"
439-
valopt local-rust-root "/usr/local" "set prefix for local rust binary"
440-
valopt llvm-root "" "set LLVM root"
441-
valopt jemalloc-root "" "set directory where libjemalloc_pic.a is located"
442-
valopt android-cross-path "/opt/ndk_standalone" "Android NDK standalone path"
443-
valopt mingw32-cross-path "" "MinGW32 cross compiler path"
444478

445-
valopt build "${DEFAULT_BUILD}" "GNUs ./configure syntax LLVM build triple"
446-
valopt host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
447-
valopt target "${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"
448479

449480
valopt localstatedir "/var/lib" "local state directory"
450481
valopt sysconfdir "/etc" "install system configuration files"
451482

452483
valopt datadir "${CFG_PREFIX}/share" "install data"
453484
valopt infodir "${CFG_PREFIX}/share/info" "install additional info"
454-
valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
455485

456-
valopt release-channel "dev" "the name of the release channel to build"
486+
# Many of these are saved below during the "writing configuration" step
487+
# (others are conditionally saved).
488+
opt_nosave manage-submodules 1 "let the build manage the git submodules"
489+
opt_nosave clang 0 "prefer clang to gcc for building the runtime"
490+
opt_nosave inject-std-version 1 "inject the current compiler version of libstd into programs"
491+
opt_nosave jemalloc 1 "build liballoc with jemalloc"
492+
493+
valopt_nosave prefix "/usr/local" "set installation prefix"
494+
valopt_nosave local-rust-root "/usr/local" "set prefix for local rust binary"
495+
valopt_nosave llvm-root "" "set LLVM root"
496+
valopt_nosave jemalloc-root "" "set directory where libjemalloc_pic.a is located"
497+
valopt_nosave android-cross-path "/opt/ndk_standalone" "Android NDK standalone path"
498+
valopt_nosave mingw32-cross-path "" "MinGW32 cross compiler path"
499+
valopt_nosave build "${DEFAULT_BUILD}" "GNUs ./configure syntax LLVM build triple"
500+
valopt_nosave host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
501+
valopt_nosave target "${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"
502+
valopt_nosave mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
503+
valopt_nosave release-channel "dev" "the name of the release channel to build"
457504

458505
# On windows we just store the libraries in the bin directory because
459506
# there's no rpath. This is where the build system itself puts libraries;
@@ -465,7 +512,7 @@ then
465512
CFG_LIBDIR_RELATIVE=bin
466513
fi
467514

468-
valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries"
515+
valopt_nosave libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries"
469516

470517
if [ $HELP -eq 1 ]
471518
then
@@ -491,8 +538,8 @@ esac
491538
if [ ! -z "$CFG_ENABLE_NIGHTLY" ]
492539
then
493540
CFG_RELEASE_CHANNEL=nightly
494-
putvar CFG_RELEASE_CHANNEL
495541
fi
542+
putvar CFG_RELEASE_CHANNEL
496543

497544
step_msg "looking for build programs"
498545

@@ -605,17 +652,27 @@ then
605652
err "no local rust to use"
606653
fi
607654

608-
LRV=`${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF} --version`
655+
CMD="${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF}"
656+
LRV=`$CMD --version`
657+
if [ $? -ne 0 ]
658+
then
659+
step_msg "failure while running $CMD --version"
660+
exit 1
661+
fi
609662
step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
610663
putvar CFG_LOCAL_RUST_ROOT
664+
else
665+
if [ ! -z "$CFG_LOCAL_RUST_ROOT" ]
666+
then
667+
warn "Use of --local-rust-root without --enable-local-rust"
668+
fi
611669
fi
612670

613671
# Force freebsd to build with clang; gcc doesn't like us there
614672
if [ $CFG_OSTYPE = unknown-freebsd ]
615673
then
616674
step_msg "on FreeBSD, forcing use of clang"
617675
CFG_ENABLE_CLANG=1
618-
putvar CFG_ENABLE_CLANG
619676
fi
620677

621678
if [ -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
@@ -632,12 +689,10 @@ then
632689
then
633690
step_msg "on OS X 10.9, forcing use of clang"
634691
CFG_ENABLE_CLANG=1
635-
putvar CFG_ENABLE_CLANG
636692
else
637693
if [ $("$CFG_GCC" --version 2>&1 | grep -c ' 4\.[0-6]') -ne 0 ]; then
638694
step_msg "older GCC found, using clang instead"
639695
CFG_ENABLE_CLANG=1
640-
putvar CFG_ENABLE_CLANG
641696
else
642697
# on OS X, with xcode 5 and newer, certain developers may have
643698
# cc, gcc and g++ point to a mixture of clang and gcc
@@ -663,6 +718,13 @@ then
663718
fi
664719
fi
665720

721+
# Okay, at this point, we have made up our minds about whether we are
722+
# going to force CFG_ENABLE_CLANG or not; save the setting if so.
723+
if [ ! -z "$CFG_ENABLE_CLANG" ]
724+
then
725+
putvar CFG_ENABLE_CLANG
726+
fi
727+
666728
if [ ! -z "$CFG_LLVM_ROOT" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ]
667729
then
668730
step_msg "using custom LLVM at $CFG_LLVM_ROOT"

0 commit comments

Comments
 (0)