Make INCLUDE-FILE less sensitive to path changes (#5159)

It's helpful for stability to not have the path in the repo reflected in
test files, something I'm separately running into. So to reduce this,
align INCLUDE-FILE with other split behavior:

- Use the filename (with a "include_files/" subdir to disambiguate),
rather than the full path.
- Note if we eventually want to support splits in these, the same
approach could be extended.
- Only provide as an arg if the user requests files as args.

Factoring AddFile back because it's hard to share; I'm also advocating
to remove the prelude manifest, which would mean the remaining call
could be removed.
This commit is contained in:
Jon Ross-Perkins
2025-03-21 16:03:25 +00:00
committed by GitHub
parent 6041e9aa9d
commit 868efb7c86
27 changed files with 110 additions and 150 deletions
+9 -5
View File
@@ -567,14 +567,18 @@ static auto TryConsumeArgs(llvm::StringRef line, llvm::StringRef line_trimmed,
return true;
}
static auto TryConsumeIncludeFile(llvm::StringRef line_trimmed,
llvm::SmallVector<std::string>* include_files)
-> ErrorOr<bool> {
static auto TryConsumeIncludeFile(
llvm::StringRef line_trimmed,
llvm::SmallVector<TestFile::Split>* include_files) -> ErrorOr<bool> {
if (!line_trimmed.consume_front("// INCLUDE-FILE: ")) {
return false;
}
include_files->push_back(std::string(line_trimmed));
std::filesystem::path path = std::string(line_trimmed);
CARBON_ASSIGN_OR_RETURN(std::string content, ReadFile(path));
include_files->push_back(
{.filename = std::filesystem::path("include_files") / path.filename(),
.content = content});
return true;
}
@@ -686,7 +690,7 @@ auto ProcessTestFile(llvm::StringRef test_name, bool running_autoupdate)
}
CARBON_ASSIGN_OR_RETURN(
is_consumed,
TryConsumeIncludeFile(line_trimmed, &test_file.include_files));
TryConsumeIncludeFile(line_trimmed, &test_file.include_file_splits));
if (is_consumed) {
continue;
}