-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathprebuild_hook.py
More file actions
37 lines (28 loc) · 1.06 KB
/
prebuild_hook.py
File metadata and controls
37 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Import("env")
from datetime import datetime
import hashlib
major_version = 0
minor_version = 7
patch_version = 6
def generate_build_id():
# Get current timestamp
timestamp = datetime.now().strftime("%Y%m%d")
env_name = env["PIOENV"]
# Create version string
version = f"{major_version}.{minor_version}.{patch_version}"
# Combine version and timestamp for hashing
content_to_hash = f"{env_name}_{version}_{timestamp}"
# Create a hash of timestamp for shorter unique ID
hash_object = hashlib.md5(content_to_hash.encode())
build_hash = hash_object.hexdigest()[:8]
# Combine timestamp and hash
build_id = f"{build_hash}"
return build_id
# Add build ID to environment
hw_type = env["PIOENV"]
build_id = generate_build_id()
env.Append(BUILD_FLAGS=[f'-D HW_TYPE=\\"{hw_type}\\"'])
env.Append(BUILD_FLAGS=[f'-D BUILD_ID=\\"{build_id}\\"'])
env.Append(BUILD_FLAGS=[f'-D VERSION_MAJOR={major_version}'])
env.Append(BUILD_FLAGS=[f'-D VERSION_MINOR={minor_version}'])
env.Append(BUILD_FLAGS=[f'-D VERSION_PATCH={patch_version}'])