Skip to content

Commit

Permalink
use tempfile for asn1c_cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbusch committed Nov 26, 2024
1 parent c375b4e commit 787e941
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions utils/codegen/asn1ToC/asn1ToC.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ def main():
shutil.copy(f, container_input_dir)

# run asn1c docker container to generate header and source files
asn1c_cmd_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "asn1c.sh")
with open(asn1c_cmd_file, "w") as f:
asn1c_cmd_file = tempfile.NamedTemporaryFile(delete=False)
with open(asn1c_cmd_file.name, "w") as f:
f.write(f"asn1c $(find /input -name '*.asn' | sort) -fcompound-names -fprefix={args.type}_ -no-gen-BER -no-gen-XER -no-gen-JER -no-gen-OER -no-gen-example -gen-UPER")

subprocess.run(["docker", "run", "--rm", "-u", f"{os.getuid()}:{os.getgid()}", "-v", f"{container_input_dir}:/input:ro", "-v", f"{container_output_dir}:/output", "-v", f"{asn1c_cmd_file}:/asn1c.sh", args.docker_image], check=True)
os.remove(asn1c_cmd_file)
subprocess.run(["docker", "run", "--rm", "-u", f"{os.getuid()}:{os.getgid()}", "-v", f"{container_input_dir}:/input:ro", "-v", f"{container_output_dir}:/output", "-v", f"{asn1c_cmd_file.name}:/asn1c.sh", args.docker_image], check=True)
os.remove(asn1c_cmd_file.name)

# move generated header and source files to output directories
for f in glob.glob(os.path.join(container_output_dir, "*.h")):
Expand Down

0 comments on commit 787e941

Please sign in to comment.