Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -DVERSION flag for release version numbers #1194

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ endif()
list(INSERT CMAKE_MODULE_PATH 0
${CMAKE_CURRENT_SOURCE_DIR}/CMake
)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)

if (VERSION)
add_definitions(-DSWAY_VERSION=\"${VERSION}\")
else()
execute_process(
COMMAND git describe --always --tags
OUTPUT_VARIABLE GIT_COMMIT_HASH
Expand All @@ -33,13 +36,10 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
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}\")
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d" UTC)
add_definitions("-DSWAY_VERSION=\"${GIT_COMMIT_HASH} (${CURRENT_DATE}, branch \\\"${GIT_BRANCH}\\\")\"")
endif()

option(enable-swaylock "Enables the swaylock utility" YES)
option(enable-swaybg "Enables the wallpaper utility" YES)
Expand Down
37 changes: 7 additions & 30 deletions sway/ipc-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,39 +306,16 @@ json_object *ipc_json_describe_input(struct libinput_device *device) {
}

json_object *ipc_json_get_version() {
int major = 0, minor = 0, patch = 0;
json_object *version = json_object_new_object();

#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
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));
sscanf(SWAY_VERSION, "%u.%u.%u", &major, &minor, &patch);

json_object_object_add(version, "human_readable", json_object_new_string(SWAY_VERSION));
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(0));
json_object_object_add(version, "minor", json_object_new_int(0));
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
json_object_object_add(version, "major", json_object_new_int(major));
json_object_object_add(version, "minor", json_object_new_int(minor));
json_object_object_add(version, "patch", json_object_new_int(patch));

return version;
}
Expand Down
10 changes: 2 additions & 8 deletions sway/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,7 @@ int main(int argc, char **argv) {
debug = 1;
break;
case 'v': // version
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
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
fprintf(stdout, "sway version " SWAY_VERSION "\n");
exit(EXIT_SUCCESS);
break;
case 'V': // verbose
Expand Down Expand Up @@ -378,9 +374,7 @@ int main(int argc, char **argv) {
// prevent ipc from crashing sway
signal(SIGPIPE, SIG_IGN);

#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
sway_log(L_INFO, "Starting sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#endif
sway_log(L_INFO, "Starting sway version " SWAY_VERSION "\n");

init_layout();

Expand Down
6 changes: 1 addition & 5 deletions swaybar/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ int main(int argc, char **argv) {
bar_id = strdup(optarg);
break;
case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
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
fprintf(stdout, "sway version " SWAY_VERSION "\n");
exit(EXIT_SUCCESS);
break;
case 'd': // Debug
Expand Down
6 changes: 1 addition & 5 deletions swaygrab/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ int main(int argc, char **argv) {
framerate = atoi(optarg);
break;
case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
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
fprintf(stdout, "sway version " SWAY_VERSION "\n");
exit(EXIT_SUCCESS);
break;
default:
Expand Down
6 changes: 1 addition & 5 deletions swaylock/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,7 @@ int main(int argc, char **argv) {
socket_path = optarg;
break;
case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
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
fprintf(stdout, "swaylock version " SWAY_VERSION "\n");
exit(EXIT_SUCCESS);
break;
case 'u':
Expand Down
6 changes: 1 addition & 5 deletions swaymsg/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,7 @@ int main(int argc, char **argv) {
cmdtype = strdup(optarg);
break;
case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
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
fprintf(stdout, "sway version " SWAY_VERSION "\n");
exit(EXIT_SUCCESS);
break;
default:
Expand Down