Commit c3428df8 authored by Luke Mewburn's avatar Luke Mewburn Committed by Luke Mewburn
Browse files

asn_process: pycrate 0.8.1 fixes duplicate imports

parent 63101d24
Loading
Loading
Loading
Loading
+1 −29
Changes for testing/asn/asn_process.py: 1 added line, 29 removed lines.
Original line number Diff line number Diff line
@@ -8,10 +8,6 @@ import subprocess
import sys
from pathlib import Path

# Luke has fixed the updstream issue with multiple imports in pycrate
# https://github.com/pycrate-org/pycrate/pull/57
# but it isn't yet included in the distribution (still at 0.7.11 , Jul 2025)
# When this gets updated we may be able to use only pycrate, and drop the use of asn1c
import pycrate_asn1c.asnproc
import pycrate_asn1c.utils

@@ -88,28 +84,9 @@ def syntaxCheckASN(fileList):
    return results


duplicateObjects = {
    "102232-1/LI-PS-PDU.asn": ["CCPayload", "IRIPayload", "Location"],
    "testing/mod1.asn": ["ClashField"],
}


def fixDuplicateObjects(filename):
    stringContent = filename.read_text()
    for object in duplicateObjects[filename.as_posix()]:
        stringContent = stringContent.replace(f"{object} ::=", f"Native{object} ::=", 1)
        stringContent = stringContent.replace(
            f"SEQUENCE OF {object}", f"SEQUENCE OF Native{object}"
        )
        # stringContent = sub(f"]\\w{object}", f"] Native{object}", stringContent)

    Path("temp.asn").write_text(stringContent)
    return "temp.asn"


def compileAllTargets(compileTargets):
    """
    Attempts to compile a set of compile targets using the pycrate ASN1 tools
    Attempts to compile a set of compile targets using the pycrate ASN.1 tools

    :param compileTargets: list of compile targets, each of which is a list of filenames
    :returns: A dict of outcome against the first filename of each compile target. Return code and message are included for failures.
@@ -135,11 +112,6 @@ def compileAllTargets(compileTargets):
            pycrate_asn1c.asnproc.GLOBAL.clear()
            for filename in target:
                pFile = Path(filename)
                if pFile.as_posix() in duplicateObjects:
                    tmpFile = Path(fixDuplicateObjects(pFile))
                    fileTexts.append(tmpFile.read_text())
                    # tmpFile.unlink()
                else:
                fileTexts.append(pFile.read_text())
                fileNames.append(filename)
                logger.debug(f"  Loading {filename}")