forked from lix-project/lix
Merge pull request #8927 from obsidiansystems/test-derivation-aterm
Test and begin documentation of the ATerm format for derivations
This commit is contained in:
commit
754528241a
|
@ -100,6 +100,7 @@
|
||||||
- [File System Object](architecture/file-system-object.md)
|
- [File System Object](architecture/file-system-object.md)
|
||||||
- [Protocols](protocols/protocols.md)
|
- [Protocols](protocols/protocols.md)
|
||||||
- [Serving Tarball Flakes](protocols/tarball-fetcher.md)
|
- [Serving Tarball Flakes](protocols/tarball-fetcher.md)
|
||||||
|
- [Derivation "ATerm" file format](protocols/derivation-aterm.md)
|
||||||
- [Glossary](glossary.md)
|
- [Glossary](glossary.md)
|
||||||
- [Contributing](contributing/contributing.md)
|
- [Contributing](contributing/contributing.md)
|
||||||
- [Hacking](contributing/hacking.md)
|
- [Hacking](contributing/hacking.md)
|
||||||
|
|
9
doc/manual/src/protocols/derivation-aterm.md
Normal file
9
doc/manual/src/protocols/derivation-aterm.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Derivation "ATerm" file format
|
||||||
|
|
||||||
|
For historical reasons, [derivations](@docroot@/glossary.md#gloss-store-derivation) are stored on-disk in [ATerm](https://homepages.cwi.nl/~daybuild/daily-books/technology/aterm-guide/aterm-guide.html) format.
|
||||||
|
|
||||||
|
Derivations are serialised in the following format:
|
||||||
|
|
||||||
|
```
|
||||||
|
Derive(...)
|
||||||
|
```
|
|
@ -143,26 +143,76 @@ TEST_JSON(ImpureDerivationTest, impure,
|
||||||
|
|
||||||
#undef TEST_JSON
|
#undef TEST_JSON
|
||||||
|
|
||||||
#define TEST_JSON(NAME, STR, VAL, DRV_NAME) \
|
#define TEST_JSON(NAME, STR, VAL) \
|
||||||
TEST_F(DerivationTest, Derivation_ ## NAME ## _to_json) { \
|
TEST_F(DerivationTest, Derivation_ ## NAME ## _to_json) { \
|
||||||
using nlohmann::literals::operator "" _json; \
|
using nlohmann::literals::operator "" _json; \
|
||||||
ASSERT_EQ( \
|
ASSERT_EQ( \
|
||||||
STR ## _json, \
|
STR ## _json, \
|
||||||
(Derivation { VAL }).toJSON(*store)); \
|
(VAL).toJSON(*store)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
TEST_F(DerivationTest, Derivation_ ## NAME ## _from_json) { \
|
TEST_F(DerivationTest, Derivation_ ## NAME ## _from_json) { \
|
||||||
using nlohmann::literals::operator "" _json; \
|
using nlohmann::literals::operator "" _json; \
|
||||||
ASSERT_EQ( \
|
ASSERT_EQ( \
|
||||||
Derivation { VAL }, \
|
(VAL), \
|
||||||
Derivation::fromJSON( \
|
Derivation::fromJSON( \
|
||||||
*store, \
|
*store, \
|
||||||
STR ## _json)); \
|
STR ## _json)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define TEST_ATERM(NAME, STR, VAL, DRV_NAME) \
|
||||||
|
TEST_F(DerivationTest, Derivation_ ## NAME ## _to_aterm) { \
|
||||||
|
ASSERT_EQ( \
|
||||||
|
STR, \
|
||||||
|
(VAL).unparse(*store, false)); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
TEST_F(DerivationTest, Derivation_ ## NAME ## _from_aterm) { \
|
||||||
|
auto parsed = parseDerivation( \
|
||||||
|
*store, \
|
||||||
|
STR, \
|
||||||
|
DRV_NAME); \
|
||||||
|
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 = {
|
||||||
|
{
|
||||||
|
store.parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv"),
|
||||||
|
{
|
||||||
|
"cat",
|
||||||
|
"dog",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
drv.platform = "wasm-sel4";
|
||||||
|
drv.builder = "foo";
|
||||||
|
drv.args = {
|
||||||
|
"bar",
|
||||||
|
"baz",
|
||||||
|
};
|
||||||
|
drv.env = {
|
||||||
|
{
|
||||||
|
"BIG_BAD",
|
||||||
|
"WOLF",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return drv;
|
||||||
|
}
|
||||||
|
|
||||||
TEST_JSON(simple,
|
TEST_JSON(simple,
|
||||||
R"({
|
R"({
|
||||||
"name": "my-derivation",
|
"name": "simple-derivation",
|
||||||
"inputSrcs": [
|
"inputSrcs": [
|
||||||
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
|
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
|
||||||
],
|
],
|
||||||
|
@ -183,37 +233,14 @@ TEST_JSON(simple,
|
||||||
},
|
},
|
||||||
"outputs": {}
|
"outputs": {}
|
||||||
})",
|
})",
|
||||||
({
|
makeSimpleDrv(*store))
|
||||||
Derivation drv;
|
|
||||||
drv.name = "my-derivation";
|
TEST_ATERM(simple,
|
||||||
drv.inputSrcs = {
|
R"(Derive([],[("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv",["cat","dog"])],["/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"],"wasm-sel4","foo",["bar","baz"],[("BIG_BAD","WOLF")]))",
|
||||||
store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"),
|
makeSimpleDrv(*store),
|
||||||
};
|
"simple-derivation")
|
||||||
drv.inputDrvs = {
|
|
||||||
{
|
|
||||||
store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep2.drv"),
|
|
||||||
{
|
|
||||||
"cat",
|
|
||||||
"dog",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
drv.platform = "wasm-sel4";
|
|
||||||
drv.builder = "foo";
|
|
||||||
drv.args = {
|
|
||||||
"bar",
|
|
||||||
"baz",
|
|
||||||
};
|
|
||||||
drv.env = {
|
|
||||||
{
|
|
||||||
"BIG_BAD",
|
|
||||||
"WOLF",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
drv;
|
|
||||||
}),
|
|
||||||
"drv-name")
|
|
||||||
|
|
||||||
#undef TEST_JSON
|
#undef TEST_JSON
|
||||||
|
#undef TEST_ATERM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue