diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1db8c4d..b25311a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,68 +1,31 @@ - - variables: -# PRODUCT_NAME: "AG" -# PRODUCT_VARIANT: "NA" -# PRODUCT_VARIANT: "EU" -# PRODUCT_VARIANT: "CN" -# PROJECT_VERSION: "10" -# SW_MAJOR: "1" -# SW_MINOR: "3" - + SW_MAJOR: "0" + SW_MINOR: "1" + APP: "engine_control" before_script: - "echo $CI_BUILD_ID" - "echo $CI_BUILD_REF_NAME" stages: -# - check - build -# - test -# - deploy + - deploy build_job: script: - "make all BOARD=stm32f4-discovery" -# - "make all BOARD=stm32f4-discovery DEBUG=y" stage: build except: - /^release/.*$/ -#check_job: -# script: -# - "make check BOARD=stm32f4-discovery DEBUG=y" -# stage: check - -#test_job: -# script: -# - "python source/scripts/get_history.py" -# - "make install BOARD=stm32f4-discovery DEBUG=y" -# stage: test - -#int_release_job: -# script: -# - "cd top_agricola/core" -# - "./generate_ci_makefile.py" -# - "make -f Makefile_ci.gen all" -# - "cd ci" -# - "./deploy_release.py -t rc" -# stage: deploy -# only: -# - /^release/.*$/ -# except: -# - tags - -#ext_release_job: -# script: -# - "cd top_agricola/core" -# - "./generate_ci_makefile.py" -# - "make -f Makefile_ci.gen all" -# - "cd ci" -# - "./deploy_release.py -t r" -# stage: deploy -# only: -# - /^release/174_AG.*$/ -# except: -# - branches - +deploy_job: + stage: deploy + script: + - "source/scripts/release_number.py" + - "make deploy BOARD=stm32f4-discovery" + artifacts: + paths: + - ./*.xz + only: + - tags diff --git a/Makefile b/Makefile index 9b4cd48..6f18835 100755 --- a/Makefile +++ b/Makefile @@ -2,11 +2,20 @@ include config/make/rules.mk APP ?= engine_control +# version numbering deployed by ci deploy script - no necessary for local build +ifdef SW_MAJOR +VERSION := -$(SW_MAJOR).$(SW_MINOR).$(CI_BUILD_ID) +else +VERSION := +endif MAINFILE = $(EXE_DIR)/$(APP)$(ELF_EXT) BINFILE = $(EXE_DIR)/$(APP)$(BIN_EXT) HEXFILE = $(EXE_DIR)/$(APP)$(HEX_EXT) SIZEFILE = $(SIZE_DIR)/$(APP)$(SIZE_EXT) MAP_FILE = $(MAP_DIR)/$(APP)$(MAP_EXT) + +DEPLOY_PACKET = $(APP)-$(ARCH)-$(BOARD)$(VERSION)$(DBG_EXT).tar.xz + INCLUDES += $(SRC_DIR) SOURCES := $(wildcard $(SRC_DIR)/*.c) @@ -21,6 +30,9 @@ SOURCES += $(foreach folder, $(SUB_FOLDER), $(wildcard $(ROOT_DIR)/$(folder)/*.c all: $(MAINFILE) +deploy: all + tar cvJf $(DEPLOY_PACKET) -C $(EXE_DIR) . + $(MAINFILE): $(OBJECTS) @$(MKDIR) $(EXE_DIR) @$(MKDIR) $(MAP_DIR) diff --git a/source/application/include/version.h b/source/application/include/version.h new file mode 100644 index 0000000..d351bc1 --- /dev/null +++ b/source/application/include/version.h @@ -0,0 +1,9 @@ +/* Release number include file */ + +#ifndef VERSION_H +#define VERSION_H + +#define MAJOR_VERSION "unknown" +#define MINOR_VERSION "unknown" +#define BUILD_NUMBER "unknown" +#endif /* VERSION_H */ diff --git a/source/application/shell_commands.c b/source/application/shell_commands.c index ed5d2d8..04f627b 100644 --- a/source/application/shell_commands.c +++ b/source/application/shell_commands.c @@ -11,6 +11,7 @@ #include "driver.h" #include "shell.h" #include "drive_ctrl.h" +#include "version.h" static void *drive_turn_right_cb(const char *param); static void *drive_turn_left_cb(const char *param); @@ -19,6 +20,13 @@ static void *drive_retard_cb(const char *param); static void *drive_halt_cb(const char *param); static void *drive_forward_cb(const char *param); static void *drive_backward_cb(const char *param); +static void *app_version(const char *param); + +static struct command drive_forward = { + .command = "version", + .description = "Get application version.", + .command_callback = app_version, +}; static struct command drive_forward = { .command = "f", @@ -150,3 +158,18 @@ static void *drive_backward_cb(const char *param) return NULL; } + +static void *app_version(const char *param) +{ +#if 0 + char *greeter = "engine_control version: "; + + drv_write(shell_object.shell_device, greeter, strlen(greeter)); + drv_write(shell_object.shell_device, MAJOR_VERSION, strlen(MAJOR_VERSION)); + drv_write(shell_object.shell_device, ".", 1); + drv_write(shell_object.shell_device, MINOR_VERSION, strlen(MINOR_VERSION)); + drv_write(shell_object.shell_device, ".", 1); + drv_write(shell_object.shell_device, BUILD_NUMBER, strlen(BUILD_NUMBER)); +#endif + return NULL; +} diff --git a/source/scripts/release_number.py b/source/scripts/release_number.py new file mode 100755 index 0000000..af01f6f --- /dev/null +++ b/source/scripts/release_number.py @@ -0,0 +1,43 @@ +#!/usr/bin/python2 +from sys import argv, exit +from getopt import getopt +from re import match, sub +import os + +def get_current_numbers(): + config = {} + if os.environ.has_key("SW_MAJOR"): + config["sw_major"] = os.environ["SW_MAJOR"] + if os.environ.has_key("SW_MINOR"): + config["sw_minor"] = os.environ["SW_MINOR"] + if os.environ.has_key("CI_BUILD_ID"): + config["build_id"] = os.environ["CI_BUILD_ID"] + return config + +def generate_include(numbers): + f = open("source/application/include/version.h", "w") + f.write("/* Release number include file */\n\n") + f.write("#ifndef VERSION_H\n") + f.write("#define VERSION_H\n\n") + if numbers.has_key("sw_major"): + f.write("#define MAJOR_VERSION\t\"" + numbers["sw_major"] + "\"\n") + else: + f.write("#define MAJOR_VERSION\t\"unknown\"\n") + if numbers.has_key("sw_minor"): + f.write("#define MINOR_VERSION\t\"" + numbers["sw_minor"] + "\"\n") + else: + f.write("#define MINOR_VERSION\t\"unknown\"\n") + if numbers.has_key("build_id"): + f.write("#define BUILD_NUMBER\t\"" + numbers["build_id"] + "\"\n") + else: + f.write("#define BUILD_NUMBER\t\"unknown\"\n") + f.write("\n#endif /* VERSION_H */\n") + f.close() + +def main(argv): + numbers = get_current_numbers() + generate_include(numbers) + +if __name__ == "__main__": + main(argv[1:]) +