Skip to content

fixes the --set option in configure.py #107059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ See [the rustc-dev-guide for more info][sysllvm].
list of options in `config.toml.example`.

```sh
printf 'profile = "user" \nchangelog-seen = 2 \n' > config.toml
./configure --set profile="user"
./configure --set changelog-seen=2
Comment on lines +103 to +104
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't correct, it will overwrite config.toml. You need two --set flags in the same command I think. Please test the modified command to make sure it works.

```


If you plan to use `x.py install` to create an installation, it is
recommended that you set the `prefix` value in the `[install]` section to a
directory.
Expand Down
100 changes: 69 additions & 31 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# ignore-tidy-linelength

from __future__ import absolute_import, division, print_function
import bootstrap
import sys
import os
rust_dir = os.path.dirname(os.path.abspath(__file__))
rust_dir = os.path.dirname(rust_dir)
rust_dir = os.path.dirname(rust_dir)
sys.path.append(os.path.join(rust_dir, "src", "bootstrap"))
import bootstrap


class Option(object):
Expand All @@ -31,28 +31,40 @@ def v(*args):
options.append(Option(*args, value=True))


o("debug", "rust.debug", "enables debugging environment; does not affect optimization of bootstrapped code")
o("debug", "rust.debug",
"enables debugging environment; does not affect optimization of bootstrapped code")
o("docs", "build.docs", "build standard library documentation")
o("compiler-docs", "build.compiler-docs", "build compiler documentation")
o("optimize-tests", "rust.optimize-tests", "build tests with optimizations")
o("verbose-tests", "rust.verbose-tests", "enable verbose output when running tests")
o("ccache", "llvm.ccache", "invoke gcc/clang via ccache to reuse object files between builds")
o("verbose-tests", "rust.verbose-tests",
"enable verbose output when running tests")
o("ccache", "llvm.ccache",
"invoke gcc/clang via ccache to reuse object files between builds")
o("sccache", None, "invoke gcc/clang via sccache to reuse object files between builds")
o("local-rust", None, "use an installed rustc rather than downloading a snapshot")
v("local-rust-root", None, "set prefix for local rust binary")
o("local-rebuild", "build.local-rebuild", "assume local-rust matches the current version, for rebuilds; implies local-rust, and is implied if local-rust already matches the current version")
o("llvm-static-stdcpp", "llvm.static-libstdcpp", "statically link to libstdc++ for LLVM")
o("llvm-link-shared", "llvm.link-shared", "prefer shared linking to LLVM (llvm-config --link-shared)")
o("local-rebuild", "build.local-rebuild",
"assume local-rust matches the current version, for rebuilds; implies local-rust, and is implied if local-rust already matches the current version")
o("llvm-static-stdcpp", "llvm.static-libstdcpp",
"statically link to libstdc++ for LLVM")
o("llvm-link-shared", "llvm.link-shared",
"prefer shared linking to LLVM (llvm-config --link-shared)")
o("rpath", "rust.rpath", "build rpaths into rustc itself")
o("llvm-version-check", "llvm.version-check", "check if the LLVM version is supported, build anyway")
o("llvm-version-check", "llvm.version-check",
"check if the LLVM version is supported, build anyway")
o("codegen-tests", "rust.codegen-tests", "run the tests/codegen tests")
o("option-checking", None, "complain about unrecognized options in this configure script")
o("ninja", "llvm.ninja", "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)")
o("ninja", "llvm.ninja",
"build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)")
o("locked-deps", "build.locked-deps", "force Cargo.lock to be up to date")
o("vendor", "build.vendor", "enable usage of vendored Rust crates")
o("sanitizers", "build.sanitizers", "build the sanitizer runtimes (asan, lsan, msan, tsan, hwasan)")
o("dist-src", "rust.dist-src", "when building tarballs enables building a source tarball")
o("cargo-native-static", "build.cargo-native-static", "static native libraries in cargo")
o("sanitizers", "build.sanitizers",
"build the sanitizer runtimes (asan, lsan, msan, tsan, hwasan)")
o("dist-src", "rust.dist-src",
"when building tarballs enables building a source tarball")
o("cargo-native-static",
"build.cargo-native-static",
"static native libraries in cargo")
o("profiler", "build.profiler", "build the profiler runtime")
o("full-tools", None, "enable all tools")
o("lld", "rust.lld", "build lld")
Expand All @@ -73,16 +85,27 @@ def v(*args):
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface")
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
o("debug-assertions-std", "rust.debug-assertions-std", "build the standard library with debugging assertions")
o("debug-assertions-std", "rust.debug-assertions-std",
"build the standard library with debugging assertions")
o("overflow-checks", "rust.overflow-checks", "build with overflow checks")
o("overflow-checks-std", "rust.overflow-checks-std", "build the standard library with overflow checks")
o("llvm-release-debuginfo", "llvm.release-debuginfo", "build LLVM with debugger metadata")
o("overflow-checks-std", "rust.overflow-checks-std",
"build the standard library with overflow checks")
o("llvm-release-debuginfo",
"llvm.release-debuginfo",
"build LLVM with debugger metadata")
v("debuginfo-level", "rust.debuginfo-level", "debuginfo level for Rust code")
v("debuginfo-level-rustc", "rust.debuginfo-level-rustc", "debuginfo level for the compiler")
v("debuginfo-level-std", "rust.debuginfo-level-std", "debuginfo level for the standard library")
v("debuginfo-level-tools", "rust.debuginfo-level-tools", "debuginfo level for the tools")
v("debuginfo-level-tests", "rust.debuginfo-level-tests", "debuginfo level for the test suites run with compiletest")
v("save-toolstates", "rust.save-toolstates", "save build and test status of external tools into this file")
v("debuginfo-level-rustc",
"rust.debuginfo-level-rustc",
"debuginfo level for the compiler")
v("debuginfo-level-std", "rust.debuginfo-level-std",
"debuginfo level for the standard library")
v("debuginfo-level-tools",
"rust.debuginfo-level-tools",
"debuginfo level for the tools")
v("debuginfo-level-tests", "rust.debuginfo-level-tests",
"debuginfo level for the test suites run with compiletest")
v("save-toolstates", "rust.save-toolstates",
"save build and test status of external tools into this file")

v("prefix", "install.prefix", "set installation prefix")
v("localstatedir", "install.localstatedir", "local state directory")
Expand All @@ -106,7 +129,8 @@ def v(*args):
"arm-linux-androideabi NDK standalone path")
v("armv7-linux-androideabi-ndk", "target.armv7-linux-androideabi.android-ndk",
"armv7-linux-androideabi NDK standalone path")
v("thumbv7neon-linux-androideabi-ndk", "target.thumbv7neon-linux-androideabi.android-ndk",
v("thumbv7neon-linux-androideabi-ndk",
"target.thumbv7neon-linux-androideabi.android-ndk",
"thumbv7neon-linux-androideabi NDK standalone path")
v("aarch64-linux-android-ndk", "target.aarch64-linux-android.android-ndk",
"aarch64-linux-android NDK standalone path")
Expand Down Expand Up @@ -149,7 +173,8 @@ def v(*args):
v("experimental-targets", "llvm.experimental-targets",
"experimental LLVM targets to build")
v("release-channel", "rust.channel", "the name of the release channel to build")
v("release-description", "rust.description", "optional descriptive string for version output")
v("release-description", "rust.description",
"optional descriptive string for version output")
v("dist-compression-formats", None,
"comma-separated list of compression formats to use")

Expand All @@ -158,8 +183,10 @@ def v(*args):

# Many of these are saved below during the "writing configuration" step
# (others are conditionally saved).
o("manage-submodules", "build.submodules", "let the build manage the git submodules")
o("full-bootstrap", "build.full-bootstrap", "build three compilers instead of two (not recommended except for testing reproducible builds)")
o("manage-submodules", "build.submodules",
"let the build manage the git submodules")
o("full-bootstrap", "build.full-bootstrap",
"build three compilers instead of two (not recommended except for testing reproducible builds)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we undo the re-formatting of this file?

o("extended", "build.extended", "build an extended rust tool set")

v("tools", None, "List of extended tools will be installed")
Expand Down Expand Up @@ -189,9 +216,11 @@ def err(msg):
# no one needs to know about these obscure options
continue
if option.value:
print('\t{:30} {}'.format('--{}=VAL'.format(option.name), option.desc))
print('\t{:30} {}'.format(
'--{}=VAL'.format(option.name), option.desc))
else:
print('\t{:30} {}'.format('--enable-{}'.format(option.name), option.desc))
print('\t{:30} {}'.format(
'--enable-{}'.format(option.name), option.desc))
print('')
print('This configure script is a thin configuration shim over the true')
print('configuration system, `config.toml`. You can explore the comments')
Expand Down Expand Up @@ -386,7 +415,8 @@ def set(key, value):
if cur_section.startswith('target'):
cur_section = 'target'
elif '.' in cur_section:
raise RuntimeError("don't know how to deal with section: {}".format(cur_section))
raise RuntimeError(
"don't know how to deal with section: {}".format(cur_section))
sections[cur_section] = [line]
section_order.append(cur_section)
else:
Expand All @@ -407,7 +437,9 @@ def set(key, value):
targets[target] = sections['target'][:]
# For `.` to be valid TOML, it needs to be quoted. But `bootstrap.py` doesn't use a proper TOML parser and fails to parse the target.
# Avoid using quotes unless it's necessary.
targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", "'{}'".format(target) if "." in target else target)
targets[target][0] = targets[target][0].replace(
"x86_64-unknown-linux-gnu",
"'{}'".format(target) if "." in target else target)


def is_number(value):
Expand Down Expand Up @@ -456,20 +488,24 @@ def configure_section(lines, config):
if key in ["infodir", "localstatedir"]:
print("warning: {} will be ignored".format(key))
else:
raise RuntimeError("failed to find config line for {}".format(key))
raise RuntimeError(
"failed to find config line for {}".format(key))


cli_args = {}
for section_key in config:
section_config = config[section_key]
if section_key not in sections:
raise RuntimeError("config key {} not in sections".format(section_key))

# key is not in toml file,added via --set from command line
cli_args[section_key] = section_config
continue
if section_key == 'target':
for target in section_config:
configure_section(targets[target], section_config[target])
else:
configure_section(sections[section_key], section_config)


# Now that we've built up our `config.toml`, write it all out in the same
# order that we read it in.
p("")
Expand All @@ -483,6 +519,8 @@ def configure_section(lines, config):
else:
for line in sections[section]:
f.write(line + "\n")
for arg in cli_args:
f.write(arg + ' = ' + cli_args[arg])

with bootstrap.output('Makefile') as f:
contents = os.path.join(rust_dir, 'src', 'bootstrap', 'mk', 'Makefile.in')
Expand Down