Skip to content

Commit 4060efc

Browse files
committed
This fixes the differences between how projects and libraries are built (build_project() vs build_library()). Issue #181
1 parent a7a163b commit 4060efc

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

tools/build_api.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -300,26 +300,43 @@ def build_library(src_paths, build_path, target, toolchain_name,
300300
toolchain.info("Building library %s (%s, %s)" % (name, target.name, toolchain_name))
301301

302302
# Scan Resources
303-
resources = []
304-
for src_path in src_paths:
305-
resources.append(toolchain.scan_resources(src_path))
303+
resources = None
304+
for path in src_paths:
305+
# Scan resources
306+
resource = toolchain.scan_resources(path)
307+
308+
# Copy headers, objects and static libraries - all files needed for static lib
309+
toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
310+
toolchain.copy_files(resource.objects, build_path, rel_path=resource.base_path)
311+
toolchain.copy_files(resource.libraries, build_path, rel_path=resource.base_path)
312+
if resource.linker_script:
313+
toolchain.copy_files(resource.linker_script, build_path, rel_path=resource.base_path)
314+
315+
# Extend resources collection
316+
if not resources:
317+
resources = resource
318+
else:
319+
resources.add(resource)
320+
321+
# We need to add if necessary additional include directories
322+
if inc_dirs:
323+
if type(inc_dirs) == ListType:
324+
resources.inc_dirs.extend(inc_dirs)
325+
else:
326+
resources.inc_dirs.append(inc_dirs)
306327

307328
# Add extra include directories / files which are required by library
308329
# This files usually are not in the same directory as source files so
309330
# previous scan will not include them
310331
if inc_dirs_ext is not None:
311332
for inc_ext in inc_dirs_ext:
312-
resources.append(toolchain.scan_resources(inc_ext))
333+
resources.add(toolchain.scan_resources(inc_ext))
313334

314335
# Dependencies Include Paths
315-
dependencies_include_dir = []
316336
if dependencies_paths is not None:
317337
for path in dependencies_paths:
318338
lib_resources = toolchain.scan_resources(path)
319-
dependencies_include_dir.extend(lib_resources.inc_dirs)
320-
321-
if inc_dirs:
322-
dependencies_include_dir.extend(inc_dirs)
339+
resources.inc_dirs.extend(lib_resources.inc_dirs)
323340

324341
if archive:
325342
# Use temp path when building archive
@@ -330,25 +347,19 @@ def build_library(src_paths, build_path, target, toolchain_name,
330347

331348
# Handle configuration
332349
config = Config(target)
333-
334-
# Copy headers, objects and static libraries
335-
for resource in resources:
336-
toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
337-
toolchain.copy_files(resource.objects, build_path, rel_path=resource.base_path)
338-
toolchain.copy_files(resource.libraries, build_path, rel_path=resource.base_path)
339-
if resource.linker_script:
340-
toolchain.copy_files(resource.linker_script, build_path, rel_path=resource.base_path)
341-
config.add_config_files(resource.json_files)
342-
350+
# Update the configuration with any .json files found while scanning
351+
config.add_config_files(resources.json_files)
352+
# And add the configuration macros to the toolchain
343353
toolchain.add_macros(config.get_config_data_macros())
344354

345355
# Compile Sources
346-
objects = []
347-
for resource in resources:
348-
objects.extend(toolchain.compile_sources(resource, abspath(tmp_path), dependencies_include_dir))
356+
for path in src_paths:
357+
src = toolchain.scan_resources(path)
358+
objects = toolchain.compile_sources(src, abspath(tmp_path), resources.inc_dirs)
359+
resources.objects.extend(objects)
349360

350361
if archive:
351-
needed_update = toolchain.build_library(objects, build_path, name)
362+
needed_update = toolchain.build_library(resources.objects, build_path, name)
352363
else:
353364
needed_update = True
354365

0 commit comments

Comments
 (0)