summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/TARGETS2
-rw-r--r--src/buildtool/common/cli.hpp63
-rw-r--r--src/buildtool/main/main.cpp25
3 files changed, 79 insertions, 11 deletions
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS
index 0640aae6..a05632c6 100644
--- a/src/buildtool/common/TARGETS
+++ b/src/buildtool/common/TARGETS
@@ -14,6 +14,8 @@
, ["src/buildtool/build_engine/expression", "expression"]
, ["src/buildtool/compatibility", "compatibility"]
, ["src/buildtool/logging", "log_level"]
+ , ["src/buildtool/logging", "logging"]
+ , ["src/utils/cpp", "path"]
, ["@", "cli11", "", "cli11"]
, ["@", "json", "", "json"]
, ["@", "fmt", "", "fmt"]
diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp
index 03f13bce..d3d15409 100644
--- a/src/buildtool/common/cli.hpp
+++ b/src/buildtool/common/cli.hpp
@@ -30,6 +30,7 @@
#include "src/buildtool/common/clidefaults.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/logging/log_level.hpp"
+#include "src/utils/cpp/path.hpp"
constexpr auto kDefaultTimeout = std::chrono::milliseconds{300000};
@@ -168,8 +169,19 @@ static inline auto SetupCommonArguments(
app->add_option_function<std::string>(
"-w,--workspace-root",
[clargs](auto const& workspace_root_raw) {
- clargs->workspace_root = std::filesystem::canonical(
- std::filesystem::absolute(workspace_root_raw));
+ std::filesystem::path root = ToNormalPath(workspace_root_raw);
+ if (not root.is_absolute()) {
+ try {
+ root = std::filesystem::absolute(root);
+ } catch (std::exception const& e) {
+ Logger::Log(LogLevel::Error,
+ "Failed to convert workspace root {} ({})",
+ workspace_root_raw,
+ e.what());
+ throw e;
+ }
+ }
+ clargs->workspace_root = root;
},
"Path of the workspace's root directory.")
->type_name("PATH");
@@ -342,8 +354,20 @@ static inline auto SetupCacheArguments(
app->add_option_function<std::string>(
"--local-build-root",
[clargs](auto const& build_root_raw) {
- clargs->local_root = std::filesystem::weakly_canonical(
- std::filesystem::absolute(build_root_raw));
+ std::filesystem::path root = ToNormalPath(build_root_raw);
+ if (!root.is_absolute()) {
+ try {
+ root = std::filesystem::absolute(root);
+ } catch (std::exception const& e) {
+ Logger::Log(
+ LogLevel::Error,
+ "Failed to convert local build root {} ({}).",
+ build_root_raw,
+ e.what());
+ throw e;
+ }
+ }
+ clargs->local_root = root;
},
"Root for local CAS, cache, and build directories.")
->type_name("PATH");
@@ -420,8 +444,20 @@ static inline auto SetupStageArguments(
app->add_option_function<std::string>(
"-o,--output-dir",
[clargs](auto const& output_dir_raw) {
- clargs->output_dir = std::filesystem::weakly_canonical(
- std::filesystem::absolute(output_dir_raw));
+ std::filesystem::path out = ToNormalPath(output_dir_raw);
+ if (not out.is_absolute()) {
+ try {
+ out = std::filesystem::absolute(out);
+ } catch (std::exception const& e) {
+ Logger::Log(
+ LogLevel::Error,
+ "Failed to convert output directory {} ({}).",
+ output_dir_raw,
+ e.what());
+ throw e;
+ }
+ }
+ clargs->output_dir = out;
},
"Path of the directory where outputs will be copied.")
->type_name("PATH")
@@ -459,8 +495,19 @@ static inline auto SetupFetchArguments(
app->add_option_function<std::string>(
"-o,--output-path",
[clargs](auto const& output_path_raw) {
- clargs->output_path = std::filesystem::weakly_canonical(
- std::filesystem::absolute(output_path_raw));
+ std::filesystem::path out = ToNormalPath(output_path_raw);
+ if (not out.is_absolute()) {
+ try {
+ out = std::filesystem::absolute(out);
+ } catch (std::exception const& e) {
+ Logger::Log(LogLevel::Error,
+ "Failed to convert output path {} ({})",
+ output_path_raw,
+ e.what());
+ throw e;
+ }
+ }
+ clargs->output_path = out;
},
"Install path for the artifact. (omit to dump to stdout)")
->type_name("PATH");
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 2bfe631b..498507b1 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -520,7 +520,17 @@ void SetupHashFunction() {
std::filesystem::path const& workspace_root,
FileRoot const& target_root,
std::string const& target_file_name) -> std::string {
- auto cwd = std::filesystem::current_path();
+ std::filesystem::path cwd{};
+ try {
+ cwd = std::filesystem::current_path();
+ } catch (std::exception const& e) {
+ Logger::Log(LogLevel::Warning,
+ "Cannot determine current working directory ({}), assuming "
+ "top-level module is requested",
+ e.what());
+ return ".";
+ }
+
auto subdir = std::filesystem::proximate(cwd, workspace_root);
if (subdir.is_relative() and (*subdir.begin() != "..")) {
// cwd is subdir of workspace_root
@@ -603,9 +613,18 @@ void SetupHashFunction() {
std::move(config)};
}
-[[nodiscard]] auto DetermineWorkspaceRootByLookingForMarkers()
+[[nodiscard]] auto DetermineWorkspaceRootByLookingForMarkers() noexcept
-> std::filesystem::path {
- auto cwd = std::filesystem::current_path();
+ std::filesystem::path cwd{};
+ try {
+ cwd = std::filesystem::current_path();
+ } catch (std::exception const& e) {
+ Logger::Log(LogLevel::Warning,
+ "Failed to determine current working directory ({})",
+ e.what());
+ Logger::Log(LogLevel::Error, "Could not determine workspace root.");
+ std::exit(kExitFailure);
+ }
auto root = cwd.root_path();
cwd = std::filesystem::relative(cwd, root);
auto root_dir = FindRoot(cwd, FileRoot{root}, kRootMarkers);