diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-06-02 11:11:39 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2025-06-02 12:44:48 +0200 |
commit | 24cc2e9fbd536ebc87ee56a2fa01096368e143ce (patch) | |
tree | f2f9ce1699090f72dc55abfb175a295bbd35b2eb | |
parent | f4e9de93b50fe8135d378830577cda687cae28ee (diff) | |
download | justbuild-24cc2e9fbd536ebc87ee56a2fa01096368e143ce.tar.gz |
just-mr: Warn for non-content-fixed repo reached from absent main
If the main repository is marked absent, warn if during the
dependency closure computation any non-content-fixed repositories
are reached, i.e., any "file"-type repositories that are neither
implicitly nor explicitly marked "to_git". Also warn if the main
repository itself is marked absent but is not content fixed.
Add small test checking that the new warning is produced.
-rw-r--r-- | src/other_tools/just_mr/setup_utils.cpp | 63 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup_utils.hpp | 2 | ||||
-rw-r--r-- | test/end-to-end/just-mr/TARGETS | 7 | ||||
-rw-r--r-- | test/end-to-end/just-mr/absent-closure.sh | 99 |
4 files changed, 171 insertions, 0 deletions
diff --git a/src/other_tools/just_mr/setup_utils.cpp b/src/other_tools/just_mr/setup_utils.cpp index 07498441..864aa684 100644 --- a/src/other_tools/just_mr/setup_utils.cpp +++ b/src/other_tools/just_mr/setup_utils.cpp @@ -80,6 +80,57 @@ void WarnUnknownKeys(std::string const& name, ExpressionPtr const& repo_def) { return std::nullopt; } +[[nodiscard]] auto IsAbsent(ExpressionPtr const& repo_def) -> bool { + if (repo_def.IsNotNull() and repo_def->IsMap()) { + if (auto repo = repo_def->Get("repository", Expression::none_t{}); + repo.IsNotNull() and repo->IsMap()) { + if (auto pragma = repo->Get("pragma", Expression::none_t{}); + pragma.IsNotNull() and pragma->IsMap()) { + auto absent = pragma->Get("absent", Expression::none_t{}); + return absent.IsNotNull() and absent->IsBool() and + absent->Bool(); + } + } + } + return false; +} + +[[nodiscard]] auto IsNotContentFixed(ExpressionPtr const& repo_def) -> bool { + if (not repo_def.IsNotNull() or not repo_def->IsMap()) { + return false; + } + if (auto repo = repo_def->Get("repository", Expression::none_t{}); + repo.IsNotNull() and repo->IsMap()) { + // Check if type == "file" + auto type = repo->Get("type", Expression::none_t{}); + if (not type.IsNotNull() or not type->IsString()) { + return false; + } + if (type->String() == "file") { + auto pragma = repo->Get("pragma", Expression::none_t{}); + if (not pragma.IsNotNull() or not pragma->IsMap()) { + return true; // not content-fixed if not to_git + } + // Check for explicit to_git == true + if (auto to_git = pragma->Get("to_git", Expression::none_t{}); + to_git.IsNotNull() and to_git->IsBool() and to_git->Bool()) { + return false; + } + // Check for implicit to_git == true + if (auto special = pragma->Get("special", Expression::none_t{}); + special.IsNotNull() and special->IsString()) { + auto const& special_str = special->String(); + if (special_str == "resolve-partially" or + special_str == "resolve-completely") { + return false; + } + } + return true; // not content-fixed if not to_git + } + } + return false; +} + } // namespace namespace JustMR::Utils { @@ -92,6 +143,8 @@ void ReachableRepositories( std::unordered_set<std::string> include_repos_set; std::unordered_set<std::string> setup_repos_set; + bool absent_main = IsAbsent(repos->Get(main, Expression::none_t{})); + // traverse all bindings of main repository for (std::queue<std::string> to_process({main}); not to_process.empty(); to_process.pop()) { @@ -108,6 +161,16 @@ void ReachableRepositories( } WarnUnknownKeys(repo_name, repos_repo_name); + // Warn if main repo is marked absent and current repo (including main) + // is not content-fixed + if (absent_main and IsNotContentFixed(repos_repo_name)) { + Logger::Log(LogLevel::Warning, + "Found non-content-fixed repository {} as dependency " + "of absent main repository {}", + nlohmann::json(repo_name).dump(), + nlohmann::json(main).dump()); + } + // If the current repo is a computed one, process its target repo if (auto precomputed = GetTargetRepoIfPrecomputed(repos, repo_name)) { to_process.push(*std::move(precomputed)); diff --git a/src/other_tools/just_mr/setup_utils.hpp b/src/other_tools/just_mr/setup_utils.hpp index 6b0d8731..7dc482e6 100644 --- a/src/other_tools/just_mr/setup_utils.hpp +++ b/src/other_tools/just_mr/setup_utils.hpp @@ -63,6 +63,8 @@ struct SetupRepos { namespace Utils { /// \brief Get the repo dependency closure for a given main repository. +/// If main repository is absent, emits a warning for any reachable +/// non-content-fixed repository found. /// \param repos ExpressionPtr of Map type. void ReachableRepositories( ExpressionPtr const& repos, diff --git a/test/end-to-end/just-mr/TARGETS b/test/end-to-end/just-mr/TARGETS index a4c0b402..426b2889 100644 --- a/test/end-to-end/just-mr/TARGETS +++ b/test/end-to-end/just-mr/TARGETS @@ -110,6 +110,12 @@ , "deps": [["", "mr-tool-under-test"], ["", "tool-under-test"]] , "repos": ["fetch-absent (data)"] } +, "absent-closure": + { "type": ["@", "rules", "shell/test", "script"] + , "name": ["absent-closure"] + , "test": ["absent-closure.sh"] + , "deps": [["", "mr-tool-under-test"]] + } , "absent-config": { "type": ["end-to-end", "with serve"] , "name": ["absent-config"] @@ -288,6 +294,7 @@ } , [ "fetch-absent" , "fetch-absent-git-tree" + , "absent-closure" , "absent-config" , "fetch-absent-archives" , "fetch-absent-archives-symlinks" diff --git a/test/end-to-end/just-mr/absent-closure.sh b/test/end-to-end/just-mr/absent-closure.sh new file mode 100644 index 00000000..c4b745cc --- /dev/null +++ b/test/end-to-end/just-mr/absent-closure.sh @@ -0,0 +1,99 @@ +#!/bin/sh +# Copyright 2025 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +### +# Test that users are warned if a non-absent repository is reached from an +# absent main repository. +## + +set -eu + +readonly JUST_MR="${PWD}/bin/mr-tool-under-test" +readonly FILE_ROOT="${TEST_TMPDIR}/file-repos" +readonly TEST_ROOT="${TEST_TMPDIR}/test-root" +readonly LBR="${TEST_TMPDIR}/local-build-root" +readonly OUT="${TEST_TMPDIR}/out" +mkdir -p "${OUT}" + +# Set up file repos +mkdir -p "${FILE_ROOT}/test_dir1" +echo test > "${FILE_ROOT}/test_dir1/test_file" +mkdir -p "${FILE_ROOT}/test_dir2/inner_dir" +echo test > "${FILE_ROOT}/test_dir2/inner_dir/test_file" +mkdir -p "${FILE_ROOT}/test_dir3/inner_dir" +echo test > "${FILE_ROOT}/test_dir3/inner_dir/test_file" + +# Setup sample repository config +mkdir -p "${TEST_ROOT}" +cd "${TEST_ROOT}" +touch ROOT +cat > repos.json <<EOF +{ "repositories": + { "main": + { "repository": + { "type": "file" + , "path": "." + , "pragma": {"absent": true} + } + , "bindings": + { "dep1": "file_repo_not_content_fixed" + , "dep2": "file_repo_to_git_explicit" + , "dep3": "file_repo_to_git_implicit" + } + } + , "file_repo_not_content_fixed": + { "repository": + { "type": "file" + , "path": "${FILE_ROOT}/test_dir1" + } + } + , "file_repo_to_git_explicit": + { "repository": + { "type": "file" + , "path": "${FILE_ROOT}/test_dir2" + , "pragma": {"to_git": true} + } + } + , "file_repo_to_git_implicit": + { "repository": + { "type": "file" + , "path": "${FILE_ROOT}/test_dir3" + , "pragma": {"special": "resolve-partially"} + } + } + } +} +EOF +echo "Repository configuration:" +cat repos.json + +echo +echo Run setup of absent main repository +echo +"${JUST_MR}" --norc --local-build-root "${LBR}" -f "${OUT}/log.txt" setup main 2>&1 + +echo +echo Check expected warnings +echo + +grep 'WARN.* "main" .*absent.* "main"' "${OUT}/log.txt" +grep 'WARN.* "file_repo_not_content_fixed" .*absent.* "main"' "${OUT}/log.txt" +grep 'WARN.* "file_repo_to_git_explicit" .*absent.* "main"' "${OUT}/log.txt" && + echo "should have failed" && exit 1 || : +grep 'WARN.* "file_repo_to_git_implicit" .*absent.* "main"' "${OUT}/log.txt" && + echo "should have failed" && exit 1 || : + +echo +echo OK |