forked from lix-project/lix
Fix tests on systems with a non-master git defaultBranch #1
|
@ -1,11 +1,7 @@
|
|||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <iomanip>
|
||||
#if __APPLE__
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
@ -18,6 +14,7 @@
|
|||
#include "build-result.hh"
|
||||
#include "store-api.hh"
|
||||
#include "derivations.hh"
|
||||
#include "strings.hh"
|
||||
#include "local-store.hh"
|
||||
#include "legacy.hh"
|
||||
#include "experimental-features.hh"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "editor-for.hh"
|
||||
#include "environment-variables.hh"
|
||||
#include "source-path.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "gc-small-vector.hh"
|
||||
#include "fetch-to-store.hh"
|
||||
#include "flake/flakeref.hh"
|
||||
#include "exit.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "experimental-features.hh"
|
||||
#include "search-path.hh"
|
||||
#include "repl-exit-status.hh"
|
||||
#include "backed-string-view.hh"
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
@ -791,4 +792,4 @@ static constexpr std::string_view corepkgsPrefix{"/__corepkgs__/"};
|
|||
|
||||
}
|
||||
|
||||
#include "eval-inline.hh"
|
||||
#include "eval-inline.hh" // IWYU pragma: keep
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "eval-error.hh"
|
||||
#include "pos-idx.hh"
|
||||
#include "pos-table.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "path.hh"
|
||||
#include "attrs.hh"
|
||||
#include "url.hh"
|
||||
#include "ref.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include "progress-bar.hh"
|
||||
#include "file-system.hh"
|
||||
#include "sync.hh"
|
||||
#include "store-api.hh"
|
||||
#include "names.hh"
|
||||
#include "terminal.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <map>
|
||||
#include <thread>
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "loggers.hh"
|
||||
#include "current-process.hh"
|
||||
#include "terminal.hh"
|
||||
#include "strings.hh"
|
||||
#include "exit.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
|
|
|
@ -7,12 +7,10 @@
|
|||
#include "path.hh"
|
||||
#include "derived-path.hh"
|
||||
#include "processes.hh"
|
||||
#include "exit.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <locale>
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "nar-accessor.hh"
|
||||
#include "thread-pool.hh"
|
||||
#include "signals.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <chrono>
|
||||
#include <regex>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "logging-json.hh"
|
||||
#include "substitution-goal.hh"
|
||||
#include "drv-output-substitution-goal.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "substitution-goal.hh"
|
||||
#include "derivation-goal.hh"
|
||||
#include "local-store.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "file-system.hh"
|
||||
#include "globals.hh"
|
||||
#include "hook-instance.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
#include "local-derivation-goal.hh"
|
||||
#include "indirect-root-store.hh"
|
||||
#include "hook-instance.hh"
|
||||
#include "machines.hh"
|
||||
#include "store-api.hh"
|
||||
#include "worker.hh"
|
||||
#include "builtins.hh"
|
||||
#include "builtins/buildenv.hh"
|
||||
#include "path-references.hh"
|
||||
#include "finally.hh"
|
||||
#include "archive.hh"
|
||||
#include "compression.hh"
|
||||
#include "daemon.hh"
|
||||
#include "topo-sort.hh"
|
||||
#include "json-utils.hh"
|
||||
|
@ -19,6 +16,7 @@
|
|||
#include "child.hh"
|
||||
#include "unix-domain-socket.hh"
|
||||
#include "mount.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <regex>
|
||||
#include <queue>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "buildenv.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "store-api.hh"
|
||||
#include "archive.hh"
|
||||
#include "compression.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "args.hh"
|
||||
#include "content-address.hh"
|
||||
#include "split.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "monitor-fd.hh"
|
||||
#include "worker-protocol.hh"
|
||||
#include "worker-protocol-impl.hh"
|
||||
#include "build-result.hh"
|
||||
#include "build-result.hh" // IWYU pragma: keep
|
||||
#include "store-api.hh"
|
||||
#include "store-cast.hh"
|
||||
#include "gc-store.hh"
|
||||
|
@ -12,6 +12,7 @@
|
|||
#include "finally.hh"
|
||||
#include "archive.hh"
|
||||
#include "derivations.hh"
|
||||
#include "strings.hh"
|
||||
#include "args.hh"
|
||||
|
||||
#include <sstream>
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
#include "store-api.hh"
|
||||
#include "globals.hh"
|
||||
#include "types.hh"
|
||||
#include "split.hh"
|
||||
#include "common-protocol.hh"
|
||||
#include "common-protocol-impl.hh"
|
||||
#include "fs-accessor.hh"
|
||||
#include "json-utils.hh"
|
||||
#include "strings.hh"
|
||||
#include "backed-string-view.hh"
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "path.hh"
|
||||
#include "outputs-spec.hh"
|
||||
#include "comparator.hh"
|
||||
#include "ref.hh"
|
||||
|
||||
#include <variant>
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "s3.hh"
|
||||
#include "signals.hh"
|
||||
#include "compression.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#if ENABLE_S3
|
||||
#include <aws/core/client/ClientConfiguration.h>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
///@file
|
||||
|
||||
#include "box_ptr.hh"
|
||||
#include "ref.hh"
|
||||
#include "logging.hh"
|
||||
#include "serialise.hh"
|
||||
#include "types.hh"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "signals.hh"
|
||||
#include "finally.hh"
|
||||
#include "unix-domain-socket.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <queue>
|
||||
#include <regex>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "path-with-outputs.hh"
|
||||
#include "ssh.hh"
|
||||
#include "ssh-store.hh"
|
||||
#include "strings.hh"
|
||||
#include "derivations.hh"
|
||||
|
||||
namespace nix {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "signals.hh"
|
||||
#include "finally.hh"
|
||||
#include "compression.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "types.hh"
|
||||
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "types.hh"
|
||||
#include "ref.hh"
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "make-content-addressed.hh"
|
||||
#include "references.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "derivations.hh"
|
||||
#include "parsed-derivations.hh"
|
||||
#include "globals.hh"
|
||||
#include "local-store.hh"
|
||||
#include "store-api.hh"
|
||||
#include "thread-pool.hh"
|
||||
#include "topo-sort.hh"
|
||||
#include "closure.hh"
|
||||
#include "filetransfer.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "fs-accessor.hh"
|
||||
#include "ref.hh"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include "fs-accessor.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "sqlite.hh"
|
||||
#include "globals.hh"
|
||||
#include "users.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "globals.hh"
|
||||
#include "strings.hh"
|
||||
#include "nar-info.hh"
|
||||
#include "store-api.hh"
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "local-store.hh"
|
||||
#include "globals.hh"
|
||||
#include "signals.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <cstring>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "parsed-derivations.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <regex>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "path-info.hh"
|
||||
#include "store-api.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "path-with-outputs.hh"
|
||||
#include "store-api.hh"
|
||||
|
||||
#include <regex>
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "signals.hh"
|
||||
#include "platform/darwin.hh"
|
||||
#include "regex.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <sys/proc_info.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "signals.hh"
|
||||
#include "platform/linux.hh"
|
||||
#include "regex.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <grp.h>
|
||||
#include <regex>
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#include "profiles.hh"
|
||||
#include "store-api.hh"
|
||||
#include "local-fs-store.hh"
|
||||
#include "users.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "finally.hh"
|
||||
#include "logging.hh"
|
||||
#include "filetransfer.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace nix {
|
||||
|
@ -64,7 +66,7 @@ void RemoteStore::initConnection(Connection & conn)
|
|||
{
|
||||
/* Send the magic greeting, check for the reply. */
|
||||
try {
|
||||
conn.from.endOfFileError = "Nix daemon disconnected unexpectedly (maybe it crashed?)";
|
||||
conn.from.specialEndOfFileError = "Nix daemon disconnected unexpectedly (maybe it crashed?)";
|
||||
conn.to << WORKER_MAGIC_1;
|
||||
conn.to.flush();
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "globals.hh"
|
||||
#include "compression.hh"
|
||||
#include "filetransfer.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <aws/core/Aws.h>
|
||||
#include <aws/core/VersionConfig.h>
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
#include "ssh-store.hh"
|
||||
#include "store-api.hh"
|
||||
#include "local-fs-store.hh"
|
||||
#include "remote-store.hh"
|
||||
#include "remote-store-connection.hh"
|
||||
#include "remote-fs-accessor.hh"
|
||||
#include "archive.hh"
|
||||
#include "worker-protocol.hh"
|
||||
#include "pool.hh"
|
||||
#include "ssh.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include "nar-info-disk-cache.hh"
|
||||
#include "thread-pool.hh"
|
||||
#include "url.hh"
|
||||
#include "references.hh"
|
||||
#include "archive.hh"
|
||||
#include "remote-store.hh"
|
||||
#include "uds-remote-store.hh"
|
||||
#include "signals.hh"
|
||||
#include "strings.hh"
|
||||
// FIXME this should not be here, see TODO below on
|
||||
// `addMultipleToStore`.
|
||||
#include "worker-protocol.hh"
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#include "args.hh"
|
||||
#include "args/root.hh"
|
||||
#include "hash.hh"
|
||||
#include "json-utils.hh"
|
||||
#include "strings.hh"
|
||||
#include "json-utils.hh" // IWYU pragma: keep (instances)
|
||||
#include "environment-variables.hh"
|
||||
|
||||
#include "experimental-features-json.hh"
|
||||
#include "experimental-features-json.hh" // IWYU pragma: keep (instances)
|
||||
#include "logging.hh"
|
||||
|
||||
#include <glob.h>
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "experimental-features.hh"
|
||||
#include "types.hh"
|
||||
#include "ref.hh"
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
|
69
src/libutil/backed-string-view.hh
Normal file
69
src/libutil/backed-string-view.hh
Normal file
|
@ -0,0 +1,69 @@
|
|||
#pragma once
|
||||
/// @file String view that can be either owned or borrowed.
|
||||
#include <variant>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
/**
|
||||
* This wants to be a little bit like rust's Cow type.
|
||||
* Some parts of the evaluator benefit greatly from being able to reuse
|
||||
* existing allocations for strings, but have to be able to also use
|
||||
* newly allocated storage for values.
|
||||
*
|
||||
* We do not define implicit conversions, even with ref qualifiers,
|
||||
* since those can easily become ambiguous to the reader and can degrade
|
||||
* into copying behaviour we want to avoid.
|
||||
*/
|
||||
class BackedStringView {
|
||||
private:
|
||||
std::variant<std::string, std::string_view> data;
|
||||
|
||||
/**
|
||||
* Needed to introduce a temporary since operator-> must return
|
||||
* a pointer. Without this we'd need to store the view object
|
||||
* even when we already own a string.
|
||||
*/
|
||||
class Ptr {
|
||||
private:
|
||||
std::string_view view;
|
||||
public:
|
||||
Ptr(std::string_view view): view(view) {}
|
||||
const std::string_view * operator->() const { return &view; }
|
||||
};
|
||||
|
||||
public:
|
||||
BackedStringView(std::string && s): data(std::move(s)) {}
|
||||
BackedStringView(std::string_view sv): data(sv) {}
|
||||
template<size_t N>
|
||||
BackedStringView(const char (& lit)[N]): data(std::string_view(lit)) {}
|
||||
|
||||
BackedStringView(const BackedStringView &) = delete;
|
||||
BackedStringView & operator=(const BackedStringView &) = delete;
|
||||
|
||||
/**
|
||||
* We only want move operations defined since the sole purpose of
|
||||
* this type is to avoid copies.
|
||||
*/
|
||||
BackedStringView(BackedStringView && other) = default;
|
||||
BackedStringView & operator=(BackedStringView && other) = default;
|
||||
|
||||
bool isOwned() const
|
||||
{
|
||||
return std::holds_alternative<std::string>(data);
|
||||
}
|
||||
|
||||
std::string toOwned() &&
|
||||
{
|
||||
return isOwned()
|
||||
? std::move(std::get<std::string>(data))
|
||||
: std::string(std::get<std::string_view>(data));
|
||||
}
|
||||
|
||||
std::string_view operator*() const
|
||||
{
|
||||
return isOwned()
|
||||
? std::get<std::string>(data)
|
||||
: std::get<std::string_view>(data);
|
||||
}
|
||||
Ptr operator->() const { return Ptr(**this); }
|
||||
};
|
|
@ -3,6 +3,7 @@
|
|||
#include "logging.hh"
|
||||
#include "position.hh"
|
||||
#include "terminal.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "logging.hh"
|
||||
#include "serialise.hh"
|
||||
#include "signals.hh"
|
||||
#include "strings.hh"
|
||||
#include "types.hh"
|
||||
#include "users.hh"
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "charptr-cast.hh"
|
||||
#include "logging.hh"
|
||||
#include "split.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
|
@ -53,6 +53,7 @@ libutil_headers = files(
|
|||
'archive.hh',
|
||||
'args/root.hh',
|
||||
'args.hh',
|
||||
'backed-string-view.hh',
|
||||
'box_ptr.hh',
|
||||
'canon-path.hh',
|
||||
'cgroup.hh',
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "finally.hh"
|
||||
#include "logging.hh"
|
||||
#include "processes.hh"
|
||||
#include "strings.hh"
|
||||
#include "serialise.hh"
|
||||
#include "signals.hh"
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include <string>
|
||||
#include <regex>
|
||||
|
||||
// Declared as extern in precompiled-headers.hh
|
||||
template class std::basic_regex<char>;
|
||||
|
||||
namespace nix::regex {
|
||||
std::string quoteRegexChars(const std::string & raw)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,21 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Convert a little-endian integer to host order.
|
||||
*/
|
||||
template<typename T>
|
||||
T readLittleEndian(unsigned char * p)
|
||||
{
|
||||
T x = 0;
|
||||
for (size_t i = 0; i < sizeof(x); ++i, ++p) {
|
||||
x |= ((T) *p) << (i * 8);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T readNum(Source & source)
|
||||
{
|
||||
|
@ -152,7 +167,7 @@ size_t FdSource::readUnbuffered(char * data, size_t len)
|
|||
n = ::read(fd, data, len);
|
||||
} while (n == -1 && errno == EINTR);
|
||||
if (n == -1) { _good = false; throw SysError("reading from file"); }
|
||||
if (n == 0) { _good = false; throw EndOfFile(std::string(*endOfFileError)); }
|
||||
if (n == 0) { _good = false; throw EndOfFile(endOfFileError()); }
|
||||
read += n;
|
||||
return n;
|
||||
}
|
||||
|
@ -163,6 +178,11 @@ bool FdSource::good()
|
|||
return _good;
|
||||
}
|
||||
|
||||
std::string FdSource::endOfFileError() const
|
||||
{
|
||||
return specialEndOfFileError.has_value() ? *specialEndOfFileError : "unexpected end-of-file";
|
||||
}
|
||||
|
||||
|
||||
size_t StringSource::read(char * data, size_t len)
|
||||
{
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include <concepts>
|
||||
#include <memory>
|
||||
|
||||
#include "charptr-cast.hh"
|
||||
#include "generator.hh"
|
||||
#include "strings.hh"
|
||||
#include "types.hh"
|
||||
#include "file-descriptor.hh"
|
||||
|
||||
|
@ -153,7 +151,10 @@ struct FdSource : BufferedSource
|
|||
{
|
||||
int fd;
|
||||
size_t read = 0;
|
||||
BackedStringView endOfFileError{"unexpected end-of-file"};
|
||||
/** Defaults to "unexpected end-of-file" */
|
||||
std::optional<std::string> specialEndOfFileError;
|
||||
|
||||
std::string endOfFileError() const;
|
||||
|
||||
FdSource() : fd(-1) { }
|
||||
FdSource(int fd) : fd(fd) { }
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "source-path.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
|
|
@ -164,19 +164,6 @@ template<class N>
|
|||
std::optional<N> string2Float(const std::string_view s);
|
||||
|
||||
|
||||
/**
|
||||
* Convert a little-endian integer to host order.
|
||||
*/
|
||||
template<typename T>
|
||||
T readLittleEndian(unsigned char * p)
|
||||
{
|
||||
T x = 0;
|
||||
for (size_t i = 0; i < sizeof(x); ++i, ++p) {
|
||||
x |= ((T) *p) << (i * 8);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to lower case.
|
||||
*/
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "ref.hh"
|
||||
|
||||
#include <list>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <string_view>
|
||||
#include <map>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include <span>
|
||||
#include <stdint.h> // IWYU pragma: keep (this is used literally everywhere)
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -166,70 +164,4 @@ constexpr auto enumerate(T && iterable)
|
|||
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
|
||||
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This wants to be a little bit like rust's Cow type.
|
||||
* Some parts of the evaluator benefit greatly from being able to reuse
|
||||
* existing allocations for strings, but have to be able to also use
|
||||
* newly allocated storage for values.
|
||||
*
|
||||
* We do not define implicit conversions, even with ref qualifiers,
|
||||
* since those can easily become ambiguous to the reader and can degrade
|
||||
* into copying behaviour we want to avoid.
|
||||
*/
|
||||
class BackedStringView {
|
||||
private:
|
||||
std::variant<std::string, std::string_view> data;
|
||||
|
||||
/**
|
||||
* Needed to introduce a temporary since operator-> must return
|
||||
* a pointer. Without this we'd need to store the view object
|
||||
* even when we already own a string.
|
||||
*/
|
||||
class Ptr {
|
||||
private:
|
||||
std::string_view view;
|
||||
public:
|
||||
Ptr(std::string_view view): view(view) {}
|
||||
const std::string_view * operator->() const { return &view; }
|
||||
};
|
||||
|
||||
public:
|
||||
BackedStringView(std::string && s): data(std::move(s)) {}
|
||||
BackedStringView(std::string_view sv): data(sv) {}
|
||||
template<size_t N>
|
||||
BackedStringView(const char (& lit)[N]): data(std::string_view(lit)) {}
|
||||
|
||||
BackedStringView(const BackedStringView &) = delete;
|
||||
BackedStringView & operator=(const BackedStringView &) = delete;
|
||||
|
||||
/**
|
||||
* We only want move operations defined since the sole purpose of
|
||||
* this type is to avoid copies.
|
||||
*/
|
||||
BackedStringView(BackedStringView && other) = default;
|
||||
BackedStringView & operator=(BackedStringView && other) = default;
|
||||
|
||||
bool isOwned() const
|
||||
{
|
||||
return std::holds_alternative<std::string>(data);
|
||||
}
|
||||
|
||||
std::string toOwned() &&
|
||||
{
|
||||
return isOwned()
|
||||
? std::move(std::get<std::string>(data))
|
||||
: std::string(std::get<std::string_view>(data));
|
||||
}
|
||||
|
||||
std::string_view operator*() const
|
||||
{
|
||||
return isOwned()
|
||||
? std::get<std::string>(data)
|
||||
: std::get<std::string_view>(data);
|
||||
}
|
||||
Ptr operator->() const { return Ptr(**this); }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "archive.hh"
|
||||
#include "derivations.hh"
|
||||
#include "dotgraph.hh"
|
||||
#include "exit.hh"
|
||||
#include "globals.hh"
|
||||
#include "build-result.hh"
|
||||
#include "store-cast.hh"
|
||||
|
@ -17,7 +18,6 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "store-api.hh"
|
||||
#include "local-fs-store.hh"
|
||||
#include "worker-protocol.hh"
|
||||
#include "exit.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include "command.hh"
|
||||
#include "shared.hh"
|
||||
#include "store-api.hh"
|
||||
#include "sync.hh"
|
||||
#include "thread-pool.hh"
|
||||
#include "signals.hh"
|
||||
#include "references.hh"
|
||||
#include "exit.hh"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
|
|
@ -58,3 +58,19 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
// This stuff is here to force the compiler to actually apply the extern
|
||||
// template directives in all compilation units. To borrow a term, under
|
||||
// complex microarchitectural conditions, clang ignores the extern template
|
||||
// declaration, as revealed in the profile.
|
||||
//
|
||||
// In most cases, extern template works fine in the header itself. We don't
|
||||
// have any idea why this happens.
|
||||
|
||||
// Here because of all the regexes everywhere (it is infeasible to block instantiation everywhere)
|
||||
// For some reason this does not actually prevent the instantiation of
|
||||
// regex::_M_compile, and the regex compiler (my interpretation of what this is
|
||||
// supposed to do is make the template bits out-of-line), but it *does* prevent
|
||||
// a bunch of codegen of regex stuff, which seems to save about 30s on-cpu.
|
||||
// Instantiated in libutil/regex.cc.
|
||||
extern template class std::basic_regex<char>;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "experimental-features.hh"
|
||||
#include "derivations.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include "tests/libstore.hh"
|
||||
#include "tests/characterization.hh"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "strings.hh"
|
||||
#include "tests/libstore.hh"
|
||||
#include "tests/characterization.hh"
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "references.hh"
|
||||
#include "strings.hh"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace nix {
|
||||
|
|
Loading…
Reference in a new issue