mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 18:41:03 +01:00
precompile and cache Carbon prelude (#7432)
Refactors the link driver to automatically compile and cache the carbon prelude for use in linking. Implements a `carbon_library` rule for compiling the Core library dependencies in the examples.
This commit is contained in:
@@ -47,6 +47,9 @@ struct SharedTestData {
|
||||
// Files in the prelude.
|
||||
llvm::SmallVector<std::string> prelude_files;
|
||||
|
||||
// Files in core not in the prelude.
|
||||
llvm::SmallVector<std::string> core_files;
|
||||
|
||||
// The installed files that tests can use.
|
||||
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> file_system =
|
||||
new llvm::vfs::InMemoryFileSystem();
|
||||
@@ -63,6 +66,12 @@ static auto GetSharedTestData(llvm::StringRef exe_path)
|
||||
CARBON_RETURN_IF_ERROR(AddFile(*data.file_system, file));
|
||||
}
|
||||
|
||||
CARBON_ASSIGN_OR_RETURN(data.core_files,
|
||||
data.installation.ReadCarbonCoreManifest());
|
||||
for (const auto& file : data.core_files) {
|
||||
CARBON_RETURN_IF_ERROR(AddFile(*data.file_system, file));
|
||||
}
|
||||
|
||||
llvm::SmallVector<std::string> clang_header_files;
|
||||
CARBON_ASSIGN_OR_RETURN(clang_header_files,
|
||||
data.installation.ReadClangHeadersManifest());
|
||||
@@ -166,6 +175,7 @@ auto ToolchainFileTest::Run(
|
||||
if (component_ == "check" || component_ == "lower") {
|
||||
filtered_test_args.reserve(test_args.size());
|
||||
bool found_prelude_flag = false;
|
||||
bool found_include_core_flag = false;
|
||||
for (auto arg : test_args) {
|
||||
bool driver_flag = arg == "--custom-core" || arg == "--no-prelude-import";
|
||||
// A flag specified by a test prelude to indicate the intention to include
|
||||
@@ -174,7 +184,9 @@ auto ToolchainFileTest::Run(
|
||||
if (driver_flag || full_prelude) {
|
||||
found_prelude_flag = true;
|
||||
}
|
||||
if (!full_prelude) {
|
||||
bool include_core = arg == "--include-carbon-core";
|
||||
found_include_core_flag |= include_core;
|
||||
if (!full_prelude && !include_core) {
|
||||
filtered_test_args.push_back(arg);
|
||||
}
|
||||
}
|
||||
@@ -183,6 +195,13 @@ auto ToolchainFileTest::Run(
|
||||
"Include a prelude from //toolchain/testing/testdata/min_prelude "
|
||||
"to specify what should be imported into the test.");
|
||||
}
|
||||
// The compile driver includes the carbon-core by default, but we invert
|
||||
// this logic for the check and lower phases, meaning we detect the presence
|
||||
// of `--include-carbon-core` in the arguments, and unless that is there
|
||||
// we automatically append the `--no-include-carbon-core` flag.
|
||||
if (!found_include_core_flag) {
|
||||
filtered_test_args.push_back("--no-include-carbon-core");
|
||||
}
|
||||
} else {
|
||||
filtered_test_args = test_args;
|
||||
}
|
||||
@@ -266,7 +285,7 @@ auto ToolchainFileTest::GetDefaultArgs() const
|
||||
} else if (component_ == "lower") {
|
||||
args.insert(args.end(), {"--dump-llvm-ir", "--target=x86_64-linux-gnu"});
|
||||
} else if (component_ == "codegen") {
|
||||
// codegen tests specify flags as needed.
|
||||
args.insert(args.end(), {"--no-include-carbon-core"});
|
||||
} else {
|
||||
CARBON_FATAL("Unexpected test component {0}: {1}", component_, test_name());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user