Skip to content

Commit

Permalink
Don't use xxd to objectify files.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed Oct 22, 2023
1 parent 8fb7860 commit 6a00653
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions build/_objectify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
from functools import partial

if len(sys.argv) != 3:
sys.exit("Usage: %s <file> <symbol>" % sys.argv[0])
filename = sys.argv[1]
symbol = sys.argv[2]

print("const uint8_t " + symbol + "[] = {")
n = 0
with open(filename, "rb") as in_file:
for c in iter(partial(in_file.read, 1), b""):
print("0x%02X," % ord(c), end="")
n += 1
if n % 16 == 0:
print()
print("};")

print("const size_t " + symbol + "_len = sizeof(" + symbol + ");")
4 changes: 2 additions & 2 deletions build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
def objectify(self, name, src: Target, symbol):
normalrule(
replaces=self,
ins=[src],
ins=["build/_objectify.py", src],
outs=[basename(filenameof(src)) + ".h"],
commands=["xxd -i -n " + symbol + " {ins} > {outs}"],
commands=["$(PYTHON) {ins[0]} {ins[1]} " + symbol + " > {outs}"],
label="OBJECTIFY",
)

Expand Down

0 comments on commit 6a00653

Please sign in to comment.