~ruther/guix-local

d1a9fb85a4d46722f06d01bde6f61acae3d9ea7a — Congcong Kuo 5 months ago 6fe5e7f
daemon: Use inline functions and variables instead of extern

Avoid separate declarations and definitions for so-called 'global' objects.

* nix/libstore/derivations.{cc, hh} (drvHashes): Use inline instead of separate
declaration and definition.
* nix/libstore/globals.{cc, hh} (settings, nixVersion): Same.
* nix/libstore/local-store.hh (drvsLogDir, deduplicationMinSize): Same.
* nix/libstore/optimise-store.cc (deduplicationMinSize): Same.
* nix/libstore/store-api.{cc, hh} (store): Same.
* nix/libutil/archive.{cc, hh} (defaultPathFilter): Same.
* nix/libutil/hash.{cc, hh} (base32Chars): Same and modify header files.
* nix/libutil/util.{cc, hh} (logType, verbosity, _writeToStderr,
_isInterrupted): Same.
* nix/local.mk: Modified according to the rename of shared.hh.
* nix/nix-daemon/guix-daemon.cc (blockInt, argvSaved, run): Same and
modify header files.
* nix/nix-daemon/nix-daemon.cc: Modify header files.
* nix/nix-daemon/shared.hh: Renamed to nix-daemon.hh

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
M nix/libstore/build.cc => nix/libstore/build.cc +0 -3
@@ 3367,9 3367,6 @@ void DerivationGoal::registerOutputs()
}


string drvsLogDir = "drvs";


Path DerivationGoal::openLogFile()
{
    logSize = 0;

M nix/libstore/derivations.cc => nix/libstore/derivations.cc +0 -3
@@ 211,9 211,6 @@ bool isFixedOutputDrv(const Derivation & drv)
}


DrvHashes drvHashes;


/* Returns the hash of a derivation modulo fixed-output
   subderivations.  A fixed-output derivation is a derivation with one
   output (`out') for which an expected hash and hash algorithm are

M nix/libstore/derivations.hh => nix/libstore/derivations.hh +1 -1
@@ 77,7 77,7 @@ Hash hashDerivationModulo(StoreAPI & store, Derivation drv);
/* Memoisation of hashDerivationModulo(). */
typedef std::map<Path, Hash> DrvHashes;

extern DrvHashes drvHashes;
inline DrvHashes drvHashes;

/* Split a string specifying a derivation and a set of outputs
   (/nix/store/hash-foo!out1,out2,...) into the derivation path and

M nix/libstore/globals.cc => nix/libstore/globals.cc +0 -6
@@ 17,9 17,6 @@ namespace nix {
#define DEFAULT_SOCKET_PATH "/daemon-socket/socket"


Settings settings;


Settings::Settings()
{
    keepFailed = false;


@@ 205,7 202,4 @@ Settings::SettingsMap Settings::getOverrides()
}


const string nixVersion = PACKAGE_VERSION;


}

M nix/libstore/globals.hh => nix/libstore/globals.hh +2 -2
@@ 227,10 227,10 @@ private:


// FIXME: don't use a global variable.
extern Settings settings;
inline Settings settings;


extern const string nixVersion;
inline const string nixVersion {PACKAGE_VERSION};


}

M nix/libstore/local-store.hh => nix/libstore/local-store.hh +4 -2
@@ 19,7 19,7 @@ namespace nix {
const int nixSchemaVersion = 7;


extern string drvsLogDir;
inline std::string drvsLogDir {"drvs"};


struct Derivation;


@@ 293,6 293,8 @@ void canonicaliseTimestampAndPermissions(const Path & path);
MakeError(PathInUse, Error);

/* Size below which a file is not considered for deduplication.  */
extern const size_t deduplicationMinSize;
/* Any file smaller than this is not considered for deduplication.
   Keep in sync with (guix store deduplication).  */
inline const size_t deduplicationMinSize {8192};

}

M nix/libstore/optimise-store.cc => nix/libstore/optimise-store.cc +0 -3
@@ 16,9 16,6 @@

namespace nix {

/* Any file smaller than this is not considered for deduplication.
   Keep in sync with (guix store deduplication).  */
const size_t deduplicationMinSize = 8192;

static void makeWritable(const Path & path)
{

M nix/libstore/store-api.cc => nix/libstore/store-api.cc +0 -13
@@ 253,16 253,3 @@ template<class T> T readStorePaths(Source & from)
template PathSet readStorePaths(Source & from);

}


#include "local-store.hh"
#include "serialise.hh"


namespace nix {


std::shared_ptr<StoreAPI> store;


}

M nix/libstore/store-api.hh => nix/libstore/store-api.hh +1 -1
@@ 363,7 363,7 @@ Paths topoSortPaths(StoreAPI & store, const PathSet & paths);

/* For now, there is a single global store API object, but we'll
   purify that in the future. */
extern std::shared_ptr<StoreAPI> store;
inline std::shared_ptr<StoreAPI> store;


/* Display a set of paths in human-readable form (i.e., between quotes

M nix/libutil/archive.cc => nix/libutil/archive.cc +0 -2
@@ 24,8 24,6 @@ static string archiveVersion1 = "nix-archive-1";

static string caseHackSuffix = "~nix~case~hack~";

PathFilter defaultPathFilter;


static void dumpContents(const Path & path, size_t size,
    Sink & sink)

M nix/libutil/archive.hh => nix/libutil/archive.hh +1 -1
@@ 50,7 50,7 @@ struct PathFilter
    virtual bool operator () (const Path & path) { return true; }
};

extern PathFilter defaultPathFilter;
inline PathFilter defaultPathFilter;

void dumpPath(const Path & path, Sink & sink,
    PathFilter & filter = defaultPathFilter);

M nix/libutil/hash.cc => nix/libutil/hash.cc +0 -4
@@ 103,10 103,6 @@ unsigned int hashLength32(const Hash & hash)
}


// omitted: E O U T
const string base32Chars = "0123456789abcdfghijklmnpqrsvwxyz";


string printHash32(const Hash & hash)
{
    Hash hash2(hash);

M nix/libutil/hash.hh => nix/libutil/hash.hh +3 -4
@@ 2,14 2,15 @@

#include <gcrypt.h>

#include "archive.hh"
#include "types.hh"
#include "serialise.hh"


namespace nix {


extern const string base32Chars;
// omitted: E O U T
inline const string base32Chars {"0123456789abcdfghijklmnpqrsvwxyz"};

typedef enum {
    htUnknown = 0,


@@ 79,8 80,6 @@ Hash hashFile(HashType ht, const Path & path);

/* Compute the hash of the given path.  The hash is defined as
   (essentially) hashString(ht, dumpPath(path)). */
struct PathFilter;
extern PathFilter defaultPathFilter;
typedef std::pair<Hash, unsigned long long> HashResult;
HashResult hashPath(HashType ht, const Path & path,
    PathFilter & filter = defaultPathFilter);

M nix/libutil/util.cc => nix/libutil/util.cc +0 -7
@@ 600,9 600,6 @@ void createSymlink(const Path & target, const Path & link)
}


LogType logType = ltPretty;
Verbosity verbosity = lvlInfo;

static int nestingLevel = 0;




@@ 691,9 688,6 @@ void writeToStderr(const string & s)
}


void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0;


void readFull(int fd, unsigned char * buf, size_t count)
{
    while (count) {


@@ 1250,7 1244,6 @@ void keepOnExec(int fd)
//////////////////////////////////////////////////////////////////////


volatile sig_atomic_t _isInterrupted = 0;

void _interrupted()
{

M nix/libutil/util.hh => nix/libutil/util.hh +4 -4
@@ 132,8 132,8 @@ typedef enum {
    ltFlat      /* no nesting */
} LogType;

extern LogType logType;
extern Verbosity verbosity; /* suppress msgs > this */
inline LogType logType {ltPretty};
inline Verbosity verbosity {lvlInfo}; /* suppress msgs > this */

class Nest
{


@@ 167,7 167,7 @@ void warnOnce(bool & haveWarned, std::string_view fs);

void writeToStderr(const string & s);

extern void (*_writeToStderr) (const unsigned char * buf, size_t count);
inline void (*_writeToStderr) (const unsigned char * buf, size_t count) = 0;


/* Wrappers arount read()/write() that read/write exactly the


@@ 323,7 323,7 @@ void commonChildInit(Pipe & logPipe);

/* User interruption. */

extern volatile sig_atomic_t _isInterrupted;
inline volatile sig_atomic_t _isInterrupted = 0;

void _interrupted();


M nix/local.mk => nix/local.mk +1 -1
@@ 113,7 113,7 @@ guix_daemon_LDADD =				\
  $(SQLITE3_LIBS) $(LIBGCRYPT_LIBS)

guix_daemon_headers =				\
  %D%/nix-daemon/shared.hh
  %D%/nix-daemon/nix-daemon.hh

if HAVE_LIBBZ2


M nix/nix-daemon/guix-daemon.cc => nix/nix-daemon/guix-daemon.cc +5 -12
@@ 17,12 17,12 @@
   You should have received a copy of the GNU General Public License
   along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.  */

#include <config.h>
#include "config.h"

#include <types.hh>
#include "shared.hh"
#include <globals.hh>
#include <util.hh>
#include "types.hh"
#include "nix-daemon.hh"
#include "globals.hh"
#include "util.hh"

#include <gcrypt.h>



@@ 36,20 36,13 @@
#include <netdb.h>
#include <strings.h>
#include <exception>
#include <iostream>
#include <format>

#include <libintl.h>
#include <locale.h>

/* Variables used by `nix-daemon.cc'.  */
volatile ::sig_atomic_t blockInt;
char **argvSaved;

using namespace nix;

/* Entry point in `nix-daemon.cc'.  */
extern void run (const std::vector<int> &);


/* Command-line options.  */

M nix/nix-daemon/nix-daemon.cc => nix/nix-daemon/nix-daemon.cc +1 -1
@@ 1,5 1,5 @@
#include "config.h"
#include "shared.hh"
#include "nix-daemon.hh"
#include "local-store.hh"
#include "util.hh"
#include "serialise.hh"

R nix/nix-daemon/shared.hh => nix/nix-daemon/nix-daemon.hh +7 -2
@@ 20,9 20,14 @@

#pragma once

#include <vector>

#include <stdlib.h>
#include <signal.h>

extern volatile ::sig_atomic_t blockInt;
/* Variables used by `nix-daemon.cc'.  */
inline volatile ::sig_atomic_t blockInt;
inline char **argvSaved;

extern char **argvSaved;
/* Entry point in `nix-daemon.cc'.  */
void run (const std::vector<int> &);