Files
carbon-lang/common/bazel_working_dir.h
T
Jon Ross-Perkins 0b9bda10b7 Refactor common main logic (#2260)
1) toolchain and explorer use the same working dir logic, share it
2) explorer's carbon.cpp and main_bin.cpp use the same relative path logic, share it
3) You can append a longer path in one call with the right kind of iterator
4) Fix what's maybe a bug in passing `relative_prelude_path.str()` to `cl::init`
5) Collapse Main and ExplorerMain to avoid passing more parameters between
2022-10-05 17:34:04 -07:00

32 lines
922 B
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_COMMON_BAZEL_WORKING_DIR_H_
#define CARBON_COMMON_BAZEL_WORKING_DIR_H_
#include "llvm/Support/FileSystem.h"
namespace Carbon {
// Behave as if the working directory is where `bazel run` was invoked.
// This should only be used in development binaries, not release.
inline auto SetWorkingDirForBazel() -> bool {
char* build_working_dir = getenv("BUILD_WORKING_DIRECTORY");
if (build_working_dir == nullptr) {
return true;
}
if (std::error_code err =
llvm::sys::fs::set_current_path(build_working_dir)) {
llvm::errs() << "Failed to set working directory: " << err.message();
return false;
}
return true;
}
} // namespace Carbon
#endif // CARBON_COMMON_BAZEL_WORKING_DIR_H_