Skip to content

Commit 2e7010e

Browse files
authored
implemented partial build of the sources if a file changed (#106)
1 parent bb5e6ec commit 2e7010e

File tree

2 files changed

+58
-24
lines changed

2 files changed

+58
-24
lines changed

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
_project_cmplr_flag_compatibility = ["-Wl,--enable-new-dtags", "-fPIC"]
120120
_project_cmplr_flag_lib = []
121121
_project_cmplr_macro = []
122+
_project_force_build = False
122123
_project_sycl_queue_control_macro = [("DPNP_LOCAL_QUEUE", "1")]
123124
_project_rpath = ["$ORIGIN"]
124125
_dpctrl_include = []
@@ -270,6 +271,7 @@
270271
"extra_link_postargs": _project_cmplr_flag_compatibility + _project_cmplr_flag_lib,
271272
"libraries": _mkl_libs + _dpctrl_lib,
272273
"macros": _project_cmplr_macro,
274+
"force_build": _project_force_build,
273275
"language": "c++"
274276
}
275277
]

utils/command_build_clib.py

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@
3434
- extra option 'runtime_library_dirs'
3535
- extra option 'extra_preargs'
3636
- extra option 'extra_link_postargs'
37+
- extra option 'force_build'
3738
- extra option 'language'
38-
39+
- a check if source needs to be rebuilt based on time stamp
40+
- a check if librayr needs to be rebuilt based on time stamp
3941
"""
4042

41-
4243
import os
44+
4345
from setuptools.command import build_clib
4446
from distutils import log
47+
from distutils.dep_util import newer_group
4548
from distutils.file_util import copy_file
4649

4750

@@ -51,7 +54,12 @@ def build_libraries(self, libraries):
5154
"""
5255
This function is overloaded to the original function in build_clib.py file
5356
"""
57+
5458
for (lib_name, build_info) in libraries:
59+
c_library_name = self.compiler.library_filename(lib_name, lib_type='shared')
60+
c_library_filename = os.path.join(self.build_clib, c_library_name)
61+
dest_filename = "dpnp" # TODO need to fix destination directory
62+
5563
sources = build_info.get('sources')
5664
if sources is None or not isinstance(sources, (list, tuple)):
5765
err_msg = f"in 'libraries' option (library '{lib_name}'),"
@@ -60,7 +68,11 @@ def build_libraries(self, libraries):
6068

6169
sources = list(sources)
6270

63-
log.info("building '%s' library", lib_name)
71+
log.info("DPNP: building '%s' library", lib_name)
72+
73+
# set compiler and options
74+
# -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC
75+
# self.compiler.compiler_so = ["clang++", "-fPIC"]
6476

6577
macros = build_info.get('macros')
6678
include_dirs = build_info.get('include_dirs')
@@ -69,29 +81,49 @@ def build_libraries(self, libraries):
6981
runtime_library_dirs = build_info.get("runtime_library_dirs")
7082
extra_preargs = build_info.get("extra_preargs")
7183
extra_link_postargs = build_info.get("extra_link_postargs")
84+
force_build = build_info.get("force_build")
7285
language = build_info.get("language")
7386

74-
objects = self.compiler.compile(sources,
75-
output_dir=self.build_temp,
76-
macros=macros,
77-
include_dirs=include_dirs,
78-
extra_preargs=extra_preargs,
79-
debug=self.debug)
80-
81-
self.compiler.link_shared_lib(objects,
82-
lib_name,
83-
output_dir=self.build_clib,
84-
libraries=libraries,
85-
library_dirs=library_dirs,
86-
runtime_library_dirs=runtime_library_dirs,
87-
extra_preargs=extra_preargs,
88-
extra_postargs=extra_link_postargs,
89-
debug=self.debug,
90-
build_temp=self.build_temp,
91-
target_lang=language)
87+
objects = []
88+
"""
89+
Build object files from sources
90+
"""
91+
for source_it in sources:
92+
obj_file_list = self.compiler.object_filenames([source_it], strip_dir=0, output_dir=self.build_temp)
93+
obj_file = "".join(obj_file_list) # convert from list to file name
9294

93-
dest_filename = "dpnp" # TODO need to fix destination directory
94-
c_library_name = self.compiler.library_filename(lib_name, lib_type='shared')
95-
c_library_filename = os.path.join(self.build_clib, c_library_name)
95+
newer_than_obj = newer_group([source_it], obj_file, missing="newer")
96+
if force_build or newer_than_obj:
97+
obj_file_list = self.compiler.compile([source_it],
98+
output_dir=self.build_temp,
99+
macros=macros,
100+
include_dirs=include_dirs,
101+
extra_preargs=extra_preargs,
102+
debug=self.debug)
103+
objects.extend(obj_file_list)
104+
else:
105+
objects.append(obj_file)
106+
107+
"""
108+
Build library file from objects
109+
"""
110+
newer_than_lib = newer_group(objects, c_library_filename, missing="newer")
111+
if force_build or newer_than_lib:
112+
self.compiler.link_shared_lib(objects,
113+
lib_name,
114+
output_dir=self.build_clib,
115+
libraries=libraries,
116+
library_dirs=library_dirs,
117+
runtime_library_dirs=runtime_library_dirs,
118+
extra_preargs=extra_preargs,
119+
extra_postargs=extra_link_postargs,
120+
debug=self.debug,
121+
build_temp=self.build_temp,
122+
target_lang=language)
96123

124+
"""
125+
Copy library to the destination path
126+
"""
97127
copy_file(c_library_filename, dest_filename, verbose=self.verbose, dry_run=self.dry_run)
128+
129+
log.info("DPNP: building '%s' library finished", lib_name)

0 commit comments

Comments
 (0)