exe_path.cpp 621 B

1234567891011121314151617181920212223
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "common/exe_path.h"
  5. #include "llvm/ADT/StringRef.h"
  6. #include "llvm/Support/FileSystem.h"
  7. #include "llvm/Support/Program.h"
  8. namespace Carbon {
  9. auto FindExecutablePath(llvm::StringRef argv0) -> std::string {
  10. if (!llvm::sys::fs::exists(argv0)) {
  11. if (llvm::ErrorOr<std::string> path = llvm::sys::findProgramByName(argv0)) {
  12. return std::move(*path);
  13. }
  14. }
  15. return argv0.str();
  16. }
  17. } // namespace Carbon