mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add INCLUDE-FILE: and --custom-core for file tests to specify a minimal prelude library (#5080)
The INCLUDE-FILE option is only used in the toolchain tests for now. If specified in a file test, the given file path is added to the test's arguments. For toolchain tests this makes the file's package available to the test. The `--custom-core` command line flag is added to the driver, which avoids adding the production `Core` package to the command line. Together, these allow a test to provide their own minimal `Core` package. For example, this would replace `Core` with the package and prelude in `facet_types.carbon`. ``` // INCLUDE-FILE: toolchain/testing/min_prelude/facet_types.carbon // EXTRA-ARGS: --custom-core ``` To support this: * //testing knows how to parse INCLUDE-FILE out of the header of a test file. * //testing adds the file to the virtual file system, and includes it in the test's arguments. * //toolchain/driver grows the --custom-core command line flag to avoid loading the production `Core` package. Tests that were creating their own minimal prelude to define BitAnd on types are now pointed to toolchain/testing/min_prelude/facet_types.carbon as the prelude. They no longer need to `import Core` in each test as a result. Such tests are no longer `no_prelude`, but instead have their own prelude. So they are moved to a `min_prelude` subdirectory. Closes #5076
This commit is contained in:
@@ -227,6 +227,23 @@ Whether to use the implicit prelude import. Enabled by default.
|
||||
arg_b.Default(true);
|
||||
arg_b.Set(&prelude_import);
|
||||
});
|
||||
b.AddFlag(
|
||||
{
|
||||
.name = "custom-core",
|
||||
.value_name = "CUSTOM_CORE",
|
||||
.help = R"""(
|
||||
Whether to use a custom Core package, the files for which must all be included
|
||||
in the compile command line.
|
||||
|
||||
The prelude library in the Core package is imported automatically. By default,
|
||||
the Core package shipped with the toolchain is used, and its files do not need
|
||||
to be specified in the compile command line.
|
||||
)""",
|
||||
},
|
||||
[&](auto& arg_b) {
|
||||
arg_b.Default(false);
|
||||
arg_b.Set(&custom_core);
|
||||
});
|
||||
b.AddStringOption(
|
||||
{
|
||||
.name = "exclude-dump-file-prefix",
|
||||
@@ -739,7 +756,7 @@ auto CompileSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
||||
// TODO: Replace this with a search for library api files in a
|
||||
// package-specific search path based on the library name.
|
||||
llvm::SmallVector<std::string> prelude;
|
||||
if (options_.prelude_import &&
|
||||
if (options_.prelude_import && !options_.custom_core &&
|
||||
options_.phase >= CompileOptions::Phase::Check) {
|
||||
if (auto find = driver_env.installation->ReadPreludeManifest(); find.ok()) {
|
||||
prelude = std::move(*find);
|
||||
|
||||
Reference in New Issue
Block a user