diff --git a/frontend/py_modules/code_projects/extract_projects.py b/frontend/py_modules/code_projects/extract_projects.py index 9ed8540bb..cdd5ddfe0 100755 --- a/frontend/py_modules/code_projects/extract_projects.py +++ b/frontend/py_modules/code_projects/extract_projects.py @@ -270,7 +270,7 @@ def expand_source_files(): if block.manual_chop: source_files = manual_chop(split) else: - source_files = real_gnatchop(split) + source_files = real_gnatchop(split, block.compiler_switches) if len(source_files) == 0: print_error(loc, "Failed to chop example, skipping\n") diff --git a/frontend/sphinx/widget/chop.py b/frontend/sphinx/widget/chop.py index 8ee66a0d6..682b6e904 100644 --- a/frontend/sphinx/widget/chop.py +++ b/frontend/sphinx/widget/chop.py @@ -5,7 +5,7 @@ import shutil import subprocess import tempfile -from typing import List +from typing import List, Optional from .resource import Resource @@ -93,7 +93,7 @@ def to_base_filename(g): return results -def real_gnatchop(lines: List[str]) -> List[Resource]: +def real_gnatchop(lines: List[str], compiler_switches: Optional[dict] = None) -> List[Resource]: """Uses gnatchop to chop the text into files Args: @@ -114,7 +114,15 @@ def real_gnatchop(lines: List[str]) -> List[Resource]: f.write('\n'.join(lines)) # run gnatchop on temp file - cmd = ['gnatchop', gnatchop_file] + if compiler_switches is None: + cmd = ['gnatchop', gnatchop_file] + else: + cmd = ['gnatchop'] + for sw in compiler_switches: + # gnatchop only accepts `-gnatXXX` switches + if "gnat" in sw: + cmd.append(sw) + cmd.append(gnatchop_file) output = subprocess.check_output(cmd, cwd=wd) files = [os.path.join(wd, f.decode("utf-8").strip()) for f in output.splitlines() if not f.startswith(b'splitting ')] diff --git a/frontend/sphinx/widget/widget.py b/frontend/sphinx/widget/widget.py index 680eb4083..767d2b163 100644 --- a/frontend/sphinx/widget/widget.py +++ b/frontend/sphinx/widget/widget.py @@ -1,6 +1,6 @@ from itertools import count import re -from typing import List, Match, Dict +from typing import List, Match, Dict, Optional from .button import Button from .chop import manual_chop, cheapo_gnatchop, real_gnatchop, ChopStrategy @@ -381,7 +381,7 @@ def parseContent(self, content: List[str]): elif self.__chop_strategy is ChopStrategy.CHEAPO: self.__files = cheapo_gnatchop(content) elif self.__chop_strategy is ChopStrategy.REAL: - self.__files = real_gnatchop(content) + self.__files = real_gnatchop(content, self.switches['Compiler']) else: raise ChopException('No chop strategy defined')