exe_path.cpp 659 B

1234567891011121314151617181920212223242526
  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 <string>
  6. #include <utility>
  7. #include "llvm/ADT/StringRef.h"
  8. #include "llvm/Support/FileSystem.h"
  9. #include "llvm/Support/Program.h"
  10. namespace Carbon {
  11. auto FindExecutablePath(llvm::StringRef argv0) -> std::string {
  12. if (!llvm::sys::fs::exists(argv0)) {
  13. if (llvm::ErrorOr<std::string> path = llvm::sys::findProgramByName(argv0)) {
  14. return std::move(*path);
  15. }
  16. }
  17. return argv0.str();
  18. }
  19. } // namespace Carbon