Skip to content

Commit

Permalink
Tag installations on make install
Browse files Browse the repository at this point in the history
  • Loading branch information
bill88t committed Aug 18, 2024
1 parent 529b728 commit 2a6c0fe
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
42 changes: 42 additions & 0 deletions scripts/tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import subprocess
from os import environ
from sys import path as spath

spath.append("../source/cptoml/")
spath.append("../scripts/CircuitMPY/")
import circuitmpy
from cptoml import put

if "FSNAME" not in environ:
environ["FSNAME"] = "BERYLLIUM"
[boardpath, board, version] = circuitmpy.detect_board()

if boardpath == None:
print(
"Error: Board not found.\nMake sure it is attached and mounted before you run make"
)
exit(1)


def cmd(txt):
try:
return subprocess.check_output(txt).strip().decode("utf-8")
except subprocess.CalledProcessError as e:
return None


def get_tag() -> str:
cmd(["git", "fetch", "--tags"])
desc = cmd(["git", "describe", "--tags"])
if cmd(["git", "status", "--porcelain"]):
desc += "-dirty"
print(desc)
return desc


def write_tag(tag: str):
put("git_tag", tag, subtable="BERYLLIUM", toml=f"{boardpath}/settings.toml")


if __name__ == "__main__":
write_tag(get_tag())
43 changes: 43 additions & 0 deletions scripts/tag_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import subprocess
from os import environ
from sys import path as spath

spath.append("../source/cptoml/")
spath.append("../scripts/CircuitMPY/")
import circuitmpy
from cptoml import put

if "FSNAME" not in environ:
environ["FSNAME"] = "BERYLLIUM"
[boardpath, board, version] = circuitmpy.detect_board()

if boardpath == None:
print(
"Error: Board not found.\nMake sure it is attached and mounted before you run make"
)
exit(1)


def cmd(txt):
try:
return subprocess.check_output(txt).strip().decode("utf-8")
except subprocess.CalledProcessError as e:
return None


def get_tag() -> str:
cmd(["git", "fetch", "--tags"])
desc = cmd(["git", "describe", "--tags"])
desc += "-debug"
if cmd(["git", "status", "--porcelain"]):
desc += "-dirty"
print(desc)
return desc


def write_tag(tag: str):
put("git_tag", tag, subtable="BERYLLIUM", toml=f"{boardpath}/settings.toml")


if __name__ == "__main__":
write_tag(get_tag())
10 changes: 8 additions & 2 deletions source/makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
SHELL = bash

all: help
install: wsltest modules rootfs kernel extra drivers boot wslclean
debug: wsltest modules rootfs kernel_debug extra drivers boot wslclean
install: wsltest modules rootfs kernel tag extra drivers boot wslclean
debug: wsltest modules rootfs kernel_debug tag_debug extra drivers boot wslclean

kernel: prep clean_core comp strap_kern
kernel_debug: prep clean_core debug_comp strap_kern
Expand Down Expand Up @@ -72,3 +72,9 @@ wsltest:
@python3 ../scripts/wslmount.py
wslclean:
@python3 ../scripts/wslrmsetter.py
tag:
@echo -ne "\nTagging installation.. "
@python3 ../scripts/tag.py
tag_debug:
@echo -ne "\nTagging installation (debug).. "
@python3 ../scripts/tag_debug.py

0 comments on commit 2a6c0fe

Please sign in to comment.