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
+15 -1
View File
@@ -15,7 +15,6 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "testing/file_test/file_system.h"
#include "testing/file_test/file_test_base.h"
#include "toolchain/driver/driver.h"
@@ -98,6 +97,21 @@ auto ToolchainFileTest::GetArgReplacements() const
return {{"core_package_dir", installation_.core_package()}};
}
// Adds a file to the fs.
static auto AddFile(llvm::vfs::InMemoryFileSystem& fs, llvm::StringRef path)
-> ErrorOr<Success> {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> file =
llvm::MemoryBuffer::getFile(path);
if (file.getError()) {
return ErrorBuilder() << "Getting `" << path
<< "`: " << file.getError().message();
}
if (!fs.addFile(path, /*ModificationTime=*/0, std::move(*file))) {
return ErrorBuilder() << "Duplicate file: `" << path << "`";
}
return Success();
}
auto ToolchainFileTest::Run(
const llvm::SmallVector<llvm::StringRef>& test_args,
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>& fs,