Skip to content

Commit a0ca7eb

Browse files
authored
Merge pull request #3092 from bridadan/parallelize-iar-build-system
[tools + tests] Adding parallelized build option for iar and uvision exporters
2 parents 9cd14e2 + d192491 commit a0ca7eb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

tools/export/iar/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from tools.export.exporters import Exporter, FailedBuildException
1111
import json
1212
from tools.export.cmsis import DeviceCMSIS
13+
from multiprocessing import cpu_count
1314

1415
class IAR(Exporter):
1516
NAME = 'iar'
@@ -101,7 +102,7 @@ def generate(self):
101102
flags['c_flags'].remove('--vla')
102103
if '--no_static_destruction' in flags['c_flags']:
103104
flags['c_flags'].remove('--no_static_destruction')
104-
#Optimizations
105+
#Optimizations
105106
if '-Oh' in flags['c_flags']:
106107
flags['c_flags'].remove('-Oh')
107108
ctx = {
@@ -135,6 +136,17 @@ def build(self):
135136
raise Exception("IarBuild.exe not found. Add to path.")
136137

137138
cmd = [iar_exe, proj_file, '-build', self.project_name]
139+
140+
# IAR does not support a '0' option to automatically use all
141+
# available CPUs, so we use Python's multiprocessing library
142+
# to detect the number of CPUs available
143+
cpus_available = cpu_count()
144+
jobs = cpus_available if cpus_available else None
145+
146+
# Only add the parallel flag if we're using more than one CPU
147+
if jobs:
148+
cmd += ['-parallel', str(jobs)]
149+
138150
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
139151
num_errors = 0
140152
#Parse the output for printing and errors

0 commit comments

Comments
 (0)