Skip to content

Commit

Permalink
Move StorePathWithOutputs into its own header/file
Browse files Browse the repository at this point in the history
In the following commits it will become less prevalent.
  • Loading branch information
Ericson2314 committed Mar 2, 2021
1 parent ed352e9 commit 3070415
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/libcmd/installables.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "util.hh"
#include "path.hh"
#include "path-with-outputs.hh"
#include "buildable.hh"
#include "eval.hh"
#include "flake/flake.hh"
Expand Down
8 changes: 0 additions & 8 deletions src/libstore/derivations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,6 @@ std::map<std::string, Hash> staticOutputHashes(Store& store, const Derivation& d
}


std::string StorePathWithOutputs::to_string(const Store & store) const
{
return outputs.empty()
? store.printStorePath(path)
: store.printStorePath(path) + "!" + concatStringsSep(",", outputs);
}


bool wantOutput(const string & output, const std::set<string> & wanted)
{
return wanted.empty() || wanted.find(output) != wanted.end();
Expand Down
36 changes: 36 additions & 0 deletions src/libstore/path-with-outputs.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "store-api.hh"

namespace nix {

std::string StorePathWithOutputs::to_string(const Store & store) const
{
return outputs.empty()
? store.printStorePath(path)
: store.printStorePath(path) + "!" + concatStringsSep(",", outputs);
}


std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s)
{
size_t n = s.find("!");
return n == s.npos
? std::make_pair(s, std::set<string>())
: std::make_pair(((std::string_view) s).substr(0, n),
tokenizeString<std::set<string>>(((std::string_view) s).substr(n + 1), ","));
}


StorePathWithOutputs Store::parsePathWithOutputs(const std::string & s)
{
auto [path, outputs] = nix::parsePathWithOutputs(s);
return {parseStorePath(path), std::move(outputs)};
}


StorePathWithOutputs Store::followLinksToStorePathWithOutputs(std::string_view path) const
{
auto [path2, outputs] = nix::parsePathWithOutputs(path);
return StorePathWithOutputs { followLinksToStorePath(path2), std::move(outputs) };
}

}
17 changes: 17 additions & 0 deletions src/libstore/path-with-outputs.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "path.hh"

namespace nix {

struct StorePathWithOutputs
{
StorePath path;
std::set<std::string> outputs;

std::string to_string(const Store & store) const;
};

std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s);

}
15 changes: 0 additions & 15 deletions src/libstore/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,4 @@ PathSet Store::printStorePathSet(const StorePathSet & paths) const
return res;
}

std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s)
{
size_t n = s.find("!");
return n == s.npos
? std::make_pair(s, std::set<string>())
: std::make_pair(((std::string_view) s).substr(0, n),
tokenizeString<std::set<string>>(((std::string_view) s).substr(n + 1), ","));
}

StorePathWithOutputs Store::parsePathWithOutputs(const std::string & s)
{
auto [path, outputs] = nix::parsePathWithOutputs(s);
return {parseStorePath(path), std::move(outputs)};
}

}
10 changes: 0 additions & 10 deletions src/libstore/path.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ typedef std::map<StorePath, std::optional<ContentAddress>> StorePathCAMap;
/* Extension of derivations in the Nix store. */
const std::string drvExtension = ".drv";

struct StorePathWithOutputs
{
StorePath path;
std::set<std::string> outputs;

std::string to_string(const Store & store) const;
};

std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s);

}

namespace std {
Expand Down
7 changes: 0 additions & 7 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ StorePath Store::followLinksToStorePath(std::string_view path) const
}


StorePathWithOutputs Store::followLinksToStorePathWithOutputs(std::string_view path) const
{
auto [path2, outputs] = nix::parsePathWithOutputs(path);
return StorePathWithOutputs { followLinksToStorePath(path2), std::move(outputs) };
}


/* Store paths have the following form:
<realized-path> = <store>/<h>-<name>
Expand Down
1 change: 1 addition & 0 deletions src/libstore/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "realisation.hh"
#include "path.hh"
#include "path-with-outputs.hh"
#include "hash.hh"
#include "content-address.hh"
#include "serialise.hh"
Expand Down

0 comments on commit 3070415

Please sign in to comment.