summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-03-13 14:14:17 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-03-20 12:33:36 +0000
commitd1537e033f2fee06590fdc8df08272a7f91bdb04 (patch)
treeb8917ec576724c0e021abc87bd4081e1f25beeac /utils
parent9e4c17075c0c881a61190f54bc5aec4e2654d015 (diff)
build: conv_gen.py: ensure parent dirs of written files exist
Previously, this would fail when generating to $builddir if that subtree did not exist yet in $builddir. Change-Id: Ia4fba96dcf74a25cf3e515eb3e4f970e0c3cdd54
Diffstat (limited to 'utils')
-rw-r--r--utils/conv_gen.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/utils/conv_gen.py b/utils/conv_gen.py
index 1ffeb3fc..0cdba756 100644
--- a/utils/conv_gen.py
+++ b/utils/conv_gen.py
@@ -306,9 +306,15 @@ def print_shared(fi, shared_polys):
code = ConvolutionalCode(0, polys, name = name)
code.print_state_and_output(fi)
+def open_for_writing(parent_dir, base_name):
+ path = os.path.join(parent_dir, base_name)
+ if not os.path.isdir(parent_dir):
+ os.makedirs(parent_dir)
+ return open(path, 'w')
+
def generate_codes(codes, path, prefix, name):
# Open a new file for writing
- f = open(os.path.join(path, name), 'w')
+ f = open_for_writing(path, name)
f.write(mod_license + "\n")
f.write("#include <stdint.h>\n")
f.write("#include <osmocom/core/conv.h>\n\n")
@@ -335,7 +341,7 @@ def generate_codes(codes, path, prefix, name):
def generate_vectors(codes, path, prefix, name, inc = None):
# Open a new file for writing
- f = open(os.path.join(path, name), 'w')
+ f = open_for_writing(path, name)
f.write(mod_license + "\n")
# Print includes
@@ -363,7 +369,7 @@ def generate_vectors(codes, path, prefix, name, inc = None):
def generate_header(codes, path, prefix, name, description = None):
# Open a new file for writing
- f = open(os.path.join(path, name), 'w')
+ f = open_for_writing(path, name)
# Print license and includes
f.write(mod_license + "\n")