Skip to content

Commit c823e0d

Browse files
authored
Merge pull request #1202 from gusthoff/topic/infrastructure/sphinx/structure/20250329/gnatchop_switches
Sphinx: pass user-defined GNAT switches to gnatchop
2 parents aa1a1df + e429cc2 commit c823e0d

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

frontend/py_modules/code_projects/extract_projects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def expand_source_files():
270270
if block.manual_chop:
271271
source_files = manual_chop(split)
272272
else:
273-
source_files = real_gnatchop(split)
273+
source_files = real_gnatchop(split, block.compiler_switches)
274274

275275
if len(source_files) == 0:
276276
print_error(loc, "Failed to chop example, skipping\n")

frontend/sphinx/widget/chop.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import shutil
66
import subprocess
77
import tempfile
8-
from typing import List
8+
from typing import List, Optional
99

1010
from .resource import Resource
1111

@@ -93,7 +93,7 @@ def to_base_filename(g):
9393
return results
9494

9595

96-
def real_gnatchop(lines: List[str]) -> List[Resource]:
96+
def real_gnatchop(lines: List[str], compiler_switches: Optional[dict] = None) -> List[Resource]:
9797
"""Uses gnatchop to chop the text into files
9898
9999
Args:
@@ -114,7 +114,15 @@ def real_gnatchop(lines: List[str]) -> List[Resource]:
114114
f.write('\n'.join(lines))
115115

116116
# run gnatchop on temp file
117-
cmd = ['gnatchop', gnatchop_file]
117+
if compiler_switches is None:
118+
cmd = ['gnatchop', gnatchop_file]
119+
else:
120+
cmd = ['gnatchop']
121+
for sw in compiler_switches:
122+
# gnatchop only accepts `-gnatXXX` switches
123+
if "gnat" in sw:
124+
cmd.append(sw)
125+
cmd.append(gnatchop_file)
118126
output = subprocess.check_output(cmd, cwd=wd)
119127
files = [os.path.join(wd, f.decode("utf-8").strip()) for f in output.splitlines()
120128
if not f.startswith(b'splitting ')]

frontend/sphinx/widget/widget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from itertools import count
22
import re
3-
from typing import List, Match, Dict
3+
from typing import List, Match, Dict, Optional
44

55
from .button import Button
66
from .chop import manual_chop, cheapo_gnatchop, real_gnatchop, ChopStrategy
@@ -381,7 +381,7 @@ def parseContent(self, content: List[str]):
381381
elif self.__chop_strategy is ChopStrategy.CHEAPO:
382382
self.__files = cheapo_gnatchop(content)
383383
elif self.__chop_strategy is ChopStrategy.REAL:
384-
self.__files = real_gnatchop(content)
384+
self.__files = real_gnatchop(content, self.switches['Compiler'])
385385
else:
386386
raise ChopException('No chop strategy defined')
387387

0 commit comments

Comments
 (0)