Skip to content

Commit

Permalink
Avoid recompiling multiple files if only the hash changes
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Feb 6, 2025
1 parent 4c98b5d commit 23a7334
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pihole-FTL*

# Versioning files (generated by Makefile)
version.h
version.c
version~

# CMake files generated during compilation
Expand Down
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,10 @@ set(sources
timers.h
vector.c
vector.h
version.c
version.h
)

set_source_files_properties(version.h PROPERTIES GENERATED TRUE)

add_custom_target(
gen_version ALL
COMMAND ${CMAKE_COMMAND} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -P ${CMAKE_CURRENT_SOURCE_DIR}/gen_version.cmake
Expand Down
4 changes: 2 additions & 2 deletions src/api/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,9 @@ int get_version_obj(struct ftl_conn *api, cJSON *version)
fclose(fp);

// Add remaining properties to ftl object
JSON_REF_STR_IN_OBJECT(ftl_local, "branch", GIT_BRANCH);
JSON_REF_STR_IN_OBJECT(ftl_local, "branch", git_branch());
JSON_REF_STR_IN_OBJECT(ftl_local, "version", get_FTL_version());
JSON_REF_STR_IN_OBJECT(ftl_local, "date", GIT_DATE);
JSON_REF_STR_IN_OBJECT(ftl_local, "date", git_date());

cJSON *core = JSON_NEW_OBJECT();
JSON_ADD_NULL_IF_NOT_EXISTS(core_local, "branch");
Expand Down
14 changes: 7 additions & 7 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,10 @@ void parse_args(int argc, char *argv[])
yellow, bold, normal);
printf("Version: %s%s%s%s\n",
green, bold, get_FTL_version(), normal);
printf("Branch: " GIT_BRANCH "\n");
printf("Commit: " GIT_HASH " (" GIT_DATE ")\n");
printf("Architecture: " FTL_ARCH "\n");
printf("Compiler: " FTL_CC "\n");
printf("Branch: %s\n", git_branch());
printf("Commit: %s (%s)",git_hash(), git_date());
printf("Architecture: %s\n", ftl_arch());
printf("Compiler: %s\n", ftl_cc());
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
printf("GLIBC version: %d.%d\n\n", __GLIBC__, __GLIBC_MINOR__);
#else
Expand Down Expand Up @@ -920,20 +920,20 @@ void parse_args(int argc, char *argv[])
if(strcmp(argv[i], "-t") == 0 ||
strcmp(argv[i], "tag") == 0)
{
printf("%s\n",GIT_TAG);
printf("%s\n", git_tag());
exit(EXIT_SUCCESS);
}

if(strcmp(argv[i], "-b") == 0 ||
strcmp(argv[i], "branch") == 0)
{
printf("%s\n",GIT_BRANCH);
printf("%s\n", git_branch());
exit(EXIT_SUCCESS);
}

if(strcmp(argv[i], "--hash") == 0)
{
printf("%s\n",GIT_HASH);
printf("%s\n", git_hash());
exit(EXIT_SUCCESS);
}

Expand Down
2 changes: 1 addition & 1 deletion src/database/message-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ void log_verify_message(const char *expected, const char *actual)
log_crit("%s", buf);

// Log to database
add_message(VERIFY_MESSAGE, buf, expected, actual, GIT_HASH, FTL_ARCH);
add_message(VERIFY_MESSAGE, buf, expected, actual, git_hash(), ftl_arch());

}

Expand Down
6 changes: 3 additions & 3 deletions src/gen_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ message(" - Commit date: ${GIT_DATE}")

# configure the version file, but output to a temporary location
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
${CMAKE_CURRENT_SOURCE_DIR}/version.c.in
${CMAKE_CURRENT_BINARY_DIR}/version~
@ONLY
)
Expand All @@ -109,7 +109,7 @@ execute_process(
COMMAND
${CMAKE_COMMAND} -E compare_files
${CMAKE_CURRENT_BINARY_DIR}/version~
${CMAKE_CURRENT_BINARY_DIR}/version.h
${CMAKE_CURRENT_BINARY_DIR}/version.c
RESULT_VARIABLE
VERSION_NEEDS_UPDATING

Expand All @@ -123,6 +123,6 @@ if(VERSION_NEEDS_UPDATING)
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/version~
${CMAKE_CURRENT_BINARY_DIR}/version.h
${CMAKE_CURRENT_BINARY_DIR}/version.c
)
endif()
18 changes: 9 additions & 9 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,10 @@ void log_counter_info(void)

void log_FTL_version(const bool crashreport)
{
log_info("FTL branch: %s", GIT_BRANCH);
log_info("FTL branch: %s", git_branch());
log_info("FTL version: %s", get_FTL_version());
log_info("FTL commit: %s", GIT_HASH);
log_info("FTL date: %s", GIT_DATE);
log_info("FTL commit: %s", git_hash());
log_info("FTL date: %s", git_date());
if(crashreport)
{
char *username_now = getUserName();
Expand All @@ -510,7 +510,7 @@ void log_FTL_version(const bool crashreport)
}
else
log_info("FTL user: %s", username);
log_info("Compiled for %s using %s", FTL_ARCH, FTL_CC);
log_info("Compiled for %s using %s", ftl_arch(), ftl_cc());
}

static char *FTLversion = NULL;
Expand All @@ -519,21 +519,21 @@ const char __attribute__ ((malloc)) *get_FTL_version(void)
// Obtain FTL version if not already determined
if(FTLversion == NULL)
{
if(strlen(GIT_TAG) > 1 )
if(strlen(git_tag()) > 1 )
{
if (strlen(GIT_VERSION) > 1)
if (strlen(git_version()) > 1)
{
// Copy version string if this is a tagged release
FTLversion = strdup(GIT_VERSION);
FTLversion = strdup(git_version());
}

}
else if(strlen(GIT_HASH) > 0)
else if(strlen(git_hash()) > 0)
{
// Build special version string when there is a hash
FTLversion = calloc(13, sizeof(char));
// Build version by appending 7 characters of the hash to "vDev-"
snprintf(FTLversion, 13, "vDev-%.7s", GIT_HASH);
snprintf(FTLversion, 13, "vDev-%.7s", git_hash());
}
else
{
Expand Down
44 changes: 44 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2025 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Version-related hard-coded strings
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */

#include "version.h"

const char * __attribute__ ((const)) git_version(void)
{
return "v5.25.2-2601-g8fe4ecd0-dirty";
}

const char * __attribute__ ((const)) git_date(void)
{
return "2025-02-06 06:07:12 +0100";
}
const char * __attribute__ ((const)) git_branch(void)
{
return "update/dnsmasq";
}
const char * __attribute__ ((const)) git_tag(void)
{
return "v5.25.2";
}

const char * __attribute__ ((const)) git_hash(void)
{
return "8fe4ecd0-dirty";
}

const char * __attribute__ ((const)) ftl_arch(void)
{
return "x86_64 (compiled locally)";
}

const char * __attribute__ ((const)) ftl_cc(void)
{
return "cc (Alpine 14.2.0) 14.2.0";
}
44 changes: 44 additions & 0 deletions src/version.c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2025 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Version-related hard-coded strings
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */

#include "version.h"

const char * __attribute__ ((const)) git_version(void)
{
return "@GIT_VERSION@";
}

const char * __attribute__ ((const)) git_date(void)
{
return "@GIT_DATE@";
}
const char * __attribute__ ((const)) git_branch(void)
{
return "@GIT_BRANCH@";
}
const char * __attribute__ ((const)) git_tag(void)
{
return "@GIT_TAG@";
}

const char * __attribute__ ((const)) git_hash(void)
{
return "@GIT_HASH@";
}

const char * __attribute__ ((const)) ftl_arch(void)
{
return "@FTL_ARCH@";
}

const char * __attribute__ ((const)) ftl_cc(void)
{
return "@FTL_CC@";
}
12 changes: 0 additions & 12 deletions src/version.h.in

This file was deleted.

0 comments on commit 23a7334

Please sign in to comment.