Calculate md5 of all include paths in compile_sources() and remove calculation from <toolchaon>get_compile_options(), thus significantly reduce repetitive md5 calculations

Unify handling of the include response file in mbedToolchain::get_inc_file()
Sanitize obsolete no-longer needed methods
Mihail Stoyanov 2016-05-06 13:06:48 +01:00 committed by Mihail Stoyanov
parent f01e1363d1
commit 7e11174a00
4 changed files with 50 additions and 72 deletions

View File

@ -30,6 +30,7 @@ from multiprocessing import Pool, cpu_count
from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path
from tools.settings import BUILD_OPTIONS, MBED_ORG_USER from tools.settings import BUILD_OPTIONS, MBED_ORG_USER
import tools.hooks as hooks import tools.hooks as hooks
from hashlib import md5
#Disables multiprocessing if set to higher number than the host machine CPUs #Disables multiprocessing if set to higher number than the host machine CPUs
@ -478,18 +479,35 @@ class mbedToolchain:
mkdir(obj_dir) mkdir(obj_dir)
return join(obj_dir, name + '.o') return join(obj_dir, name + '.o')
def get_inc_file(self, includes):
include_file = join(self.temp_dir, "includes_%s.txt" % self.inc_md5)
if not exists(include_file):
with open(include_file, "wb") as f:
cmd_list = []
for c in includes:
if c:
cmd_list.append(('-I%s' % c).replace("\\", "/"))
string = " ".join(cmd_list)
f.write(string)
return include_file
def compile_sources(self, resources, build_path, inc_dirs=None): def compile_sources(self, resources, build_path, inc_dirs=None):
# Web IDE progress bar for project build # Web IDE progress bar for project build
files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
self.to_be_compiled = len(files_to_compile) self.to_be_compiled = len(files_to_compile)
self.compiled = 0 self.compiled = 0
self.temp_dir = build_path
inc_paths = resources.inc_dirs inc_paths = resources.inc_dirs
if inc_dirs is not None: if inc_dirs is not None:
inc_paths.extend(inc_dirs) inc_paths.extend(inc_dirs)
# De-duplicate include paths and sort for consistency # De-duplicate include paths
inc_paths = set(inc_paths)
# Sort include paths for consistency
inc_paths = sorted(set(inc_paths)) inc_paths = sorted(set(inc_paths))
# Unique id of all include paths
self.inc_md5 = md5(' '.join(inc_paths)).hexdigest()
# Where to store response files
self.temp_dir = build_path
objects = [] objects = []
queue = [] queue = []

View File

@ -16,7 +16,6 @@ limitations under the License.
""" """
import re import re
from os.path import join, dirname, splitext, basename, exists from os.path import join, dirname, splitext, basename, exists
from hashlib import md5
from tools.toolchains import mbedToolchain from tools.toolchains import mbedToolchain
from tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB, GOANNA_PATH from tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB, GOANNA_PATH
@ -79,11 +78,6 @@ class ARM(mbedToolchain):
self.ar = join(ARM_BIN, "armar") self.ar = join(ARM_BIN, "armar")
self.elf2bin = join(ARM_BIN, "fromelf") self.elf2bin = join(ARM_BIN, "fromelf")
def remove_option(self, option):
for tool in [self.asm, self.cc, self.cppc]:
if option in tool:
tool.remove(option)
def parse_dependencies(self, dep_path): def parse_dependencies(self, dep_path):
dependencies = [] dependencies = []
for line in open(dep_path).readlines(): for line in open(dep_path).readlines():
@ -113,25 +107,13 @@ class ARM(mbedToolchain):
match.group('message') match.group('message')
) )
def get_dep_opt(self, dep_path): def get_dep_option(self, object):
base, _ = splitext(object)
dep_path = base + '.d'
return ["--depend", dep_path] return ["--depend", dep_path]
def get_compile_options(self, defines, includes): def get_compile_options(self, defines, includes):
cmd = [] return ['-D%s' % d for d in defines] + ['--via', self.get_inc_file(includes)]
sum = md5(' '.join(includes)).hexdigest()
options_file = join(self.temp_dir, "options_%s.txt" % sum)
if not exists(options_file):
with open(options_file, "wb") as f:
cmd_list = ['-D%s' % d for d in defines]
for c in includes:
if c:
cmd_list.append(('-I%s' % c) if not c.startswith('-') else c)
string = " ".join(cmd_list).replace("\\", "/")
f.write(string)
cmd.extend(['--via', options_file])
return cmd
@hook_tool @hook_tool
def assemble(self, source, object, includes): def assemble(self, source, object, includes):
@ -158,9 +140,7 @@ class ARM(mbedToolchain):
# Build compile command # Build compile command
cmd = cc + self.get_compile_options(self.get_symbols(), includes) cmd = cc + self.get_compile_options(self.get_symbols(), includes)
base, _ = splitext(object) cmd.extend(self.get_dep_option(object))
dep_path = base + '.d'
cmd.extend(self.get_dep_opt(dep_path))
cmd.extend(["-o", object, source]) cmd.extend(["-o", object, source])

View File

@ -16,7 +16,6 @@ limitations under the License.
""" """
import re import re
from os.path import join, basename, splitext, dirname, exists from os.path import join, basename, splitext, dirname, exists
from hashlib import md5
from tools.toolchains import mbedToolchain from tools.toolchains import mbedToolchain
from tools.settings import GCC_ARM_PATH, GCC_CR_PATH from tools.settings import GCC_ARM_PATH, GCC_CR_PATH
@ -69,7 +68,7 @@ class GCC(mbedToolchain):
"-Wno-unused-parameter", "-Wno-missing-field-initializers", "-Wno-unused-parameter", "-Wno-missing-field-initializers",
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin", "-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
"-ffunction-sections", "-fdata-sections", "-ffunction-sections", "-fdata-sections",
"-MMD", "-fno-delete-null-pointer-checks", "-fomit-frame-pointer" "-fno-delete-null-pointer-checks", "-fomit-frame-pointer"
] + self.cpu ] + self.cpu
if "save-asm" in self.options: if "save-asm" in self.options:
@ -162,22 +161,13 @@ class GCC(mbedToolchain):
message + match.group('message') message + match.group('message')
) )
def get_dep_option(self, object):
base, _ = splitext(object)
dep_path = base + '.d'
return ["-MD", "-MF", dep_path]
def get_compile_options(self, defines, includes): def get_compile_options(self, defines, includes):
cmd = [] return ['-D%s' % d for d in defines] + ['@%s' % self.get_inc_file(includes)]
sum = md5(' '.join(includes)).hexdigest()
options_file = join(self.temp_dir, "options_%s.txt" % sum)
if not exists(options_file):
with open(options_file, "wb") as f:
cmd_list = ['-D%s' % d for d in defines]
for c in includes:
if c:
cmd_list.append(('-I%s' % c) if not c.startswith('-') else c)
string = " ".join(cmd_list).replace("\\", "/")
f.write(string)
cmd.extend(['@%s' % options_file])
return cmd
@hook_tool @hook_tool
def assemble(self, source, object, includes): def assemble(self, source, object, includes):
@ -193,8 +183,12 @@ class GCC(mbedToolchain):
@hook_tool @hook_tool
def compile(self, cc, source, object, includes): def compile(self, cc, source, object, includes):
# Build compile command # Build compile command
cmd = cc + self.get_compile_options(self.get_symbols(), includes) + ["-o", object, source] cmd = cc + self.get_compile_options(self.get_symbols(), includes)
cmd.extend(self.get_dep_option(object))
cmd.extend(["-o", object, source])
# Call cmdline hook # Call cmdline hook
cmd = self.hook.get_cmdline_compiler(cmd) cmd = self.hook.get_cmdline_compiler(cmd)

View File

@ -17,7 +17,6 @@ limitations under the License.
import re import re
from os import remove from os import remove
from os.path import join, exists, dirname, splitext, exists from os.path import join, exists, dirname, splitext, exists
from hashlib import md5
from tools.toolchains import mbedToolchain from tools.toolchains import mbedToolchain
from tools.settings import IAR_PATH from tools.settings import IAR_PATH
@ -73,6 +72,10 @@ class IAR(mbedToolchain):
self.ar = join(IAR_BIN, "iarchive") self.ar = join(IAR_BIN, "iarchive")
self.elf2bin = join(IAR_BIN, "ielftool") self.elf2bin = join(IAR_BIN, "ielftool")
def parse_dependencies(self, dep_path):
return [path.strip() for path in open(dep_path).readlines()
if (path and not path.isspace())]
def parse_output(self, output): def parse_output(self, output):
for line in output.splitlines(): for line in output.splitlines():
match = IAR.DIAGNOSTIC_PATTERN.match(line) match = IAR.DIAGNOSTIC_PATTERN.match(line)
@ -94,32 +97,17 @@ class IAR(mbedToolchain):
match.group('message') match.group('message')
) )
def get_dep_opt(self, dep_path): def get_dep_option(self, object):
base, _ = splitext(object)
dep_path = base + '.d'
return ["--dependencies", dep_path] return ["--dependencies", dep_path]
def cc_extra(self, base): def cc_extra(self, object):
base, _ = splitext(object)
return ["-l", base + '.s'] return ["-l", base + '.s']
def parse_dependencies(self, dep_path):
return [path.strip() for path in open(dep_path).readlines()
if (path and not path.isspace())]
def get_compile_options(self, defines, includes): def get_compile_options(self, defines, includes):
cmd = [] return ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]
sum = md5(' '.join(includes)).hexdigest()
options_file = join(self.temp_dir, "options_%s.txt" % sum)
if not exists(options_file):
with open(options_file, "wb") as f:
cmd_list = ['-D%s' % d for d in defines]
for c in includes:
if c:
cmd_list.append(('-I%s' % c) if not c.startswith('-') else c)
string = " ".join(cmd_list).replace("\\", "/")
f.write(string)
cmd.extend(['-f', options_file])
return cmd
@hook_tool @hook_tool
def assemble(self, source, object, includes): def assemble(self, source, object, includes):
@ -137,11 +125,9 @@ class IAR(mbedToolchain):
# Build compile command # Build compile command
cmd = cc + self.get_compile_options(self.get_symbols(), includes) cmd = cc + self.get_compile_options(self.get_symbols(), includes)
base, _ = splitext(object) cmd.extend(self.get_dep_option(object))
dep_path = base + '.d'
cmd.extend(self.get_dep_opt(dep_path))
cmd.extend(self.cc_extra(base)) cmd.extend(self.cc_extra(object))
cmd.extend(["-o", object, source]) cmd.extend(["-o", object, source])