Skip to content
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

Added GetRunfilesDir() to be able to reliably determine prelude location under various invocation scenarios #1207

Merged
merged 19 commits into from
May 2, 2022
Merged
Changes from 9 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
18 changes: 16 additions & 2 deletions executable_semantics/fuzzing/executable_semantics_fuzzer.cpp
Original file line number Diff line number Diff line change
@@ -10,10 +10,23 @@
#include "executable_semantics/interpreter/exec_program.h"
#include "executable_semantics/syntax/parse.h"
#include "executable_semantics/syntax/prelude.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"

namespace Carbon {

// Determines runfiles dir to use.
static auto GetRunfilesDir() -> std::string {
pk19604014 marked this conversation as resolved.
Show resolved Hide resolved
const char* test_src_dir = getenv("TEST_SRCDIR");
std::string runfiles_dir =
test_src_dir != nullptr
? test_src_dir
: llvm::sys::fs::getMainExecutable(nullptr, nullptr) + ".runfiles";
CHECK(llvm::sys::fs::exists(runfiles_dir))
<< runfiles_dir << " doesn't exist";
return runfiles_dir;
}

// Parses and executes a fuzzer-generated program.
void ParseAndExecute(const Fuzzing::CompilationUnit& compilation_unit) {
const std::string source = ProtoToCarbonWithMain(compilation_unit);
@@ -25,8 +38,9 @@ void ParseAndExecute(const Fuzzing::CompilationUnit& compilation_unit) {
llvm::errs() << "Parsing failed: " << ast.error().message() << "\n";
return;
}
AddPrelude("executable_semantics/data/prelude.carbon", &arena,
&ast->declarations);
AddPrelude(
GetRunfilesDir() + "/carbon/executable_semantics/data/prelude.carbon",
pk19604014 marked this conversation as resolved.
Show resolved Hide resolved
&arena, &ast->declarations);
const ErrorOr<int> result =
ExecProgram(&arena, *ast, /*trace_stream=*/std::nullopt);
if (!result.ok()) {