Merge changes I36e3e951,I38e9174d into main
* changes: local-derivation-goal: improve "illegal reference" error nix-util: Add concatMapStrings
This commit is contained in:
@@ -2512,8 +2512,24 @@ void LocalDerivationGoal::checkOutputs(const std::map<std::string, ValidPathInfo
|
||||
spec.insert(output->path);
|
||||
else if (auto storePath = get(alreadyRegisteredOutputs, i))
|
||||
spec.insert(*storePath);
|
||||
else
|
||||
throw BuildError("derivation contains an illegal reference specifier '%s'", i);
|
||||
else {
|
||||
std::string outputsListing = concatMapStringsSep(
|
||||
", ",
|
||||
newlyBuiltOutputs,
|
||||
[](auto & o) { return o.first; }
|
||||
);
|
||||
if (!alreadyRegisteredOutputs.empty()) {
|
||||
outputsListing.append(outputsListing.empty() ? "" : ", ");
|
||||
outputsListing.append(concatMapStringsSep(
|
||||
", ",
|
||||
alreadyRegisteredOutputs,
|
||||
[](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
|
||||
|
||||
+17
-1
@@ -5,6 +5,7 @@
|
||||
#include "lix/libutil/types.hh"
|
||||
|
||||
#include <vector>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
namespace nix {
|
||||
|
||||
@@ -34,7 +35,6 @@ MakeError(FormatError, Error);
|
||||
*/
|
||||
template<class C> C tokenizeString(std::string_view s, std::string_view separators = " \t\n\r");
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate the given strings with a separator between the
|
||||
* elements.
|
||||
@@ -63,6 +63,22 @@ auto concatStrings(Parts && ... parts)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add quotes around a collection of strings.
|
||||
*/
|
||||
|
||||
@@ -74,4 +74,10 @@ rec {
|
||||
buildCommand = ''echo ${dep} > "''${outputs[out]}"'';
|
||||
};
|
||||
|
||||
test12 = makeTest 12 {
|
||||
builder = builtins.toFile "builder.sh" "mkdir $out $lib";
|
||||
outputs = ["out" "lib"];
|
||||
disallowedReferences = ["dev"];
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -51,3 +51,7 @@ if isDaemonNewer 2.12pre20230103; then
|
||||
test11=$(nix-build -o $RESULT check-refs.nix -A test11)
|
||||
[[ -z $(nix-store -q --references "$test11") ]]
|
||||
fi
|
||||
|
||||
# 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"
|
||||
|
||||
@@ -667,4 +667,43 @@ namespace nix {
|
||||
ASSERT_EQ(filterANSIEscapes("f𐍈𐍈bär", true, 4), "f𐍈𐍈b");
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* concatMapStringsSep
|
||||
* --------------------------------------------------------------------------*/
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user