busybox_info.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #ifndef CARBON_TOOLCHAIN_INSTALL_BUSYBOX_INFO_H_
  5. #define CARBON_TOOLCHAIN_INSTALL_BUSYBOX_INFO_H_
  6. #include <filesystem>
  7. #include <optional>
  8. #include <string>
  9. #include "common/error.h"
  10. namespace Carbon {
  11. // An optional override of argv0, particularly used by `//toolchain/carbon` to
  12. // get desired behavior without further special-casing.
  13. inline constexpr const char* Argv0OverrideEnv = "CARBON_ARGV0_OVERRIDE";
  14. struct BusyboxInfo {
  15. // The path to `carbon-busybox`.
  16. std::filesystem::path bin_path;
  17. // The mode, such as `carbon` or `clang`.
  18. std::optional<std::string> mode;
  19. };
  20. // Returns the busybox information, given argv[0].
  21. //
  22. // Extracts the desired mode for the busybox from the initial command name.
  23. //
  24. // Checks if the path in argv0 is an executable in a valid Carbon install, or a
  25. // symlink to such an executable, and sets `bin_path` to the path of
  26. // `lib/carbon/carbon-busybox` within that install.
  27. //
  28. // If unable to locate a plausible busybox binary, returns an error instead.
  29. auto GetBusyboxInfo(const char* argv0) -> ErrorOr<BusyboxInfo>;
  30. } // namespace Carbon
  31. #endif // CARBON_TOOLCHAIN_INSTALL_BUSYBOX_INFO_H_