Skip to content

Commit dc8c146

Browse files
authored
Merge pull request #14097 from obsidiansystems/light-realisation-improvements
Realisation improvements, dummy store support, unit testing
2 parents 28adcfd + 5592bb7 commit dc8c146

32 files changed

+423
-254
lines changed

src/libcmd/built-path.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ RealisedPath::Set BuiltPath::toRealisedPaths(Store & store) const
117117
"the derivation '%s' has unrealised output '%s' (derived-path.cc/toRealisedPaths)",
118118
store.printStorePath(p.drvPath->outPath()),
119119
outputName);
120-
auto thisRealisation = store.queryRealisation(DrvOutput{*drvOutput, outputName});
120+
DrvOutput key{*drvOutput, outputName};
121+
auto thisRealisation = store.queryRealisation(key);
121122
assert(thisRealisation); // We’ve built it, so we must
122123
// have the realisation
123-
res.insert(*thisRealisation);
124+
res.insert(Realisation{*thisRealisation, std::move(key)});
124125
} else {
125126
res.insert(outputPath);
126127
}

src/libstore-tests/common-protocol.cc

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,34 @@ CHARACTERIZATION_TEST(
112112
"realisation",
113113
(std::tuple<Realisation, Realisation>{
114114
Realisation{
115-
.id =
116-
DrvOutput{
117-
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
118-
.outputName = "baz",
119-
},
120-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
121-
.signatures = {"asdf", "qwer"},
115+
{
116+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
117+
.signatures = {"asdf", "qwer"},
118+
},
119+
DrvOutput{
120+
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
121+
.outputName = "baz",
122+
},
122123
},
123124
Realisation{
124-
.id =
125-
{
126-
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
127-
.outputName = "baz",
128-
},
129-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
130-
.signatures = {"asdf", "qwer"},
131-
.dependentRealisations =
132-
{
125+
{
126+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
127+
.signatures = {"asdf", "qwer"},
128+
.dependentRealisations =
133129
{
134-
DrvOutput{
135-
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
136-
.outputName = "quux",
130+
{
131+
DrvOutput{
132+
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
133+
.outputName = "quux",
134+
},
135+
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
137136
},
138-
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
139137
},
140-
},
138+
},
139+
{
140+
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
141+
.outputName = "baz",
142+
},
141143
},
142144
}))
143145

src/libstore-tests/dummy-store.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <gtest/gtest.h>
22

3-
#include "nix/store/dummy-store.hh"
3+
#include "nix/store/dummy-store-impl.hh"
44
#include "nix/store/globals.hh"
55
#include "nix/store/realisation.hh"
66

@@ -13,7 +13,7 @@ TEST(DummyStore, realisation_read)
1313
auto store = [] {
1414
auto cfg = make_ref<DummyStoreConfig>(StoreReference::Params{});
1515
cfg->readOnly = false;
16-
return cfg->openStore();
16+
return cfg->openDummyStore();
1717
}();
1818

1919
auto drvHash = Hash::parseExplicitFormatUnprefixed(
@@ -22,6 +22,17 @@ TEST(DummyStore, realisation_read)
2222
auto outputName = "foo";
2323

2424
EXPECT_EQ(store->queryRealisation({drvHash, outputName}), nullptr);
25+
26+
UnkeyedRealisation value{
27+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"},
28+
};
29+
30+
store->buildTrace.insert({drvHash, {{outputName, make_ref<UnkeyedRealisation>(value)}}});
31+
32+
auto value2 = store->queryRealisation({drvHash, outputName});
33+
34+
ASSERT_TRUE(value2);
35+
EXPECT_EQ(*value2, value);
2536
}
2637

2738
} // namespace nix

src/libstore-tests/realisation.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ INSTANTIATE_TEST_SUITE_P(
4949
RealisationJsonTest,
5050
([] {
5151
Realisation simple{
52-
53-
.id =
54-
{
55-
.drvHash = Hash::parseExplicitFormatUnprefixed(
56-
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
57-
HashAlgorithm::SHA256,
58-
HashFormat::Base16),
59-
.outputName = "foo",
60-
},
61-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"},
52+
{
53+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"},
54+
},
55+
{
56+
.drvHash = Hash::parseExplicitFormatUnprefixed(
57+
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
58+
HashAlgorithm::SHA256,
59+
HashFormat::Base16),
60+
.outputName = "foo",
61+
},
6262
};
6363
return ::testing::Values(
6464
std::pair{

src/libstore-tests/serve-protocol.cc

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,34 @@ VERSIONED_CHARACTERIZATION_TEST(
9595
defaultVersion,
9696
(std::tuple<Realisation, Realisation>{
9797
Realisation{
98-
.id =
99-
DrvOutput{
100-
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
101-
.outputName = "baz",
102-
},
103-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
104-
.signatures = {"asdf", "qwer"},
98+
{
99+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
100+
.signatures = {"asdf", "qwer"},
101+
},
102+
{
103+
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
104+
.outputName = "baz",
105+
},
105106
},
106107
Realisation{
107-
.id =
108-
{
109-
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
110-
.outputName = "baz",
111-
},
112-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
113-
.signatures = {"asdf", "qwer"},
114-
.dependentRealisations =
115-
{
108+
{
109+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
110+
.signatures = {"asdf", "qwer"},
111+
.dependentRealisations =
116112
{
117-
DrvOutput{
118-
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
119-
.outputName = "quux",
113+
{
114+
DrvOutput{
115+
.drvHash = Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
116+
.outputName = "quux",
117+
},
118+
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
120119
},
121-
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
122120
},
123-
},
121+
},
122+
{
123+
.drvHash = Hash::parseSRI("sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="),
124+
.outputName = "baz",
125+
},
124126
},
125127
}))
126128

@@ -196,25 +198,27 @@ VERSIONED_CHARACTERIZATION_TEST(
196198
{
197199
"foo",
198200
{
199-
.id =
200-
DrvOutput{
201-
.drvHash =
202-
Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
203-
.outputName = "foo",
204-
},
205-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
201+
{
202+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"},
203+
},
204+
DrvOutput{
205+
.drvHash =
206+
Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
207+
.outputName = "foo",
208+
},
206209
},
207210
},
208211
{
209212
"bar",
210213
{
211-
.id =
212-
DrvOutput{
213-
.drvHash =
214-
Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
215-
.outputName = "bar",
216-
},
217-
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar"},
214+
{
215+
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar"},
216+
},
217+
DrvOutput{
218+
.drvHash =
219+
Hash::parseSRI("sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U="),
220+
.outputName = "bar",
221+
},
218222
},
219223
},
220224
},

0 commit comments

Comments
 (0)