2023-02-19 16:11:20 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2023-04-17 15:22:31 +00:00
|
|
|
#include "experimental-features.hh"
|
2023-02-19 16:11:20 +00:00
|
|
|
#include "derivations.hh"
|
|
|
|
|
|
|
|
#include "tests/libstore.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
class DerivationTest : public LibStoreTest
|
|
|
|
{
|
2023-04-17 15:22:31 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* We set these in tests rather than the regular globals so we don't have
|
|
|
|
* to worry about race conditions if the tests run concurrently.
|
|
|
|
*/
|
|
|
|
ExperimentalFeatureSettings mockXpSettings;
|
2023-02-19 16:11:20 +00:00
|
|
|
};
|
|
|
|
|
2023-04-17 15:22:31 +00:00
|
|
|
class CaDerivationTest : public DerivationTest
|
|
|
|
{
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
mockXpSettings.set("experimental-features", "ca-derivations");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-19 15:33:48 +00:00
|
|
|
class DynDerivationTest : public DerivationTest
|
|
|
|
{
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
mockXpSettings.set("experimental-features", "dynamic-derivations ca-derivations");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-17 15:22:31 +00:00
|
|
|
class ImpureDerivationTest : public DerivationTest
|
|
|
|
{
|
|
|
|
void SetUp() override
|
|
|
|
{
|
|
|
|
mockXpSettings.set("experimental-features", "impure-derivations");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
TEST_F(DerivationTest, BadATerm_version) {
|
|
|
|
ASSERT_THROW(
|
|
|
|
parseDerivation(
|
|
|
|
*store,
|
|
|
|
R"(DrvWithVersion("invalid-version",[],[("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv",["cat","dog"])],["/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"],"wasm-sel4","foo",["bar","baz"],[("BIG_BAD","WOLF")]))",
|
|
|
|
"whatever",
|
|
|
|
mockXpSettings),
|
|
|
|
FormatError);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DynDerivationTest, BadATerm_oldVersionDynDeps) {
|
|
|
|
ASSERT_THROW(
|
|
|
|
parseDerivation(
|
|
|
|
*store,
|
|
|
|
R"(Derive([],[("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv",(["cat","dog"],[("cat",["kitten"]),("goose",["gosling"])]))],["/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"],"wasm-sel4","foo",["bar","baz"],[("BIG_BAD","WOLF")]))",
|
|
|
|
"dyn-dep-derivation",
|
|
|
|
mockXpSettings),
|
|
|
|
FormatError);
|
|
|
|
}
|
|
|
|
|
2023-04-17 15:22:31 +00:00
|
|
|
#define TEST_JSON(FIXTURE, NAME, STR, VAL, DRV_NAME, OUTPUT_NAME) \
|
|
|
|
TEST_F(FIXTURE, DerivationOutput_ ## NAME ## _to_json) { \
|
2023-02-17 23:37:35 +00:00
|
|
|
using nlohmann::literals::operator "" _json; \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
STR ## _json, \
|
|
|
|
(DerivationOutput { VAL }).toJSON( \
|
|
|
|
*store, \
|
|
|
|
DRV_NAME, \
|
|
|
|
OUTPUT_NAME)); \
|
|
|
|
} \
|
|
|
|
\
|
2023-04-17 15:22:31 +00:00
|
|
|
TEST_F(FIXTURE, DerivationOutput_ ## NAME ## _from_json) { \
|
2023-02-17 23:37:35 +00:00
|
|
|
using nlohmann::literals::operator "" _json; \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
DerivationOutput { VAL }, \
|
|
|
|
DerivationOutput::fromJSON( \
|
|
|
|
*store, \
|
|
|
|
DRV_NAME, \
|
|
|
|
OUTPUT_NAME, \
|
2023-04-17 15:22:31 +00:00
|
|
|
STR ## _json, \
|
|
|
|
mockXpSettings)); \
|
2023-02-19 16:11:20 +00:00
|
|
|
}
|
|
|
|
|
2023-04-17 15:22:31 +00:00
|
|
|
TEST_JSON(DerivationTest, inputAddressed,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
|
|
|
"path": "/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-drv-name-output-name"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::InputAddressed {
|
|
|
|
.path = store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-drv-name-output-name"),
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-04-19 18:48:53 +00:00
|
|
|
TEST_JSON(DerivationTest, caFixedFlat,
|
|
|
|
R"({
|
|
|
|
"hashAlgo": "sha256",
|
|
|
|
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f",
|
|
|
|
"path": "/nix/store/rhcg9h16sqvlbpsa6dqm57sbr2al6nzg-drv-name-output-name"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::CAFixed {
|
2023-07-05 22:53:44 +00:00
|
|
|
.ca = {
|
2023-04-19 18:48:53 +00:00
|
|
|
.method = FileIngestionMethod::Flat,
|
|
|
|
.hash = Hash::parseAnyPrefixed("sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
|
|
|
TEST_JSON(DerivationTest, caFixedNAR,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
|
|
|
"hashAlgo": "r:sha256",
|
|
|
|
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f",
|
|
|
|
"path": "/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-drv-name-output-name"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::CAFixed {
|
2023-07-05 22:53:44 +00:00
|
|
|
.ca = {
|
2023-04-19 18:48:53 +00:00
|
|
|
.method = FileIngestionMethod::Recursive,
|
|
|
|
.hash = Hash::parseAnyPrefixed("sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="),
|
2023-02-28 17:46:00 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-04-19 15:33:48 +00:00
|
|
|
TEST_JSON(DynDerivationTest, caFixedText,
|
2023-02-28 17:46:00 +00:00
|
|
|
R"({
|
|
|
|
"hashAlgo": "text:sha256",
|
|
|
|
"hash": "894517c9163c896ec31a2adbd33c0681fd5f45b2c0ef08a64c92a03fb97f390f",
|
|
|
|
"path": "/nix/store/6s1zwabh956jvhv4w9xcdb5jiyanyxg1-drv-name-output-name"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::CAFixed {
|
2023-07-05 22:53:44 +00:00
|
|
|
.ca = {
|
2023-04-19 18:48:53 +00:00
|
|
|
.hash = Hash::parseAnyPrefixed("sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8="),
|
2023-02-19 16:11:20 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-04-17 15:22:31 +00:00
|
|
|
TEST_JSON(CaDerivationTest, caFloating,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
|
|
|
"hashAlgo": "r:sha256"
|
|
|
|
})",
|
|
|
|
(DerivationOutput::CAFloating {
|
|
|
|
.method = FileIngestionMethod::Recursive,
|
|
|
|
.hashType = htSHA256,
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-04-17 15:22:31 +00:00
|
|
|
TEST_JSON(DerivationTest, deferred,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({ })",
|
|
|
|
DerivationOutput::Deferred { },
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-04-17 15:22:31 +00:00
|
|
|
TEST_JSON(ImpureDerivationTest, impure,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
|
|
|
"hashAlgo": "r:sha256",
|
|
|
|
"impure": true
|
|
|
|
})",
|
|
|
|
(DerivationOutput::Impure {
|
|
|
|
.method = FileIngestionMethod::Recursive,
|
|
|
|
.hashType = htSHA256,
|
|
|
|
}),
|
|
|
|
"drv-name", "output-name")
|
|
|
|
|
2023-02-17 23:37:35 +00:00
|
|
|
#undef TEST_JSON
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
#define TEST_JSON(FIXTURE, NAME, STR, VAL) \
|
|
|
|
TEST_F(FIXTURE, Derivation_ ## NAME ## _to_json) { \
|
2023-09-05 15:16:39 +00:00
|
|
|
using nlohmann::literals::operator "" _json; \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
STR ## _json, \
|
|
|
|
(VAL).toJSON(*store)); \
|
|
|
|
} \
|
|
|
|
\
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
TEST_F(FIXTURE, Derivation_ ## NAME ## _from_json) { \
|
2023-09-05 15:16:39 +00:00
|
|
|
using nlohmann::literals::operator "" _json; \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
(VAL), \
|
|
|
|
Derivation::fromJSON( \
|
|
|
|
*store, \
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
STR ## _json, \
|
|
|
|
mockXpSettings)); \
|
2023-02-17 23:37:35 +00:00
|
|
|
}
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
#define TEST_ATERM(FIXTURE, NAME, STR, VAL, DRV_NAME) \
|
|
|
|
TEST_F(FIXTURE, Derivation_ ## NAME ## _to_aterm) { \
|
2023-09-05 15:16:39 +00:00
|
|
|
ASSERT_EQ( \
|
|
|
|
STR, \
|
|
|
|
(VAL).unparse(*store, false)); \
|
|
|
|
} \
|
|
|
|
\
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
TEST_F(FIXTURE, Derivation_ ## NAME ## _from_aterm) { \
|
2023-09-05 15:16:39 +00:00
|
|
|
auto parsed = parseDerivation( \
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
*store, \
|
|
|
|
STR, \
|
|
|
|
DRV_NAME, \
|
|
|
|
mockXpSettings); \
|
2023-09-05 15:16:39 +00:00
|
|
|
ASSERT_EQ( \
|
|
|
|
(VAL).toJSON(*store), \
|
|
|
|
parsed.toJSON(*store)); \
|
|
|
|
ASSERT_EQ( \
|
|
|
|
(VAL), \
|
|
|
|
parsed); \
|
|
|
|
}
|
|
|
|
|
|
|
|
Derivation makeSimpleDrv(const Store & store) {
|
|
|
|
Derivation drv;
|
|
|
|
drv.name = "simple-derivation";
|
|
|
|
drv.inputSrcs = {
|
|
|
|
store.parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"),
|
|
|
|
};
|
|
|
|
drv.inputDrvs = {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
.map = {
|
2023-09-05 15:16:39 +00:00
|
|
|
{
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
store.parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv"),
|
|
|
|
{
|
|
|
|
.value = {
|
|
|
|
"cat",
|
|
|
|
"dog",
|
|
|
|
},
|
|
|
|
},
|
2023-09-05 15:16:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
drv.platform = "wasm-sel4";
|
|
|
|
drv.builder = "foo";
|
|
|
|
drv.args = {
|
|
|
|
"bar",
|
|
|
|
"baz",
|
|
|
|
};
|
|
|
|
drv.env = {
|
|
|
|
{
|
|
|
|
"BIG_BAD",
|
|
|
|
"WOLF",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return drv;
|
|
|
|
}
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
TEST_JSON(DerivationTest, simple,
|
2023-02-19 16:11:20 +00:00
|
|
|
R"({
|
2023-09-05 15:16:39 +00:00
|
|
|
"name": "simple-derivation",
|
2023-02-19 16:11:20 +00:00
|
|
|
"inputSrcs": [
|
|
|
|
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
|
|
|
|
],
|
|
|
|
"inputDrvs": {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv": {
|
|
|
|
"dynamicOutputs": {},
|
|
|
|
"outputs": [
|
|
|
|
"cat",
|
|
|
|
"dog"
|
|
|
|
]
|
|
|
|
}
|
2023-02-19 16:11:20 +00:00
|
|
|
},
|
|
|
|
"system": "wasm-sel4",
|
|
|
|
"builder": "foo",
|
|
|
|
"args": [
|
|
|
|
"bar",
|
|
|
|
"baz"
|
|
|
|
],
|
2023-02-20 22:32:19 +00:00
|
|
|
"env": {
|
|
|
|
"BIG_BAD": "WOLF"
|
|
|
|
},
|
2023-02-19 16:11:20 +00:00
|
|
|
"outputs": {}
|
|
|
|
})",
|
2023-09-05 15:16:39 +00:00
|
|
|
makeSimpleDrv(*store))
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
TEST_ATERM(DerivationTest, simple,
|
2023-09-05 15:16:39 +00:00
|
|
|
R"(Derive([],[("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv",["cat","dog"])],["/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"],"wasm-sel4","foo",["bar","baz"],[("BIG_BAD","WOLF")]))",
|
|
|
|
makeSimpleDrv(*store),
|
|
|
|
"simple-derivation")
|
2023-02-19 16:11:20 +00:00
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-01 22:05:53 +00:00
|
|
|
Derivation makeDynDepDerivation(const Store & store) {
|
|
|
|
Derivation drv;
|
|
|
|
drv.name = "dyn-dep-derivation";
|
|
|
|
drv.inputSrcs = {
|
|
|
|
store.parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"),
|
|
|
|
};
|
|
|
|
drv.inputDrvs = {
|
|
|
|
.map = {
|
|
|
|
{
|
|
|
|
store.parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv"),
|
|
|
|
DerivedPathMap<StringSet>::ChildNode {
|
|
|
|
.value = {
|
|
|
|
"cat",
|
|
|
|
"dog",
|
|
|
|
},
|
|
|
|
.childMap = {
|
|
|
|
{
|
|
|
|
"cat",
|
|
|
|
DerivedPathMap<StringSet>::ChildNode {
|
|
|
|
.value = {
|
|
|
|
"kitten",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"goose",
|
|
|
|
DerivedPathMap<StringSet>::ChildNode {
|
|
|
|
.value = {
|
|
|
|
"gosling",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
drv.platform = "wasm-sel4";
|
|
|
|
drv.builder = "foo";
|
|
|
|
drv.args = {
|
|
|
|
"bar",
|
|
|
|
"baz",
|
|
|
|
};
|
|
|
|
drv.env = {
|
|
|
|
{
|
|
|
|
"BIG_BAD",
|
|
|
|
"WOLF",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return drv;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_JSON(DynDerivationTest, dynDerivationDeps,
|
|
|
|
R"({
|
|
|
|
"name": "dyn-dep-derivation",
|
|
|
|
"inputSrcs": [
|
|
|
|
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
|
|
|
|
],
|
|
|
|
"inputDrvs": {
|
|
|
|
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv": {
|
|
|
|
"dynamicOutputs": {
|
|
|
|
"cat": {
|
|
|
|
"dynamicOutputs": {},
|
|
|
|
"outputs": ["kitten"]
|
|
|
|
},
|
|
|
|
"goose": {
|
|
|
|
"dynamicOutputs": {},
|
|
|
|
"outputs": ["gosling"]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"outputs": [
|
|
|
|
"cat",
|
|
|
|
"dog"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"system": "wasm-sel4",
|
|
|
|
"builder": "foo",
|
|
|
|
"args": [
|
|
|
|
"bar",
|
|
|
|
"baz"
|
|
|
|
],
|
|
|
|
"env": {
|
|
|
|
"BIG_BAD": "WOLF"
|
|
|
|
},
|
|
|
|
"outputs": {}
|
|
|
|
})",
|
|
|
|
makeDynDepDerivation(*store))
|
|
|
|
|
|
|
|
TEST_ATERM(DynDerivationTest, dynDerivationDeps,
|
|
|
|
R"(DrvWithVersion("xp-dyn-drv",[],[("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv",(["cat","dog"],[("cat",["kitten"]),("goose",["gosling"])]))],["/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"],"wasm-sel4","foo",["bar","baz"],[("BIG_BAD","WOLF")]))",
|
|
|
|
makeDynDepDerivation(*store),
|
|
|
|
"dyn-dep-derivation")
|
|
|
|
|
2023-02-19 16:11:20 +00:00
|
|
|
#undef TEST_JSON
|
2023-09-05 15:16:39 +00:00
|
|
|
#undef TEST_ATERM
|
2023-02-19 16:11:20 +00:00
|
|
|
|
|
|
|
}
|