summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/buildtool/build_engine/base_maps/source_map.test.cpp29
-rw-r--r--test/buildtool/build_engine/target_map/TARGETS1
-rw-r--r--test/buildtool/build_engine/target_map/data_targets/simple_targets/TARGETS22
-rw-r--r--test/buildtool/build_engine/target_map/data_targets/symlink_reference/TARGETS9
-rw-r--r--test/buildtool/build_engine/target_map/target_map.test.cpp86
5 files changed, 139 insertions, 8 deletions
diff --git a/test/buildtool/build_engine/base_maps/source_map.test.cpp b/test/buildtool/build_engine/base_maps/source_map.test.cpp
index 3b787ffe..05157870 100644
--- a/test/buildtool/build_engine/base_maps/source_map.test.cpp
+++ b/test/buildtool/build_engine/base_maps/source_map.test.cpp
@@ -28,6 +28,14 @@ namespace {
using namespace BuildMaps::Base; // NOLINT
void SetupConfig(bool use_git) {
+ // manually create locally a test symlink in data_src; should match the
+ // git test_repo structure
+ if (not use_git) {
+ auto link_path = kBasePath / "data_src/foo/link";
+ if (not FileSystemManager::Exists(link_path)) {
+ REQUIRE(FileSystemManager::CreateSymlink("dummy", link_path));
+ }
+ }
auto root = FileRoot{kBasePath / "data_src"};
if (use_git) {
auto repo_path = CreateTestRepo();
@@ -156,3 +164,24 @@ TEST_CASE("subdir file") {
CHECK(artifacts["bar/file"]["data"]["size"] == 0);
}
}
+
+TEST_CASE("subdir symlink") {
+ nlohmann::json artifacts;
+ auto name = EntityName{"", "foo", "link"};
+ auto consumer = [&artifacts](auto values) {
+ artifacts = (*values[0])->Artifacts()->ToJson();
+ };
+
+ SECTION("via file") {
+ CHECK(ReadSourceTarget(name, consumer, /*use_git=*/false));
+ CHECK(artifacts["link"]["type"] == "LOCAL");
+ CHECK(artifacts["link"]["data"]["path"] == "foo/link");
+ }
+
+ SECTION("via git tree") {
+ CHECK(ReadSourceTarget(name, consumer, /*use_git=*/true));
+ CHECK(artifacts["link"]["type"] == "KNOWN");
+ CHECK(artifacts["link"]["data"]["id"] == kSrcLinkId);
+ CHECK(artifacts["link"]["data"]["size"] == 5); // content: dummy
+ }
+}
diff --git a/test/buildtool/build_engine/target_map/TARGETS b/test/buildtool/build_engine/target_map/TARGETS
index 7eae3c0c..e83c22d1 100644
--- a/test/buildtool/build_engine/target_map/TARGETS
+++ b/test/buildtool/build_engine/target_map/TARGETS
@@ -67,6 +67,7 @@
, "data_targets/result/TARGETS"
, "data_targets/simple_rules/TARGETS"
, "data_targets/simple_targets/TARGETS"
+ , "data_targets/symlink_reference/TARGETS"
, "data_targets/tree/TARGETS"
, "data_targets/x/TARGETS"
, "data_targets/x/x/TARGETS"
diff --git a/test/buildtool/build_engine/target_map/data_targets/simple_targets/TARGETS b/test/buildtool/build_engine/target_map/data_targets/simple_targets/TARGETS
index 4306c3ae..0001a223 100644
--- a/test/buildtool/build_engine/target_map/data_targets/simple_targets/TARGETS
+++ b/test/buildtool/build_engine/target_map/data_targets/simple_targets/TARGETS
@@ -7,11 +7,11 @@
}
, "collect dep artifacts":
{ "type": ["simple_rules", "collect deps"]
- , "deps": ["foo.txt", "bar.txt", "baz.txt"]
+ , "deps": ["foo.txt", "bar.txt", "baz.txt", "link"]
}
, "collect as runfiles":
{ "type": ["simple_rules", "collect deps as runfiles"]
- , "deps": ["foo.txt", "bar.txt", "baz.txt"]
+ , "deps": ["foo.txt", "bar.txt", "baz.txt", "link"]
}
, "stage blob":
{ "type": ["simple_rules", "text file"]
@@ -43,16 +43,26 @@
]
, "analyze": ["collect as runfiles"]
}
+, "use generic sym":
+ { "type": "generic"
+ , "deps": ["bar.txt"]
+ , "cmds": ["ln -s $(cat bar.txt) sym"]
+ , "outs": ["sym"]
+ }
, "use generic":
{ "type": "generic"
- , "deps": ["foo.txt", "bar.txt"]
- , "cmds": ["cat foo.txt bar.txt > out", "echo 'DONE' >> out"]
+ , "deps": ["foo.txt", "link"]
+ , "cmds": ["cat foo.txt > out", "readlink link > out", "echo 'DONE' >> out"]
, "outs": ["out"]
}
, "install":
{ "type": "install"
- , "deps": ["foo.txt", "bar.txt"]
- , "files": {"combined.txt": "use generic", "subdir/restaged.txt": "bar.txt"}
+ , "deps": ["foo.txt", "bar.txt", "link"]
+ , "files":
+ { "link_gen": "use generic sym"
+ , "combined.txt": "use generic"
+ , "subdir/restaged.txt": "bar.txt"
+ }
, "dirs":
[ ["collect as runfiles", "mix/in/this/subdir"]
, ["runfile names", "mix/in/this/subdir"]
diff --git a/test/buildtool/build_engine/target_map/data_targets/symlink_reference/TARGETS b/test/buildtool/build_engine/target_map/data_targets/symlink_reference/TARGETS
new file mode 100644
index 00000000..c05d9517
--- /dev/null
+++ b/test/buildtool/build_engine/target_map/data_targets/symlink_reference/TARGETS
@@ -0,0 +1,9 @@
+{ "_link":
+ {"type": "install", "files": {"raw_data/link": ["SYMLINK", null, "link"]}}
+, "link":
+ { "type": "generic"
+ , "deps": ["_link"]
+ , "outs": ["link"]
+ , "cmds": ["ln -s $(readlink raw_data/link | tr 'a-z' 'A-Z') link"]
+ }
+}
diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp
index 9b667425..98d3a938 100644
--- a/test/buildtool/build_engine/target_map/target_map.test.cpp
+++ b/test/buildtool/build_engine/target_map/target_map.test.cpp
@@ -28,7 +28,24 @@ namespace {
using none_t = Expression::none_t;
+auto CreateSymlinks() -> bool {
+ auto base_src = std::filesystem::path(
+ "test/buildtool/build_engine/target_map/data_src");
+ // create the symlinks
+ REQUIRE(FileSystemManager::CreateSymlink(
+ "dummy", base_src / "a" / "b" / "targets_here" / "c" / "d" / "link"));
+ REQUIRE(FileSystemManager::CreateSymlink(
+ "dummy", base_src / "symlink_reference" / "link"));
+ REQUIRE(FileSystemManager::CreateSymlink(
+ "dummy", base_src / "simple_targets" / "link"));
+
+ return true;
+}
+
void SetupConfig() {
+ // manually create locally test symlinks in data_src, but only once
+ [[maybe_unused]] static auto done = CreateSymlinks();
+ // create the file roots
auto info = RepositoryConfig::RepositoryInfo{
FileRoot{"test/buildtool/build_engine/target_map/data_src"},
FileRoot{"test/buildtool/build_engine/target_map/data_targets"},
@@ -85,6 +102,32 @@ TEST_CASE("simple targets") {
CHECK(artifact->IsArtifact());
}
+ SECTION("Actual source symlink file") {
+ {
+ error_msg = "NONE";
+ error = false;
+
+ TaskSystem ts;
+ target_map.ConsumeAfterKeysReady(
+ &ts,
+ {BuildMaps::Target::ConfiguredTarget{
+ .target =
+ BuildMaps::Base::EntityName{
+ "", "a/b/targets_here", "c/d/link"},
+ .config = empty_config}},
+ [&result](auto values) { result = *values[0]; },
+ [&error, &error_msg](std::string const& msg, bool /*unused*/) {
+ error = true;
+ error_msg = msg;
+ });
+ }
+ CHECK(!error);
+ CHECK(error_msg == "NONE");
+ auto artifacts = result->Artifacts();
+ ExpressionPtr artifact = artifacts->Get("c/d/link", none_t{});
+ CHECK(artifact->IsArtifact());
+ }
+
SECTION("No targets file here") {
{
error_msg = "NONE";
@@ -248,6 +291,7 @@ TEST_CASE("simple targets") {
"simple_targets/bar.txt");
CHECK(artifacts_desc["baz.txt"]["data"]["path"] ==
"simple_targets/baz.txt");
+ CHECK(artifacts_desc["link"]["data"]["path"] == "simple_targets/link");
}
SECTION("Rule stages blob") {
@@ -441,7 +485,7 @@ TEST_CASE("generator functions in string arguments") {
CHECK(!error);
CHECK(error_msg == "NONE");
CHECK(result->Artifacts()->ToJson()["index.txt"]["type"] == "KNOWN");
- CHECK(result->Blobs()[0] == "bar.txt;baz.txt;foo.txt");
+ CHECK(result->Blobs()[0] == "bar.txt;baz.txt;foo.txt;link");
}
SECTION("runfies") {
@@ -465,7 +509,7 @@ TEST_CASE("generator functions in string arguments") {
CHECK(!error);
CHECK(error_msg == "NONE");
CHECK(result->Artifacts()->ToJson()["index.txt"]["type"] == "KNOWN");
- CHECK(result->Blobs()[0] == "bar.txt;baz.txt;foo.txt");
+ CHECK(result->Blobs()[0] == "bar.txt;baz.txt;foo.txt;link");
}
}
@@ -539,8 +583,12 @@ TEST_CASE("built-in rules") {
CHECK(stage["foo.txt"]["data"]["path"] == "simple_targets/foo.txt");
CHECK(stage["bar.txt"]["type"] == "LOCAL");
CHECK(stage["bar.txt"]["data"]["path"] == "simple_targets/bar.txt");
+ CHECK(stage["bar.txt"]["type"] == "LOCAL");
+ CHECK(stage["link"]["data"]["path"] == "simple_targets/link");
CHECK(stage["combined.txt"]["type"] == "ACTION");
CHECK(stage["combined.txt"]["data"]["path"] == "out");
+ CHECK(stage["link_gen"]["type"] == "ACTION");
+ CHECK(stage["link_gen"]["data"]["path"] == "sym");
CHECK(stage["subdir/restaged.txt"]["type"] == "LOCAL");
CHECK(stage["subdir/restaged.txt"]["data"]["path"] ==
"simple_targets/bar.txt");
@@ -550,6 +598,8 @@ TEST_CASE("built-in rules") {
"simple_targets/bar.txt");
CHECK(stage["mix/in/this/subdir/baz.txt"]["data"]["path"] ==
"simple_targets/baz.txt");
+ CHECK(stage["mix/in/this/subdir/link"]["data"]["path"] ==
+ "simple_targets/link");
CHECK(stage["mix/in/this/subdir/index.txt"]["type"] == "KNOWN");
}
@@ -667,6 +717,38 @@ TEST_CASE("target reference") {
"file_reference/hello.txt");
}
+ SECTION("symlink vs target") {
+ error = false;
+ error_msg = "NONE";
+ {
+ TaskSystem ts;
+ target_map.ConsumeAfterKeysReady(
+ &ts,
+ {BuildMaps::Target::ConfiguredTarget{
+ .target =
+ BuildMaps::Base::EntityName{
+ "", "symlink_reference", "link"},
+ .config = empty_config}},
+ [&result](auto values) { result = *values[0]; },
+ [&error, &error_msg](std::string const& msg, bool /*unused*/) {
+ error = true;
+ error_msg = msg;
+ });
+ }
+ CHECK(!error);
+ CHECK(error_msg == "NONE");
+ CHECK(result->Artifacts()->ToJson()["link"]["type"] == "ACTION");
+ CHECK(result->Artifacts()->ToJson()["link"]["data"]["path"] == "link");
+
+ CHECK(result->Actions().size() == 1);
+ CHECK(
+ result->Actions()[0]->ToJson()["input"]["raw_data/link"]["type"] ==
+ "LOCAL");
+ CHECK(result->Actions()[0]
+ ->ToJson()["input"]["raw_data/link"]["data"]["path"] ==
+ "symlink_reference/link");
+ }
+
SECTION("relative address") {
error = false;
error_msg = "NONE";