Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version handling #59

Merged
merged 2 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ $(PROGRAM).bin: $(PROGRAM).elf
$(PROGRAM).elf: $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^

# The '|' denotes Include/version.h as an order-only prerequisite, it will not
# force a rebuild the file is updated, but makes sure that the file exists
# before we start generating the object files.
$(OBJS): | Include/version.h

# Dummy target to force re-generation of version.h eacn run.
#
# If a rule has no prerequisites or recipe, and the target of the rule is a
# nonexistent file, then make imagines this target to have been updated
# whenever its rule is run. This implies that all targets depending on this one
# will always have their recipe run.
FORCE:

Include/version.h: FORCE
python3 tools/build/generateVersionHeader.py --crazyflie-base $(abspath .) --output $@

clean:
rm -f $(PROGRAM).bin $(PROGRAM).elf $(OBJS)

Expand Down
2 changes: 2 additions & 0 deletions interface/syslink.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ void syslinkReset();
#define SYSLINK_OW_READ 0x22
#define SYSLINK_OW_WRITE 0x23

#define SYSLINK_SYS_NRF_VERSION 0x30

#endif
15 changes: 15 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "systick.h"
#include "nrf_sdm.h"
#include "nrf_soc.h"
#include "version.h"

#include "memory.h"
#include "ownet.h"
Expand Down Expand Up @@ -338,7 +339,21 @@ void mainloop()
// Send the P2P packet immediately without buffer
esbSendP2PPacket(slRxPacket.data[0],&slRxPacket.data[1],slRxPacket.length-1);
break;
case SYSLINK_SYS_NRF_VERSION:{
size_t len = strlen(V_STAG);
slTxPacket.type = SYSLINK_SYS_NRF_VERSION;

memcpy(&slTxPacket.data[0], V_STAG, len);

if (V_MODIFIED) {
slTxPacket.data[len] = '*';
len += 1;
}

slTxPacket.data[len] = '\0';
slTxPacket.length = len + 1;
syslinkSend(&slTxPacket);
} break;
}
}

Expand Down
95 changes: 95 additions & 0 deletions tools/build/generateVersionHeader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python

import argparse
import os
import subprocess

version = {}


def extract_information_from_git(base):
print(f"{base}")
revision = (
subprocess.check_output(["git", "-C", base, "rev-parse", "HEAD"])
.decode("utf-8")
.strip()
)

version["revision"] = revision[0:12]
version["irevision0"] = "0x" + revision[0:8]
version["irevision1"] = "0x" + revision[8:12]
version["productionRelease"] = "false"

try:
identify = subprocess.check_output(
["git", "-C", base, "describe", "--abbrev=12", "--tags", "HEAD"]
).decode("utf-8")
identify = identify.split("-")

if len(identify) > 2:
version["local_revision"] = identify[len(identify) - 2]
else:
version["local_revision"] = "0"

version["tag"] = identify[0]
for x in range(1, len(identify) - 2):
version["tag"] += "-"
version["tag"] += identify[x]
except subprocess.CalledProcessError:
# We are maybe running from a shallow tree
version["local_revision"] = "0"
version["tag"] = "NA"

version["tag"] = version["tag"].strip()

if version["local_revision"] != "0":
version["tag"] = version["tag"] + " +" + version["local_revision"]

branch = (
subprocess.check_output(
["git", "-C", base, "rev-parse", "--abbrev-ref", "HEAD"]
)
.decode("utf-8")
.strip()
)
version["branch"] = branch

subprocess.call(["git", "-C", base, "update-index", "-q", "--refresh"])
changes = (
subprocess.check_output(
["git", "-C", base, "diff-index", "--name-only", "HEAD", "--"]
)
.decode("utf-8")
.strip()
)
if len(changes):
version["modified"] = "true"
else:
version["modified"] = "false"


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--crazyflie-base",
help="base folder of the crazyflie firmware",
action="store",
default="./",
)
parser.add_argument(
"--output", help="name of output header", action="store", default="Include/version.h"
)
args = parser.parse_args()

extract_information_from_git(args.crazyflie_base)

header = (
"#pragma once\n\n"
f'#define V_SLOCAL_REVISION "{version["local_revision"]}"\n'
f'#define V_SREVISION "{version["revision"]}"\n'
f'#define V_STAG "{version["tag"]}"\n'
f'#define V_MODIFIED {version["modified"]}\n'
)

with open(os.path.join(args.crazyflie_base, args.output), "w") as f:
f.write(header)