mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:40:11 +01:00
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
32 lines
922 B
C++
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_
|