summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-08-18 16:32:58 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-08-19 14:09:01 +0200
commit141035d936a0b361d2802499fd9b824e8c6a6a5e (patch)
tree0f5bc621a5fed369c9cbaaaccf03d4d83ad9e948
parent37f0272bf0d6c75b62c7bb10f3d1b80e1d1c41fb (diff)
downloadjustbuild-141035d936a0b361d2802499fd9b824e8c6a6a5e.tar.gz
main: honor configuration for target_file name
... also when determining default module or target.
-rw-r--r--src/buildtool/main/main.cpp10
-rw-r--r--test/end-to-end/TARGETS1
-rw-r--r--test/end-to-end/cli/TARGETS8
-rw-r--r--test/end-to-end/cli/defaults.sh53
4 files changed, 66 insertions, 6 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index b7b22056..30035819 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -348,13 +348,11 @@ void SetupHashFunction() {
[[nodiscard]] auto DetermineCurrentModule(
std::filesystem::path const& workspace_root,
FileRoot const& target_root,
- std::optional<std::string> const& target_file_name_opt) -> std::string {
+ std::string const& target_file_name) -> std::string {
auto cwd = std::filesystem::current_path();
auto subdir = std::filesystem::proximate(cwd, workspace_root);
if (subdir.is_relative() and (*subdir.begin() != "..")) {
// cwd is subdir of workspace_root
- std::string target_file_name =
- target_file_name_opt ? *target_file_name_opt : "TARGETS";
if (auto root_dir = FindRoot(subdir, target_root, {target_file_name})) {
return root_dir->string();
}
@@ -376,10 +374,12 @@ void SetupHashFunction() {
std::exit(kExitFailure);
}
auto current_module = std::string{"."};
+ std::string target_file_name =
+ *RepositoryConfig::Instance().TargetFileName(main_repo);
if (main_ws_root) {
// module detection only works if main workspace is on the file system
current_module = DetermineCurrentModule(
- *main_ws_root, *target_root, clargs.target_file_name);
+ *main_ws_root, *target_root, target_file_name);
}
auto config = ReadConfiguration(clargs);
if (clargs.target) {
@@ -397,8 +397,6 @@ void SetupHashFunction() {
}
return Target::ConfiguredTarget{std::move(*entity), std::move(config)};
}
- std::string target_file_name =
- clargs.target_file_name ? *clargs.target_file_name : "TARGETS";
auto const target_file =
(std::filesystem::path{current_module} / target_file_name).string();
auto file_content = target_root->ReadFile(target_file);
diff --git a/test/end-to-end/TARGETS b/test/end-to-end/TARGETS
index 1a984106..9bf99a36 100644
--- a/test/end-to-end/TARGETS
+++ b/test/end-to-end/TARGETS
@@ -5,6 +5,7 @@
, "tainted": ["test"]
, "dirs":
[ [["./", "actions", "TESTS"], "actions"]
+ , [["./", "cli", "TESTS"], "cli"]
, [["./", "generated-binary", "TESTS"], "generated-binary"]
, [["./", "targets", "TESTS"], "targets"]
, [["./", "user-errors", "TESTS"], "user-errors"]
diff --git a/test/end-to-end/cli/TARGETS b/test/end-to-end/cli/TARGETS
new file mode 100644
index 00000000..dd7b0444
--- /dev/null
+++ b/test/end-to-end/cli/TARGETS
@@ -0,0 +1,8 @@
+{ "defaults":
+ { "type": ["@", "rules", "shell/test", "script"]
+ , "name": ["defaults"]
+ , "test": ["defaults.sh"]
+ , "deps": [["test/end-to-end", "tool-under-test"]]
+ }
+, "TESTS": {"type": "install", "tainted": ["test"], "deps": ["defaults"]}
+}
diff --git a/test/end-to-end/cli/defaults.sh b/test/end-to-end/cli/defaults.sh
new file mode 100644
index 00000000..70ae7ec7
--- /dev/null
+++ b/test/end-to-end/cli/defaults.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+set -e
+
+TOOL=$(realpath ./bin/tool-under-test)
+mkdir -p .root
+BUILDROOT=$(realpath .root)
+mkdir -p out
+OUTDIR=$(realpath out)
+
+
+mkdir src
+cd src
+touch ROOT
+
+cat > repos.json <<'EOF'
+{"repositories": {"": {"target_file_name": "TARGETS.local"}}}
+EOF
+export CONF=$(realpath repos.json)
+
+cat > TARGETS.local <<'EOF'
+{"a": {"type": "file_gen", "name": "a.txt", "data": "A-top-level"}}
+EOF
+
+echo
+echo === Default target ===
+${TOOL} build -C $CONF --local-build-root ${BUILDROOT} -Pa.txt | grep top-level
+
+
+echo
+echo === top-level module found ===
+
+mkdir foo
+cd foo
+cat > TARGETS <<'EOF'
+{"a": {"type": "file_gen", "name": "a.txt", "data": "WRONG"}}
+EOF
+${TOOL} build -C $CONF --local-build-root ${BUILDROOT} -Pa.txt | grep top-level
+
+echo === correct root referece ===
+
+cat > TARGETS.local <<'EOF'
+{"a": {"type": "file_gen", "name": "b.txt", "data": "A-local"}
+, "": {"type": "install", "deps": ["a", ["", "a"]]}
+}
+EOF
+
+${TOOL} install -C $CONF --local-build-root ${BUILDROOT} -o ${OUTDIR}/top-ref 2>&1
+echo
+grep top-level ${OUTDIR}/top-ref/a.txt
+grep local ${OUTDIR}/top-ref/b.txt
+
+echo
+echo === DONE ===