1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Merge pull request #12105 from trofi/local-derivation-goal-better-reference-bug

local-derivation-goal: improve "illegal reference" error
This commit is contained in:
mergify[bot] 2025-03-25 14:54:27 +00:00 committed by GitHub
commit 9b0f455609
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 75 additions and 2 deletions

View file

@ -2991,8 +2991,12 @@ void LocalDerivationGoal::checkOutputs(const std::map<std::string, ValidPathInfo
spec.insert(worker.store.parseStorePath(i)); spec.insert(worker.store.parseStorePath(i));
else if (auto output = get(outputs, i)) else if (auto output = get(outputs, i))
spec.insert(output->path); spec.insert(output->path);
else else {
throw BuildError("derivation contains an illegal reference specifier '%s'", i); std::string outputsListing = concatMapStringsSep(", ", outputs, [](auto & o) { return o.first; });
throw BuildError("derivation '%s' output check for '%s' contains an illegal reference specifier '%s',"
" expected store path or output name (one of [%s])",
worker.store.printStorePath(drvPath), outputName, i, outputsListing);
}
} }
auto used = recursive auto used = recursive

View file

@ -80,6 +80,42 @@ TEST(concatStringsSep, buildSingleString)
ASSERT_EQ(concatStringsSep(",", strings), "this"); ASSERT_EQ(concatStringsSep(",", strings), "this");
} }
TEST(concatMapStringsSep, empty)
{
Strings strings;
ASSERT_EQ(concatMapStringsSep(",", strings, [](const std::string & s) { return s; }), "");
}
TEST(concatMapStringsSep, justOne)
{
Strings strings;
strings.push_back("this");
ASSERT_EQ(concatMapStringsSep(",", strings, [](const std::string & s) { return s; }), "this");
}
TEST(concatMapStringsSep, two)
{
Strings strings;
strings.push_back("this");
strings.push_back("that");
ASSERT_EQ(concatMapStringsSep(",", strings, [](const std::string & s) { return s; }), "this,that");
}
TEST(concatMapStringsSep, map)
{
std::map<std::string, std::string> strings;
strings["this"] = "that";
strings["1"] = "one";
ASSERT_EQ(
concatMapStringsSep(
", ", strings, [](const std::pair<std::string, std::string> & s) { return s.first + " -> " + s.second; }),
"1 -> one, this -> that");
}
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* dropEmptyInitThenConcatStringsSep * dropEmptyInitThenConcatStringsSep
* --------------------------------------------------------------------------*/ * --------------------------------------------------------------------------*/

View file

@ -39,6 +39,7 @@ basicSplitString(std::basic_string_view<OsChar> s, std::basic_string_view<OsChar
template std::string concatStringsSep(std::string_view, const std::list<std::string> &); template std::string concatStringsSep(std::string_view, const std::list<std::string> &);
template std::string concatStringsSep(std::string_view, const std::set<std::string> &); template std::string concatStringsSep(std::string_view, const std::set<std::string> &);
template std::string concatStringsSep(std::string_view, const std::vector<std::string> &); template std::string concatStringsSep(std::string_view, const std::vector<std::string> &);
template std::string concatStringsSep(std::string_view, const boost::container::small_vector<std::string, 64> &);
typedef std::string_view strings_2[2]; typedef std::string_view strings_2[2];
template std::string concatStringsSep(std::string_view, const strings_2 &); template std::string concatStringsSep(std::string_view, const strings_2 &);

View file

@ -6,6 +6,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <boost/container/small_vector.hpp>
namespace nix { namespace nix {
/* /*
@ -54,6 +56,21 @@ std::string concatStringsSep(const std::string_view sep, const C & ss);
extern template std::string concatStringsSep(std::string_view, const std::list<std::string> &); extern template std::string concatStringsSep(std::string_view, const std::list<std::string> &);
extern template std::string concatStringsSep(std::string_view, const std::set<std::string> &); extern template std::string concatStringsSep(std::string_view, const std::set<std::string> &);
extern template std::string concatStringsSep(std::string_view, const std::vector<std::string> &); extern template std::string concatStringsSep(std::string_view, const std::vector<std::string> &);
extern template std::string concatStringsSep(std::string_view, const boost::container::small_vector<std::string, 64> &);
/**
* Apply a function to the `iterable`'s items and concat them with `separator`.
*/
template<class C, class F>
std::string concatMapStringsSep(std::string_view separator, const C & iterable, F fn)
{
boost::container::small_vector<std::string, 64> strings;
strings.reserve(iterable.size());
for (const auto & elem : iterable) {
strings.push_back(fn(elem));
}
return concatStringsSep(separator, strings);
}
/** /**
* Ignore any empty strings at the start of the list, and then concatenate the * Ignore any empty strings at the start of the list, and then concatenate the

View file

@ -79,4 +79,13 @@ rec {
buildCommand = ''echo ${dep} > "''${outputs[out]}"''; buildCommand = ''echo ${dep} > "''${outputs[out]}"'';
}; };
test12 = makeTest 12 {
builder = builtins.toFile "builder.sh" "mkdir $out $lib";
outputs = [
"out"
"lib"
];
disallowedReferences = [ "dev" ];
};
} }

View file

@ -60,3 +60,9 @@ if ! isTestOnNixOS; then
fi fi
fi fi
if isDaemonNewer "2.28pre20241225"; then
# test12 should fail (syntactically invalid).
expectStderr 1 nix-build -vvv -o "$RESULT" check-refs.nix -A test12 >"$TEST_ROOT/test12.stderr"
grepQuiet -F "output check for 'lib' contains an illegal reference specifier 'dev', expected store path or output name (one of [lib, out])" < "$TEST_ROOT/test12.stderr"
fi