Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Fix AKTUALIZR_VERSION cache killer
Browse files Browse the repository at this point in the history
If it's part of the CMake global definitions, it invalidates all source
files' ccache after each version change (ie: commit).

Exposing the version through a function only requires the definition to
be part of a single file, so most translation units can be cached.

Signed-off-by: Laurent Bonnans <[email protected]>
  • Loading branch information
lbonn committed Jul 4, 2019
1 parent 10b888e commit 389d61f
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 17 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ if(NOT AKTUALIZR_VERSION)
endif(GIT_EXECUTABLE)
endif(NOT AKTUALIZR_VERSION)

add_definitions(-DAKTUALIZR_VERSION="${AKTUALIZR_VERSION}")

if(BUILD_OSTREE)
find_package(OSTree REQUIRED)
add_definitions(-DBUILD_OSTREE)
Expand Down
4 changes: 3 additions & 1 deletion src/aktualizr_lite/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "package_manager/ostreemanager.h"
#include "primary/sotauptaneclient.h"

#include "utilities/aktualizr_version.h"

namespace bpo = boost::program_options;

static std::shared_ptr<SotaUptaneClient> liteClient(Config &config) {
Expand Down Expand Up @@ -170,7 +172,7 @@ void check_info_options(const bpo::options_description &description, const bpo::
exit(EXIT_SUCCESS);
}
if (vm.count("version") != 0) {
std::cout << "Current aktualizr version is: " << AKTUALIZR_VERSION << "\n";
std::cout << "Current aktualizr version is: " << aktualizr_version() << "\n";
exit(EXIT_SUCCESS);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/aktualizr_primary/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "logging/logging.h"
#include "primary/aktualizr.h"
#include "secondary.h"
#include "utilities/aktualizr_version.h"
#include "utilities/utils.h"

namespace bpo = boost::program_options;
Expand All @@ -20,7 +21,7 @@ void check_info_options(const bpo::options_description &description, const bpo::
exit(EXIT_SUCCESS);
}
if (vm.count("version") != 0) {
std::cout << "Current aktualizr version is: " << AKTUALIZR_VERSION << "\n";
std::cout << "Current aktualizr version is: " << aktualizr_version() << "\n";
exit(EXIT_SUCCESS);
}
}
Expand Down Expand Up @@ -102,7 +103,7 @@ int main(int argc, char *argv[]) {

bpo::variables_map commandline_map = parse_options(argc, argv);

LOG_INFO << "Aktualizr version " AKTUALIZR_VERSION " starting";
LOG_INFO << "Aktualizr version " << aktualizr_version() << " starting";

int r = EXIT_FAILURE;

Expand Down
5 changes: 3 additions & 2 deletions src/aktualizr_secondary/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "aktualizr_secondary.h"
#include "aktualizr_secondary_config.h"
#include "utilities/aktualizr_version.h"
#include "utilities/utils.h"

#include "logging/logging.h"
Expand All @@ -20,7 +21,7 @@ void check_secondary_options(const bpo::options_description &description, const
exit(EXIT_SUCCESS);
}
if (vm.count("version") != 0) {
std::cout << "Current aktualizr-secondary version is: " << AKTUALIZR_VERSION << "\n";
std::cout << "Current aktualizr-secondary version is: " << aktualizr_version() << "\n";
exit(EXIT_SUCCESS);
}
}
Expand Down Expand Up @@ -77,7 +78,7 @@ bpo::variables_map parse_options(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
logger_init();
logger_set_threshold(boost::log::trivial::info);
LOG_INFO << "Aktualizr-secondary version " AKTUALIZR_VERSION " starting";
LOG_INFO << "Aktualizr-secondary version " << aktualizr_version() << " starting";

bpo::variables_map commandline_map = parse_options(argc, argv);

Expand Down
3 changes: 2 additions & 1 deletion src/cert_provider/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "crypto/crypto.h"
#include "http/httpclient.h"
#include "logging/logging.h"
#include "utilities/aktualizr_version.h"
#include "utilities/utils.h"

namespace bpo = boost::program_options;
Expand All @@ -26,7 +27,7 @@ void check_info_options(const bpo::options_description& description, const bpo::
exit(EXIT_SUCCESS);
}
if (vm.count("version") != 0) {
std::cout << "Current aktualizr-cert-provider version is: " << AKTUALIZR_VERSION << "\n";
std::cout << "Current aktualizr-cert-provider version is: " << aktualizr_version() << "\n";
exit(EXIT_SUCCESS);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/hmi_stub/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "config/config.h"
#include "logging/logging.h"
#include "primary/aktualizr.h"
#include "utilities/aktualizr_version.h"
#include "utilities/utils.h"

namespace bpo = boost::program_options;
Expand All @@ -29,7 +30,7 @@ void check_info_options(const bpo::options_description &description, const bpo::
exit(EXIT_SUCCESS);
}
if (vm.count("version") != 0) {
std::cout << "Current hmi_stub version is: " << AKTUALIZR_VERSION << "\n";
std::cout << "Current hmi_stub version is: " << aktualizr_version() << "\n";
exit(EXIT_SUCCESS);
}
}
Expand Down Expand Up @@ -121,7 +122,7 @@ void process_event(const std::shared_ptr<event::BaseEvent> &event) {
int main(int argc, char *argv[]) {
logger_init();
logger_set_threshold(boost::log::trivial::info);
LOG_INFO << "hmi_stub version " AKTUALIZR_VERSION " starting";
LOG_INFO << "hmi_stub version " << aktualizr_version() << " starting";

bpo::variables_map commandline_map = parse_options(argc, argv);

Expand Down
3 changes: 2 additions & 1 deletion src/libaktualizr/http/httpclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <openssl/ssl.h>

#include "crypto/openssl_compat.h"
#include "utilities/aktualizr_version.h"
#include "utilities/utils.h"

struct WriteStringArg {
Expand Down Expand Up @@ -45,7 +46,7 @@ static size_t writeString(void* contents, size_t size, size_t nmemb, void* userp
return size * nmemb;
}

HttpClient::HttpClient() : user_agent(std::string("Aktualizr/") + AKTUALIZR_VERSION) {
HttpClient::HttpClient() : user_agent(std::string("Aktualizr/") + aktualizr_version()) {
curl = curl_easy_init();
if (curl == nullptr) {
throw std::runtime_error("Could not initialize curl");
Expand Down
5 changes: 4 additions & 1 deletion src/libaktualizr/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
set(SOURCES apiqueue.cc
set(SOURCES aktualizr_version.cc
apiqueue.cc
dequeue_buffer.cc
sockaddr_io.cc
timer.cc
types.cc
utils.cc)

set(HEADERS apiqueue.h
aktualizr_version.h
config_utils.h
dequeue_buffer.h
exceptions.h
Expand All @@ -15,6 +17,7 @@ set(HEADERS apiqueue.h
types.h
utils.h)

set_property(SOURCE aktualizr_version.cc PROPERTY COMPILE_DEFINITIONS AKTUALIZR_VERSION="${AKTUALIZR_VERSION}")

add_library(utilities OBJECT ${SOURCES})
include(AddAktualizrTest)
Expand Down
5 changes: 5 additions & 0 deletions src/libaktualizr/utilities/aktualizr_version.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "aktualizr_version.h"

const char *aktualizr_version() {
return AKTUALIZR_VERSION;
}
10 changes: 10 additions & 0 deletions src/libaktualizr/utilities/aktualizr_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef AKTUALIZR_VERSION_H_
#define AKTUALIZR_VERSION_H_

// This is part of a separate library which is the only one where the
// AKTUALIZR_VERSION macro is defined, so that the rest of the code base
// compilation can be cached (e.g: with ccache)

const char *aktualizr_version();

#endif // AKTUALIZR_VERSION_H_
6 changes: 4 additions & 2 deletions src/sota_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include_directories("${PROJECT_SOURCE_DIR}/src/libaktualizr/third_party/jsoncpp"
set(SOTA_TOOLS_LIB_SRC
authenticate.cc
deploy.cc
garage_tools_version.cc
oauth2.cc
ostree_dir_repo.cc
ostree_hash.cc
Expand All @@ -15,6 +16,8 @@ set(SOTA_TOOLS_LIB_SRC
treehub_server.cc)

if (BUILD_SOTA_TOOLS)
set(GARAGE_TOOLS_VERSION "${AKTUALIZR_VERSION}")
set_property(SOURCE garage_tools_version.cc PROPERTY COMPILE_DEFINITIONS GARAGE_TOOLS_VERSION="${GARAGE_TOOLS_VERSION}")
add_library(sota_tools_static_lib STATIC ${SOTA_TOOLS_LIB_SRC})
target_include_directories(sota_tools_static_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR} ${GLIB2_INCLUDE_DIRS})
endif (BUILD_SOTA_TOOLS)
Expand Down Expand Up @@ -64,8 +67,6 @@ if (BUILD_SOTA_TOOLS)
add_executable(garage-deploy ${GARAGE_DEPLOY_SRCS})
target_link_libraries(garage-deploy sota_tools_static_lib aktualizr_static_lib ${SOTA_TOOLS_EXTERNAL_LIBS})

add_definitions(-DGARAGE_TOOLS_VERSION="${AKTUALIZR_VERSION}")

add_dependencies(build_tests garage-deploy)

install(TARGETS garage-deploy RUNTIME DESTINATION bin COMPONENT garage_deploy)
Expand Down Expand Up @@ -101,6 +102,7 @@ set(ALL_SOTA_TOOLS_HEADERS
authenticate.h
deploy.h
garage_common.h
garage_tools_version.h
oauth2.h
ostree_dir_repo.h
ostree_hash.h
Expand Down
3 changes: 2 additions & 1 deletion src/sota_tools/garage_check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "accumulator.h"
#include "authenticate.h"
#include "garage_common.h"
#include "garage_tools_version.h"
#include "logging/logging.h"
#include "ostree_http_repo.h"
#include "ostree_object.h"
Expand Down Expand Up @@ -61,7 +62,7 @@ int main(int argc, char **argv) {
return EXIT_SUCCESS;
}
if (vm.count("version") != 0) {
LOG_INFO << "Current garage-check version is: " << GARAGE_TOOLS_VERSION;
LOG_INFO << "Current garage-check version is: " << garage_tools_version();
exit(EXIT_SUCCESS);
}
po::notify(vm);
Expand Down
3 changes: 2 additions & 1 deletion src/sota_tools/garage_deploy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "accumulator.h"
#include "authenticate.h"
#include "deploy.h"
#include "garage_tools_version.h"
#include "garage_common.h"
#include "logging/logging.h"
#include "ostree_http_repo.h"
Expand Down Expand Up @@ -51,7 +52,7 @@ int main(int argc, char **argv) {
return EXIT_SUCCESS;
}
if (vm.count("version") != 0) {
LOG_INFO << "Current garage-deploy version is: " << GARAGE_TOOLS_VERSION;
LOG_INFO << "Current garage-deploy version is: " << garage_tools_version();
exit(EXIT_SUCCESS);
}
po::notify(vm);
Expand Down
3 changes: 2 additions & 1 deletion src/sota_tools/garage_push.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "accumulator.h"
#include "deploy.h"
#include "garage_common.h"
#include "garage_tools_version.h"
#include "logging/logging.h"
#include "ostree_dir_repo.h"
#include "ostree_repo.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ int main(int argc, char **argv) {
return EXIT_SUCCESS;
}
if (vm.count("version") != 0) {
LOG_INFO << "Current garage-push version is: " << GARAGE_TOOLS_VERSION;
LOG_INFO << "Current garage-push version is: " << garage_tools_version();
exit(EXIT_SUCCESS);
}
po::notify(vm);
Expand Down
5 changes: 5 additions & 0 deletions src/sota_tools/garage_tools_version.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "garage_tools_version.h"

const char *garage_tools_version() {
return GARAGE_TOOLS_VERSION;
}
8 changes: 8 additions & 0 deletions src/sota_tools/garage_tools_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef GARAGE_TOOLS_VERSION_H_
#define GARAGE_TOOLS_VERSION_H_

// Same purpose as aktualizr_version.h

const char *garage_tools_version();

#endif // GARAGE_TOOLS_VERSION_H_

0 comments on commit 389d61f

Please sign in to comment.