From 31b9578ad028cf5eff7fa426f134891cbba83ca9 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 3 Aug 2020 19:09:20 -0400 Subject: fix(3p/nix): Fix parseDrvPathWithOutputs At some point the behavior of this function got changed as part of our cleanup - this fixes it to behave the way the rest of the codebase expects (and how it is documented in the header) and covers it with a few tests. Change-Id: Id4c91232968e73489cd866fb4a2a84bcf20d875e Reviewed-on: https://cl.tvl.fyi/c/depot/+/1629 Tested-by: BuildkiteCI Reviewed-by: tazjin --- third_party/nix/src/libstore/derivations.cc | 6 +++--- third_party/nix/src/tests/derivations_test.cc | 30 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/third_party/nix/src/libstore/derivations.cc b/third_party/nix/src/libstore/derivations.cc index 8a50f3c85b4d..978d39b94e7d 100644 --- a/third_party/nix/src/libstore/derivations.cc +++ b/third_party/nix/src/libstore/derivations.cc @@ -408,15 +408,15 @@ Hash hashDerivationModulo(Store& store, Derivation drv) { return hashString(htSHA256, drv.unparse()); } -// TODO(tazjin): doc comment? DrvPathWithOutputs parseDrvPathWithOutputs(absl::string_view path) { auto pos = path.find('!'); if (pos == absl::string_view::npos) { return DrvPathWithOutputs(path, std::set()); } - return DrvPathWithOutputs(path.substr(pos + 1), - absl::StrSplit(path, absl::ByChar(','))); + return DrvPathWithOutputs( + path.substr(0, pos), + absl::StrSplit(path.substr(pos + 1), absl::ByChar(','))); } Path makeDrvPathWithOutputs(const Path& drvPath, diff --git a/third_party/nix/src/tests/derivations_test.cc b/third_party/nix/src/tests/derivations_test.cc index e026fbe3b11c..1e2719addaf1 100644 --- a/third_party/nix/src/tests/derivations_test.cc +++ b/third_party/nix/src/tests/derivations_test.cc @@ -103,4 +103,34 @@ RC_GTEST_FIXTURE_PROP(DerivationsTest, UnparseParseRoundTrip, AssertDerivationsEqual(drv, parsed); } +class ParseDrvPathWithOutputsTest : public DerivationsTest {}; + +TEST(ParseDrvPathWithOutputsTest, ParseDrvPathWithOutputs) { + auto input = "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test.drv!out"; + auto result = nix::parseDrvPathWithOutputs(input); + + ASSERT_EQ(result.first, + "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test.drv"); + ASSERT_EQ(result.second, nix::PathSet{"out"}); +} + +TEST(ParseDrvPathWithOutputsTest, ParseDrvPathWithMultipleOutputs) { + auto input = "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test.drv!out,dev"; + auto result = nix::parseDrvPathWithOutputs(input); + + nix::PathSet expected = {"out", "dev"}; + + ASSERT_EQ(result.first, + "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test.drv"); + ASSERT_EQ(result.second, expected); +} + +TEST(ParseDrvPathWithOutputsTest, ParseDrvPathWithNoOutputs) { + auto input = "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test"; + auto result = nix::parseDrvPathWithOutputs(input); + + ASSERT_EQ(result.first, "/nix/store/my51f75kp056md84gq2v08pd140pcz57-test"); + ASSERT_EQ(result.second, nix::PathSet()); +} + } // namespace nix -- cgit 1.4.1