From db961e1e9fba6e0c439f69ac8342ef887d9d19a6 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 20 Jun 2023 17:54:07 +0200 Subject: Add non-upwards symlinks in the rule language... via a 'SYMLINK' constructor function. This works similarly to the 'FILE' construct, but the name given must point to a non-upwards symlink and a symlink artifact is being generated from it. Also updates the relevant tests. --- .../build_engine/target_map/target_map.cpp | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/buildtool/build_engine/target_map/target_map.cpp') diff --git a/src/buildtool/build_engine/target_map/target_map.cpp b/src/buildtool/build_engine/target_map/target_map.cpp index d2e73f07..99f6d9f0 100644 --- a/src/buildtool/build_engine/target_map/target_map.cpp +++ b/src/buildtool/build_engine/target_map/target_map.cpp @@ -1471,6 +1471,17 @@ void TreeTarget( .config = Configuration{}}); } + for (const auto& x : dir_entries.SymlinksIterator()) { + v.emplace_back(ConfiguredTarget{ + .target = + BuildMaps::Base::EntityName{ + target.repository, + dir_name, + x, + BuildMaps::Base::ReferenceType::kSymlink}, + .config = Configuration{}}); + } + for (const auto& x : dir_entries.DirectoriesIterator()) { v.emplace_back(ConfiguredTarget{ .target = @@ -1573,6 +1584,15 @@ void GlobTargetWithDirEntry( BuildMaps::Base::ReferenceType::kFile}); } } + for (auto const& x : dir.SymlinksIterator()) { + if (fnmatch(pattern.c_str(), x.c_str(), 0) == 0) { + matches.emplace_back(BuildMaps::Base::EntityName{ + target.repository, + target.module, + x, + BuildMaps::Base::ReferenceType::kSymlink}); + } + } source_target_map->ConsumeAfterKeysReady( ts, matches, @@ -1644,6 +1664,23 @@ auto CreateTargetMap( fatal); }); } + else if (key.target.GetNamedTarget().reference_t == + BuildMaps::Base::ReferenceType::kSymlink) { + // Not a defined target, treat as source target + source_target_map->ConsumeAfterKeysReady( + ts, + {key.target}, + [setter](auto values) { + (*setter)(AnalysedTargetPtr{*values[0]}); + }, + [logger, target = key.target](auto const& msg, auto fatal) { + (*logger)(fmt::format("While analysing target {} as " + "symlink:\n{}", + target.ToString(), + msg), + fatal); + }); + } else if (key.target.GetNamedTarget().reference_t == BuildMaps::Base::ReferenceType::kGlob) { auto wrapped_logger = std::make_shared( -- cgit v1.2.3