Skip to content

Commit

Permalink
get version from git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Nov 5, 2021
1 parent 6b53ad1 commit 60e9ac0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ set(CMAKE_CUDA_COMPILER $ENV{CUDA_HOME}/bin/nvcc)
enable_language(CUDA)
include_directories($ENV{CUDA_HOME}/include)

# VERSIONING
execute_process(
COMMAND git rev-parse --is-inside-work-tree
OUTPUT_VARIABLE GIT_REPO OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (GIT_REPO)
execute_process (
COMMAND bash -c "echo $(git describe --dirty --always --tags) | tr - +"
OUTPUT_VARIABLE git_version
)
add_definitions(-DTS_VERSION=${git_version})
endif()

set(target ts)
add_executable(
${target}
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ OBJECTS=main.o \
TARGET=ts
INSTALL=install -c

GIT_REPO=$(shell git rev-parse --is-inside-work-tree)
ifdef GIT_REPO
GIT_VERSION=$(shell echo $(shell git describe --dirty --always --tags) | tr - +)
endif

all: $(TARGET)

$(TARGET): $(OBJECTS)
Expand All @@ -32,6 +37,7 @@ $(TARGET): $(OBJECTS)

# Dependencies
main.o: main.c main.h
$(CC) $(CFLAGS) $(CPPFLAGS) -DTS_VERSION=$(GIT_VERSION) -c $< -o $@
server_start.o: server_start.c main.h
server.o: server.c main.h
client.o: client.c main.h
Expand Down
13 changes: 0 additions & 13 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,16 +922,3 @@ void c_set_logdir() {
send_msg(server_socket, &m);
send_bytes(server_socket, command_line.label, m.u.size);
}

static void shuffle(int *array, size_t n) {
if (n > 1) {
size_t i;
srand(time(NULL));
for (i = 0; i < n - 1; i++) {
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
}
25 changes: 21 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
Please find the license in the provided COPYING file.
*/
#define TS_VERSION_FALLBACK "1.3.0"

/* from https://github.com/LLNL/lbann/issues/117
* and https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html#Stringizing */
#define TS_MAKE_STR(x) _TS_MAKE_STR(x)
#define _TS_MAKE_STR(x) #x

#include <unistd.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -28,9 +35,18 @@ int term_width;
static char getopt_env[] = "POSIXLY_CORRECT=YES";
static char *old_getopt_env;

static char version[] = "Task Spooler v1.2 - a task queue system for the unix user.\n"
"Copyright (C) 2007-2020 Duc Nguyen - Lluis Batlle i Rossell";

static char version[1024];

static void init_version() {
#ifdef TS_VERSION
char *ts_version = TS_MAKE_STR(TS_VERSION);
sprintf(version, "Task Spooler %s - a task queue system for the unix user.\n"
"Copyright (C) 2007-2020 Duc Nguyen - Lluis Batlle i Rossell", ts_version);
#else
sprintf(version, "Task Spooler %s - a task queue system for the unix user.\n"
"Copyright (C) 2007-2020 Duc Nguyen - Lluis Batlle i Rossell", TS_VERSION_FALLBACK);
#endif
}

static void default_command_line() {
command_line.request = c_LIST;
Expand Down Expand Up @@ -446,7 +462,7 @@ static void print_help(const char *cmd) {
printf(" --unsetenv [var] remove the specified flag from server environment.\n");
printf(" --set_gpu_free_perc [num] set the value of GPU memory threshold above which GPUs are considered available (90 by default).\n");
printf(" --get_gpu_free_perc get the value of GPU memory threshold above which GPUs are considered available.\n");
printf(" --unsetenv <var> remove the specified flag from server environment.\n");
printf(" --unsetenv [var] remove the specified flag from server environment.\n");
printf(" --get_label || -a [id] show the job label. Of the last added, if not specified.\n");
printf(" --full_cmd || -F [id] show full command. Of the last added, if not specified.\n");
printf(" --count_running || -R return the number of running jobs\n");
Expand Down Expand Up @@ -516,6 +532,7 @@ static void get_terminal_width() {
int main(int argc, char **argv) {
int errorlevel = 0;

init_version();
get_terminal_width();
process_type = CLIENT;

Expand Down

0 comments on commit 60e9ac0

Please sign in to comment.