-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from 4ms/git-version
Generate firmware update manifest json file and git metadata
- Loading branch information
Showing
15 changed files
with
430 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
set(CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}) | ||
if (NOT DEFINED pre_configure_dir) | ||
set(pre_configure_dir ${CMAKE_CURRENT_LIST_DIR}) | ||
endif () | ||
|
||
if (NOT DEFINED post_configure_dir) | ||
set(post_configure_dir ${CMAKE_CURRENT_BINARY_DIR}/checkgit) | ||
endif () | ||
|
||
set(pre_configure_file ${pre_configure_dir}/git_version.cpp.in) | ||
set(post_configure_file ${post_configure_dir}/git_version.cpp) | ||
|
||
function(CheckGitWrite git_hash) | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/git-state.txt ${git_hash}) | ||
endfunction() | ||
|
||
function(CheckGitRead git_hash) | ||
if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/git-state.txt) | ||
file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/git-state.txt CONTENT) | ||
LIST(GET CONTENT 0 var) | ||
|
||
set(${git_hash} ${var} PARENT_SCOPE) | ||
endif () | ||
endfunction() | ||
|
||
function(CheckGitVersion) | ||
# Get the latest abbreviated commit hash of the working branch | ||
execute_process( | ||
COMMAND bash -c "git log -1 --format=%h" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | ||
OUTPUT_VARIABLE GIT_HASH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
execute_process( | ||
COMMAND bash -c "git log -1 --format=%ci" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | ||
OUTPUT_VARIABLE GIT_COMMIT_TIME | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
execute_process( | ||
COMMAND bash -c "git describe --match firmware\\* --tags" | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | ||
OUTPUT_VARIABLE GIT_FIRMWARE_VERSION_TAG | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
execute_process( | ||
COMMAND echo "Git hash: ${GIT_HASH}. Commit time: ${GIT_COMMIT_TIME}. Tag: ${GIT_FIRMWARE_VERSION_TAG}" | ||
) | ||
|
||
set(GIT_FIRMWARE_VERSION_TAG ${GIT_FIRMWARE_VERSION_TAG} PARENT_SCOPE) | ||
|
||
CheckGitRead(GIT_HASH_CACHE) | ||
if (NOT EXISTS ${post_configure_dir}) | ||
file(MAKE_DIRECTORY ${post_configure_dir}) | ||
endif () | ||
|
||
if (NOT EXISTS ${post_configure_dir}/git_version.h) | ||
file(COPY ${pre_configure_dir}/git_version.h DESTINATION ${post_configure_dir}) | ||
endif() | ||
|
||
if (NOT DEFINED GIT_HASH_CACHE) | ||
set(GIT_HASH_CACHE "INVALID") | ||
endif () | ||
|
||
# Only update the git_version.cpp if the hash has changed. This will | ||
# prevent us from rebuilding the project more than we need to. | ||
if (NOT ${GIT_HASH} STREQUAL "${GIT_HASH_CACHE}" OR NOT EXISTS ${post_configure_file}) | ||
# Set the GIT_HASH_CACHE variable so the next build won't have | ||
# to regenerate the source file. | ||
CheckGitWrite(${GIT_HASH}) | ||
|
||
configure_file(${pre_configure_file} ${post_configure_file} @ONLY) | ||
endif () | ||
|
||
endfunction() | ||
|
||
function(CheckGitSetup) | ||
|
||
add_custom_target(AlwaysCheckGit COMMAND ${CMAKE_COMMAND} | ||
-DRUN_CHECK_GIT_VERSION=1 | ||
-Dpre_configure_dir=${pre_configure_dir} | ||
-Dpost_configure_file=${post_configure_dir} | ||
-DGIT_HASH_CACHE=${GIT_HASH_CACHE} | ||
-P ${CURRENT_LIST_DIR}/CheckGit.cmake | ||
BYPRODUCTS ${post_configure_file} | ||
) | ||
|
||
CheckGitVersion() | ||
set(GIT_FIRMWARE_VERSION_TAG ${GIT_FIRMWARE_VERSION_TAG} PARENT_SCOPE) | ||
endfunction() | ||
|
||
# This is used to run this function from an external cmake process. | ||
if (RUN_CHECK_GIT_VERSION) | ||
CheckGitVersion() | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <string_view> | ||
|
||
std::string_view GIT_HASH = "@GIT_HASH@"; | ||
std::string_view GIT_COMMIT_TIME = "@GIT_COMMIT_TIME@"; | ||
std::string_view GIT_FIRMWARE_VERSION_TAG = "@GIT_FIRMWARE_VERSION_TAG@"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
#include <string_view> | ||
|
||
extern std::string_view GIT_HASH; | ||
extern std::string_view GIT_COMMIT_TIME; | ||
extern std::string_view GIT_FIRMWARE_VERSION_TAG; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import logging | ||
import json | ||
import os | ||
|
||
ManifestFormatVersion = 1 | ||
|
||
def process_file(filename, imagetype, version): | ||
entry = {} | ||
entry["type"] = imagetype | ||
entry["filename"] = os.path.basename(filename) | ||
entry["filesize"] = os.stat(filename).st_size | ||
|
||
#TODO md5 | ||
entry["md5"] = "123" | ||
|
||
entry["version"] = {} | ||
v = version.split(".") | ||
if len(v) > 0: | ||
entry["version"]["major"] = v[0] | ||
if len(v) > 1: | ||
entry["version"]["minor"] = v[1] | ||
if len(v) > 2: | ||
entry["version"]["revision"] = v[2] | ||
|
||
return entry | ||
|
||
def parse_file_version(version): | ||
""" Convert a string like: firmware-v0.6.2-278-g52dfd038 | ||
Or: v1.2.3 | ||
Or: 2.1.5 | ||
Into: 0.6.2 | ||
""" | ||
vsplit = version.split("-") | ||
if len(vsplit) > 1: | ||
v = vsplit[1] | ||
else: | ||
v = vsplit[0] | ||
|
||
v = v.strip("v") | ||
return v | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser("Generate firmware update manifest json file") | ||
parser.add_argument("--app", dest="app_file", help="Input application uimg file") | ||
parser.add_argument("--version", dest="version", help="Version string e.g. \"1.2.3\"") | ||
parser.add_argument("out_file", help="Output json file") | ||
parser.add_argument("-v", dest="verbose", help="Verbose logging", action="store_true") | ||
args = parser.parse_args() | ||
|
||
if args.verbose: | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
j = {'version': ManifestFormatVersion} | ||
|
||
version = parse_file_version(args.version) | ||
|
||
j["files"] = [] | ||
j["files"].append(process_file(args.app_file, "app", version)) | ||
|
||
with open(args.out_file, "w+") as out_file: | ||
data_json = json.dumps(j, indent=4) | ||
out_file.write(data_json) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#include "gui/helpers/lv_helpers.hh" | ||
#include "gui/pages/base.hh" | ||
#include "gui/pages/page_list.hh" | ||
#include "gui/slsexport/meta5/ui.h" | ||
#include "gui/styles.hh" | ||
|
||
namespace MetaModule | ||
{ | ||
|
||
struct HardwareTestTab { | ||
|
||
void prepare_focus(lv_group_t *group) { | ||
this->group = group; | ||
} | ||
|
||
void update() { | ||
} | ||
|
||
private: | ||
lv_group_t *group = nullptr; | ||
}; | ||
} // namespace MetaModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#include "gui/helpers/lv_helpers.hh" | ||
#include "gui/pages/base.hh" | ||
#include "gui/pages/page_list.hh" | ||
#include "gui/slsexport/meta5/ui.h" | ||
#include "gui/styles.hh" | ||
|
||
namespace MetaModule | ||
{ | ||
|
||
struct PrefsTab { | ||
|
||
void prepare_focus(lv_group_t *group) { | ||
this->group = group; | ||
} | ||
|
||
void update() { | ||
} | ||
|
||
private: | ||
lv_group_t *group = nullptr; | ||
}; | ||
} // namespace MetaModule |
Oops, something went wrong.