2020-01-21 15:27:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
#include "hash.hh"
|
|
|
|
#include "path.hh"
|
2020-02-01 15:41:54 +00:00
|
|
|
#include "tree-info.hh"
|
2020-01-21 15:27:53 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2020-01-31 18:16:40 +00:00
|
|
|
#include <variant>
|
|
|
|
|
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2020-01-21 15:27:53 +00:00
|
|
|
|
|
|
|
namespace nix { class Store; }
|
|
|
|
|
|
|
|
namespace nix::fetchers {
|
|
|
|
|
|
|
|
struct Input;
|
|
|
|
|
|
|
|
struct Tree
|
|
|
|
{
|
|
|
|
Path actualPath;
|
|
|
|
StorePath storePath;
|
2020-02-01 15:41:54 +00:00
|
|
|
TreeInfo info;
|
2020-01-21 15:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Input : std::enable_shared_from_this<Input>
|
|
|
|
{
|
2020-01-28 12:11:02 +00:00
|
|
|
std::optional<Hash> narHash; // FIXME: implement
|
2020-01-21 15:27:53 +00:00
|
|
|
|
2020-01-31 18:16:40 +00:00
|
|
|
virtual std::string type() const = 0;
|
|
|
|
|
2020-01-22 20:26:19 +00:00
|
|
|
virtual ~Input() { }
|
|
|
|
|
2020-01-21 15:27:53 +00:00
|
|
|
virtual bool operator ==(const Input & other) const { return false; }
|
|
|
|
|
|
|
|
virtual bool isDirect() const { return true; }
|
|
|
|
|
|
|
|
virtual bool isImmutable() const { return (bool) narHash; }
|
|
|
|
|
|
|
|
virtual bool contains(const Input & other) const { return false; }
|
|
|
|
|
|
|
|
virtual std::optional<std::string> getRef() const { return {}; }
|
|
|
|
|
|
|
|
virtual std::optional<Hash> getRev() const { return {}; }
|
|
|
|
|
|
|
|
virtual std::string to_string() const = 0;
|
|
|
|
|
2020-01-31 18:16:40 +00:00
|
|
|
typedef std::variant<std::string, int64_t> Attr;
|
|
|
|
typedef std::map<std::string, Attr> Attrs;
|
|
|
|
|
|
|
|
Attrs toAttrs() const;
|
|
|
|
|
2020-01-21 15:27:53 +00:00
|
|
|
std::pair<Tree, std::shared_ptr<const Input>> fetchTree(ref<Store> store) const;
|
|
|
|
|
|
|
|
virtual std::shared_ptr<const Input> applyOverrides(
|
|
|
|
std::optional<std::string> ref,
|
|
|
|
std::optional<Hash> rev) const;
|
|
|
|
|
|
|
|
virtual std::optional<Path> getSourcePath() const { return {}; }
|
|
|
|
|
|
|
|
virtual void clone(const Path & destDir) const
|
|
|
|
{
|
|
|
|
throw Error("do not know how to clone input '%s'", to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
virtual std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(ref<Store> store) const = 0;
|
2020-01-31 18:16:40 +00:00
|
|
|
|
|
|
|
virtual Attrs toAttrsInternal() const = 0;
|
2020-01-21 15:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ParsedURL;
|
|
|
|
|
|
|
|
struct InputScheme
|
|
|
|
{
|
2020-01-22 20:26:19 +00:00
|
|
|
virtual ~InputScheme() { }
|
|
|
|
|
2020-01-21 15:27:53 +00:00
|
|
|
virtual std::unique_ptr<Input> inputFromURL(const ParsedURL & url) = 0;
|
2020-01-31 18:16:40 +00:00
|
|
|
|
|
|
|
virtual std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) = 0;
|
2020-01-21 15:27:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<Input> inputFromURL(const ParsedURL & url);
|
|
|
|
|
|
|
|
std::unique_ptr<Input> inputFromURL(const std::string & url);
|
|
|
|
|
2020-01-31 18:16:40 +00:00
|
|
|
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs);
|
|
|
|
|
2020-01-21 15:27:53 +00:00
|
|
|
void registerInputScheme(std::unique_ptr<InputScheme> && fetcher);
|
|
|
|
|
2020-01-31 18:16:40 +00:00
|
|
|
nlohmann::json attrsToJson(const Input::Attrs & attrs);
|
|
|
|
|
|
|
|
std::optional<std::string> maybeGetStrAttr(const Input::Attrs & attrs, const std::string & name);
|
|
|
|
|
|
|
|
std::string getStrAttr(const Input::Attrs & attrs, const std::string & name);
|
|
|
|
|
2020-01-21 15:27:53 +00:00
|
|
|
}
|