Add -DVERSION flag for release version numbers

This commit is contained in:
Sebastian Noack 2017-04-26 11:29:30 +02:00
parent aca0710b9e
commit 173b338567
7 changed files with 19 additions and 64 deletions

View file

@ -20,7 +20,10 @@ endif()
list(INSERT CMAKE_MODULE_PATH 0 list(INSERT CMAKE_MODULE_PATH 0
${CMAKE_CURRENT_SOURCE_DIR}/CMake ${CMAKE_CURRENT_SOURCE_DIR}/CMake
) )
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
if (VERSION)
add_definitions(-DSWAY_VERSION=\"${VERSION}\")
else()
execute_process( execute_process(
COMMAND git describe --always --tags COMMAND git describe --always --tags
OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_VARIABLE GIT_COMMIT_HASH
@ -33,14 +36,11 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
) )
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d" UTC)
add_definitions("-DSWAY_VERSION=\"${GIT_COMMIT_HASH} (${CURRENT_DATE}, branch \\\"${GIT_BRANCH}\\\")\"")
endif() endif()
add_definitions(-DSWAY_GIT_VERSION=\"${GIT_COMMIT_HASH}\")
add_definitions(-DSWAY_GIT_BRANCH=\"${GIT_BRANCH}\")
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d" UTC)
add_definitions(-DSWAY_VERSION_DATE=\"${CURRENT_DATE}\")
option(enable-swaylock "Enables the swaylock utility" YES) option(enable-swaylock "Enables the swaylock utility" YES)
option(enable-swaybg "Enables the wallpaper utility" YES) option(enable-swaybg "Enables the wallpaper utility" YES)
option(enable-swaybar "Enables the swaybar utility" YES) option(enable-swaybar "Enables the swaybar utility" YES)

View file

@ -306,39 +306,16 @@ json_object *ipc_json_describe_input(struct libinput_device *device) {
} }
json_object *ipc_json_get_version() { json_object *ipc_json_get_version() {
int major = 0, minor = 0, patch = 0;
json_object *version = json_object_new_object(); json_object *version = json_object_new_object();
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE sscanf(SWAY_VERSION, "%u.%u.%u", &major, &minor, &patch);
char *full_version = calloc(strlen(SWAY_GIT_VERSION) + strlen(SWAY_GIT_BRANCH) + strlen(SWAY_VERSION_DATE) + 20, 1);
if (!full_version) {
json_object_object_add(version, "human_readable",
json_object_new_string("Allocating version string failed"));
// TODO: it's stupid that we allocate this in the first place
json_object_object_add(version, "major", json_object_new_int(0));
json_object_object_add(version, "minor", json_object_new_int(0));
json_object_object_add(version, "patch", json_object_new_int(0));
return version;
}
strcat(full_version, SWAY_GIT_VERSION);
strcat(full_version, " (");
strcat(full_version, SWAY_VERSION_DATE);
strcat(full_version, ", branch \"");
strcat(full_version, SWAY_GIT_BRANCH);
strcat(full_version, "\")");
json_object_object_add(version, "human_readable", json_object_new_string(full_version)); json_object_object_add(version, "human_readable", json_object_new_string(SWAY_VERSION));
json_object_object_add(version, "variant", json_object_new_string("sway")); json_object_object_add(version, "variant", json_object_new_string("sway"));
// Todo once we actually release a version json_object_object_add(version, "major", json_object_new_int(major));
json_object_object_add(version, "major", json_object_new_int(0)); json_object_object_add(version, "minor", json_object_new_int(minor));
json_object_object_add(version, "minor", json_object_new_int(0)); json_object_object_add(version, "patch", json_object_new_int(patch));
json_object_object_add(version, "patch", json_object_new_int(1));
free(full_version);
#else
json_object_object_add(version, "human_readable", json_object_new_string("version not found"));
json_object_object_add(version, "major", json_object_new_int(0));
json_object_object_add(version, "minor", json_object_new_int(0));
json_object_object_add(version, "patch", json_object_new_int(0));
#endif
return version; return version;
} }

View file

@ -267,11 +267,7 @@ int main(int argc, char **argv) {
debug = 1; debug = 1;
break; break;
case 'v': // version case 'v': // version
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE fprintf(stdout, "sway version " SWAY_VERSION "\n");
fprintf(stdout, "sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#else
fprintf(stdout, "version not detected\n");
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'V': // verbose case 'V': // verbose
@ -378,9 +374,7 @@ int main(int argc, char **argv) {
// prevent ipc from crashing sway // prevent ipc from crashing sway
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE sway_log(L_INFO, "Starting sway version " SWAY_VERSION "\n");
sway_log(L_INFO, "Starting sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#endif
init_layout(); init_layout();

View file

@ -63,11 +63,7 @@ int main(int argc, char **argv) {
bar_id = strdup(optarg); bar_id = strdup(optarg);
break; break;
case 'v': case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE fprintf(stdout, "sway version " SWAY_VERSION "\n");
fprintf(stdout, "sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#else
fprintf(stdout, "version not detected\n");
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'd': // Debug case 'd': // Debug

View file

@ -201,11 +201,7 @@ int main(int argc, char **argv) {
framerate = atoi(optarg); framerate = atoi(optarg);
break; break;
case 'v': case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE fprintf(stdout, "sway version " SWAY_VERSION "\n");
fprintf(stdout, "sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#else
fprintf(stdout, "version not detected\n");
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
default: default:

View file

@ -451,11 +451,7 @@ int main(int argc, char **argv) {
socket_path = optarg; socket_path = optarg;
break; break;
case 'v': case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE fprintf(stdout, "swaylock version " SWAY_VERSION "\n");
fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#else
fprintf(stdout, "version not detected\n");
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'u': case 'u':

View file

@ -230,11 +230,7 @@ int main(int argc, char **argv) {
cmdtype = strdup(optarg); cmdtype = strdup(optarg);
break; break;
case 'v': case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE fprintf(stdout, "sway version " SWAY_VERSION "\n");
fprintf(stdout, "sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#else
fprintf(stdout, "version not detected\n");
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
default: default: