2020-10-08 15:36:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "path.hh"
|
2020-12-08 20:07:52 +00:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2020-10-08 15:36:51 +00:00
|
|
|
|
2020-12-14 16:24:30 +00:00
|
|
|
|
|
|
|
/* Awfull hacky generation of the comparison operators by doing a lexicographic
|
|
|
|
* comparison between the choosen fields
|
|
|
|
* ```
|
|
|
|
* GENERATE_CMP(ClassName, my->field1, my->field2, ...)
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* will generate comparison operators semantically equivalent to:
|
|
|
|
* ```
|
|
|
|
* bool operator<(const ClassName& other) {
|
|
|
|
* return field1 < other.field1 && field2 < other.field2 && ...;
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
#define GENERATE_ONE_CMP(COMPARATOR, MY_TYPE, FIELDS...) \
|
|
|
|
bool operator COMPARATOR(const MY_TYPE& other) const { \
|
|
|
|
const MY_TYPE* me = this; \
|
|
|
|
auto fields1 = std::make_tuple( FIELDS ); \
|
|
|
|
me = &other; \
|
|
|
|
auto fields2 = std::make_tuple( FIELDS ); \
|
|
|
|
return fields1 COMPARATOR fields2; \
|
|
|
|
}
|
|
|
|
#define GENERATE_EQUAL(args...) GENERATE_ONE_CMP(==, args)
|
|
|
|
#define GENERATE_LEQ(args...) GENERATE_ONE_CMP(<, args)
|
|
|
|
#define GENERATE_CMP(args...) \
|
|
|
|
GENERATE_EQUAL(args) \
|
|
|
|
GENERATE_LEQ(args)
|
|
|
|
|
2020-10-08 15:36:51 +00:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
struct DrvOutput {
|
2020-12-09 15:56:56 +00:00
|
|
|
// The hash modulo of the derivation
|
|
|
|
Hash drvHash;
|
2020-10-08 15:36:51 +00:00
|
|
|
std::string outputName;
|
|
|
|
|
|
|
|
std::string to_string() const;
|
|
|
|
|
2020-12-09 15:56:56 +00:00
|
|
|
std::string strHash() const
|
|
|
|
{ return drvHash.to_string(Base16, true); }
|
|
|
|
|
2020-10-08 15:36:51 +00:00
|
|
|
static DrvOutput parse(const std::string &);
|
|
|
|
|
2020-12-14 16:24:30 +00:00
|
|
|
GENERATE_CMP(DrvOutput, me->drvHash, me->outputName);
|
2020-10-08 15:36:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Realisation {
|
|
|
|
DrvOutput id;
|
|
|
|
StorePath outPath;
|
|
|
|
|
2020-12-08 20:07:52 +00:00
|
|
|
nlohmann::json toJSON() const;
|
|
|
|
static Realisation fromJSON(const nlohmann::json& json, const std::string& whence);
|
2020-12-14 16:24:30 +00:00
|
|
|
|
|
|
|
StorePath getPath() const { return outPath; }
|
|
|
|
|
|
|
|
GENERATE_CMP(Realisation, me->id, me->outPath);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OpaquePath {
|
|
|
|
StorePath path;
|
|
|
|
|
|
|
|
StorePath getPath() const { return path; }
|
|
|
|
|
|
|
|
GENERATE_CMP(OpaquePath, me->path);
|
2020-10-08 15:36:51 +00:00
|
|
|
};
|
|
|
|
|
2020-12-14 16:24:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A store path with all the history of how it went into the store
|
|
|
|
*/
|
|
|
|
struct RealisedPath {
|
|
|
|
/*
|
|
|
|
* A path is either the result of the realisation of a derivation or
|
|
|
|
* an opaque blob that has been directly added to the store
|
|
|
|
*/
|
|
|
|
using Raw = std::variant<Realisation, OpaquePath>;
|
|
|
|
Raw raw;
|
|
|
|
|
|
|
|
using Set = std::set<RealisedPath>;
|
|
|
|
|
|
|
|
RealisedPath(StorePath path) : raw(OpaquePath{path}) {}
|
|
|
|
RealisedPath(Realisation r) : raw(r) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Syntactic sugar to run `std::visit` on the raw value:
|
|
|
|
* path.visit(blah) == std::visit(blah, path.raw)
|
|
|
|
*/
|
|
|
|
template <class Visitor>
|
|
|
|
constexpr decltype(auto) visit(Visitor && vis) {
|
|
|
|
return std::visit(vis, raw);
|
|
|
|
}
|
|
|
|
template <class Visitor>
|
|
|
|
constexpr decltype(auto) visit(Visitor && vis) const {
|
|
|
|
return std::visit(vis, raw);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the raw store path associated to this
|
|
|
|
*/
|
|
|
|
StorePath path() const;
|
|
|
|
|
|
|
|
void closure(Store& store, Set& ret) const;
|
|
|
|
static void closure(Store& store, const Set& startPaths, Set& ret);
|
|
|
|
Set closure(Store& store) const;
|
|
|
|
|
|
|
|
GENERATE_CMP(RealisedPath, me->raw);
|
|
|
|
};
|
2020-10-08 15:36:51 +00:00
|
|
|
|
|
|
|
}
|