Move tor_git_revision into a new module.

At first, we put the tor_git_revision constant in tor_main.c, so
that we wouldn't have to recompile config.o every time the git
revision changed.  But putting it there had unintended side effect
of forcing every program that wanted to link libor.a (including
test, test-slow, the fuzzers, the benchmarks, etc) to declare their
own tor_git_revision instance.

That's not very nice, especially since we want to start supporting
others who want to link against Tor (see 23846).

So, create a new git_revision.c file that only contains this
constant, and remove the duplicated boilerplate from everywhere
else.

Part of implementing ticket 23845.
This commit is contained in:
Nick Mathewson 2017-10-18 13:49:35 -04:00
parent b9b5f9a1a5
commit 72b5e4a2db
9 changed files with 36 additions and 28 deletions

4
changes/ticket23845 Normal file
View File

@ -0,0 +1,4 @@
o Code simplification and refactoring:
- The tor_git_revision[] constant no longer needs to be redeclared
by everything that links against the rest of Tor. Done as part
of ticket 23845, to simplify our external API.

View File

@ -82,6 +82,7 @@
#include "dirvote.h" #include "dirvote.h"
#include "dns.h" #include "dns.h"
#include "entrynodes.h" #include "entrynodes.h"
#include "git_revision.h"
#include "geoip.h" #include "geoip.h"
#include "hibernate.h" #include "hibernate.h"
#include "main.h" #include "main.h"
@ -879,8 +880,6 @@ set_options(or_options_t *new_val, char **msg)
return 0; return 0;
} }
extern const char tor_git_revision[]; /* from tor_main.c */
/** The version of this Tor process, as parsed. */ /** The version of this Tor process, as parsed. */
static char *the_tor_version = NULL; static char *the_tor_version = NULL;
/** A shorter version of this Tor process's version, for export in our router /** A shorter version of this Tor process's version, for export in our router

17
src/or/git_revision.c Normal file
View File

@ -0,0 +1,17 @@
/* Copyright 2001-2004 Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#include "git_revision.h"
/** String describing which Tor Git repository version the source was
* built from. This string is generated by a bit of shell kludging in
* src/or/include.am, and is usually right.
*/
const char tor_git_revision[] =
#ifndef _MSC_VER
#include "micro-revision.i"
#endif
"";

12
src/or/git_revision.h Normal file
View File

@ -0,0 +1,12 @@
/* Copyright 2001-2004 Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_GIT_REVISION_H
#define TOR_GIT_REVISION_H
extern const char tor_git_revision[];
#endif

View File

@ -51,6 +51,7 @@ LIBTOR_A_SOURCES = \
src/or/geoip.c \ src/or/geoip.c \
src/or/entrynodes.c \ src/or/entrynodes.c \
src/or/ext_orport.c \ src/or/ext_orport.c \
src/or/git_revision.c \
src/or/hibernate.c \ src/or/hibernate.c \
src/or/hs_cache.c \ src/or/hs_cache.c \
src/or/hs_cell.c \ src/or/hs_cell.c \
@ -189,6 +190,7 @@ ORHEADERS = \
src/or/fp_pair.h \ src/or/fp_pair.h \
src/or/geoip.h \ src/or/geoip.h \
src/or/entrynodes.h \ src/or/entrynodes.h \
src/or/git_revision.h \
src/or/hibernate.h \ src/or/hibernate.h \
src/or/hs_cache.h \ src/or/hs_cache.h \
src/or/hs_cell.h \ src/or/hs_cell.h \

View File

@ -3,18 +3,6 @@
* Copyright (c) 2007-2017, The Tor Project, Inc. */ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */ /* See LICENSE for licensing information */
extern const char tor_git_revision[];
/** String describing which Tor Git repository version the source was
* built from. This string is generated by a bit of shell kludging in
* src/or/include.am, and is usually right.
*/
const char tor_git_revision[] =
#ifndef _MSC_VER
#include "micro-revision.i"
#endif
"";
/** /**
* \file tor_main.c * \file tor_main.c
* \brief Stub module containing a main() function. * \brief Stub module containing a main() function.

View File

@ -3,11 +3,6 @@
* Copyright (c) 2007-2017, The Tor Project, Inc. */ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */ /* See LICENSE for licensing information */
extern const char tor_git_revision[];
/* Ordinarily defined in tor_main.c; this bit is just here to provide one
* since we're not linking to tor_main.c */
const char tor_git_revision[] = "";
/** /**
* \file bench.c * \file bench.c
* \brief Benchmarks for lower level Tor modules. * \brief Benchmarks for lower level Tor modules.

View File

@ -9,9 +9,6 @@
#include "crypto.h" #include "crypto.h"
#include "crypto_ed25519.h" #include "crypto_ed25519.h"
extern const char tor_git_revision[];
const char tor_git_revision[] = "";
static or_options_t *mock_options = NULL; static or_options_t *mock_options = NULL;
static const or_options_t * static const or_options_t *
mock_get_options(void) mock_get_options(void)

View File

@ -3,12 +3,6 @@
* Copyright (c) 2007-2017, The Tor Project, Inc. */ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */ /* See LICENSE for licensing information */
extern const char tor_git_revision[];
/* Ordinarily defined in tor_main.c; this bit is just here to provide one
* since we're not linking to tor_main.c */
const char tor_git_revision[] = "";
/** /**
* \file test_common.c * \file test_common.c
* \brief Common pieces to implement unit tests. * \brief Common pieces to implement unit tests.