-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse string context elements properly
Prior to this change, we had a bunch of ad-hoc string manipulation code scattered around. This made it hard to figure out what data model for string contexts is. Now, we still store string contexts most of the time as encoded strings --- I was wary of the performance implications of changing that --- but whenever we parse them we do so only through the `NixStringContextElem::parse` method, which handles all cases. This creates a data type that is very similar to `DerivedPath` but: - Represents the funky `=<drvpath>` case as properly distinct from the others. - Only encodes a single output, no wildcards and no set, for the "built" case. (I would like to deprecate `=<path>`, after which we are in spitting distance of `DerivedPath` and could maybe get away with fewer types, but that is another topic for another day.) Additionally, `App` now uses `DerivedPath` not `StorePathWithOutputs` for its (simplified) context. This is just better as `StorePathWithOutputs` is the deprecated old type just for the old CLI.
- Loading branch information
1 parent
1534133
commit 09fd5ac
Showing
15 changed files
with
258 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "value/context.hh" | ||
#include "store-api.hh" | ||
|
||
#include <optional> | ||
|
||
namespace nix { | ||
|
||
NixStringContextElem NixStringContextElem::parse(const Store & store, std::string_view s) | ||
{ | ||
switch (s.at(0)) { | ||
case '!': { | ||
size_t index = s.find("!", 1); | ||
return NixStringContextElem::Built { | ||
.drvPath = store.parseStorePath(s.substr(index + 1)), | ||
.output = std::string(s.substr(1, index - 1)), | ||
}; | ||
} | ||
case '=': { | ||
return NixStringContextElem::DrvDeep { | ||
.drvPath = store.parseStorePath(s.substr(1)), | ||
}; | ||
} | ||
default: { | ||
return NixStringContextElem::Opaque { | ||
.path = store.parseStorePath(s), | ||
}; | ||
} | ||
} | ||
} | ||
|
||
std::string NixStringContextElem::render(const Store & store) const { | ||
return std::visit(overloaded { | ||
[&](const NixStringContextElem::Built & b) { | ||
std::string res; | ||
res += '!'; | ||
res += store.printStorePath(b.drvPath); | ||
res += '!'; | ||
res += b.output; | ||
return res; | ||
}, | ||
[&](const NixStringContextElem::DrvDeep & d) { | ||
std::string res; | ||
res += '='; | ||
res += store.printStorePath(d.drvPath); | ||
return res; | ||
}, | ||
[&](const NixStringContextElem::Opaque & o) { | ||
return store.printStorePath(o.path); | ||
}, | ||
}, raw()); | ||
} | ||
|
||
} |
Oops, something went wrong.