diff --git a/dct_launch.py b/dct_launch.py index 094937821a1f433a14bdbdf767c84e3c59ccf492..c38544cb264b8da342a0b0818234fbd370b48521 100755 --- a/dct_launch.py +++ b/dct_launch.py @@ -112,8 +112,8 @@ class DCTLauncher(object): try: args_compile = [""] + self.args mex_builder = MexBuilder.getInstanceFromArgs(args_compile, dct_dir = self.dct_dir) - mex_builder.findMexs() - mex_builder.compileFuncs() + mex_builder.find_mex_files() + mex_builder.compile_mex_files() except ValueError as ex: if (len(ex.args) is not 0) and (ex.args[0] is not ""): dct.dct_io_xml.DCTOutput.printError(ex.args) diff --git a/zUtil_Conf/conf.example.xml b/zUtil_Conf/conf.example.xml index f4e15540c7f664c0e6f991dedc9cad1518fd03a9..2e8d48d7857aa7d1ff1bdffa8f211fa8589e1f63 100644 --- a/zUtil_Conf/conf.example.xml +++ b/zUtil_Conf/conf.example.xml @@ -56,27 +56,12 @@ <mex_files> <exclude_list> + <path>zUtil_Cxx/test/*.cpp</path> <path>zUtil_Imaging/pmedf/pmedf_readC.cpp</path> - <path>zUtil_ForwardProjection/jacobs_ray3d_c.c</path> - <path>zUtil_ForwardProjection/jacobs_rays.c</path> - <path>zUtil_Crack/External/ITK_REGISTRATION/src/ProgOptions.cxx</path> - <path>zUtil_Crack/External/ITK_REGISTRATION/src/TestRegistrationProgOptions.cxx</path> - <path>zUtil_Crack/External/ITK_REGISTRATION/src/itkRegistrationAffineTransform.cxx</path> - <path>zUtil_Crack/External/ITK_REGISTRATION/src/itkRegistrationVersorRigid3DTransform.cxx</path> - <path>zUtil_Crack/External/ITK_SEGMENTATION/src/ProgOptions.cxx</path> - <path>zUtil_Crack/External/ITK_SEGMENTATION/src/TestProgOptions.cxx</path> - <path>zUtil_Crack/External/ITK_SEGMENTATION/src/itkCrackRemesh.cxx</path> - <path>zUtil_Crack/External/ITK_SEGMENTATION/src/itkCrackSegmentation.cxx</path> - <path>zUtil_Crack/External/ITK_SEGMENTATION/src/itkMeshTovtkPolyData.cxx</path> - <path>zUtil_Crack/External/ITK_SEGMENTATION/src/vtkShowWriteMesh.cxx</path> - <path>zUtil_Crack/External/ITK_TOOLS/src/itkMedianImageFilter.cxx</path> - <path>zUtil_Crack/External/ITK_TOOLS/src/itkNormalizeImageFilter.cxx</path> - <path>zUtil_Crack/External/ITK_TOOLS/src/itkRescaleIntensityImageFilter.cxx</path> - <path>zUtil_Crack/External/ITK_TOOLS/src/itkResizeVolume.cxx</path> - <path>zUtil_Crack/External/ITK_TOOLS/src/itkShiftScaleImageFilter.cxx</path> - <path>zUtil_Crack/External/ITK_TOOLS/src/itkTransformBinaryFromFile.cxx</path> - <path>zUtil_Crack/External/ITK_TOOLS/src/itkVersorRigid3DTransform.cxx</path> - <path>zUtil_Crack/External/ITK_TOOLS/src/itkVersorRigid3DTransform2.cxx</path> + <path>zUtil_ForwardProjection/*.c</path> + <path>zUtil_Crack/External/ITK_REGISTRATION/src/*.cxx</path> + <path>zUtil_Crack/External/ITK_SEGMENTATION/src/*.cxx</path> + <path>zUtil_Crack/External/ITK_TOOLS/src/*.cxx</path> </exclude_list> <file> diff --git a/zUtil_Python/dct_compile_mex_functions.py b/zUtil_Python/dct_compile_mex_functions.py index fa500931f960f572531a331739f946e0159420f4..44e6e6dccf2e5b1151ea5a1a18966de369abc249 100755 --- a/zUtil_Python/dct_compile_mex_functions.py +++ b/zUtil_Python/dct_compile_mex_functions.py @@ -88,6 +88,7 @@ class MexBuilder(object): self.outdir = outdir self.c_files = { } + self.excluded_c_files = { } self.mfiles_to_consider = mfiles_to_consider self.force_compile = force_compile @@ -123,11 +124,14 @@ class MexBuilder(object): print(" -force-compile : to force the compilation even if not needed") print(" -fresh-mexopts : to force the resetting of mexopts file") - def findMexs(self): - """ - def findMexs(): + def is_mex_excluded(self, file_path): + if self.mex_info is not None: + return self.mex_info.isExcluded(file_path, self.dct_dir) + return False - Finds the mex files (well, the C sources) and saves the files into the object + def find_mex_files(self): + """ + Finds the mex files (well, the C and Cxx sources) and saves the files into the object """ self.out.printSubJob("Finding mex files, from: '%s'" % self.dct_dir) for root, dir_name, file_names in os.walk(self.dct_dir): @@ -135,13 +139,45 @@ class MexBuilder(object): for file_name in file_names: if fnmatch.fnmatch(file_name, file_extension): filepath = os.path.join(root, file_name) - self.c_files[file_name] = filepath - self.out.printSubJob("These files were found:") + if self.is_mex_excluded(filepath): + self.excluded_c_files[file_name] = filepath + else: + self.c_files[file_name] = filepath + self.out.printSubJob("These files were found, but excluded:") + for file_name in self.excluded_c_files: + self.out.printSubSubJob('File', file_name + ' ( ' + self.excluded_c_files[file_name] + ' )') + self.out.printSubJob("These files were found, and they can be compiled:") for file_name in self.c_files: self.out.printSubSubJob('File', file_name + ' ( ' + self.c_files[file_name] + ' )') print('') - def _buildMakeCmd(self, cmd, includes, lib_paths, libs, defines, options): + def _compile_mex_file(self, file_name): + """ + Tries to compile the given file. + """ + file_path = self.c_files[file_name] + + compiler_path = os.path.join(self.matlab_dir, "bin", "mex") + cmd = [ compiler_path, file_path, '-outdir', self.outdir ] + + includes = [ os.path.join(self.dct_dir, 'zUtil_Cxx', 'include') ] + lib_paths = [] + libs = [] + defines = [] + options = [] + + if self.mex_info is not None: + props = self.mex_info.getFileProperties(file_name) + if props is None: + props = self.mex_info.getFileProperties(file_path) + if props is not None: + # No info at all into the xml file + includes = includes + props.get("includes") + lib_paths = lib_paths + props.get("lib_paths") + libs = libs + props.get("libs") + defines = defines + props.get("defines") + options = options + props.get("options") + if self.out.verboseLevel > 1: cmd.append('-v') if self.debug is True: @@ -163,39 +199,8 @@ class MexBuilder(object): self.out.printSubSubJob('File', cmd[1] + ' (cmd: ' + string.join(cmd, ' ') + ' )') return subprocess.call(cmd) - def _compileFile(self, file_path): - """ - [Internal] def _compileFile(file_path): - - Tries to compile the given file_path. - """ - compiler_path = os.path.join(self.matlab_dir, "bin", "mex") - cmd = [ compiler_path, file_path, '-outdir', self.outdir ] - - includes = [ os.path.join(self.dct_dir, 'zUtil_Cxx', 'include') ] - lib_paths = [] - libs = [] - defines = [] - options = [] - - if (self.mex_info is not None) \ - and (self.mex_info.isExcluded(file_path) is False): - - props = self.mex_info.getFileProperties(file_path) - if props is not None: - # No info at all into the xml file - includes = includes + props.get("includes") - lib_paths = lib_paths + props.get("lib_paths") - libs = libs + props.get("libs") - defines = defines + props.get("defines") - options = options + props.get("options") - - return self._buildMakeCmd(cmd, includes, lib_paths, libs, defines, options) - - def compileFuncs(self): + def compile_mex_files(self): """ - def compileFuncs(): - Compiles the mex files into the list. """ @@ -223,7 +228,6 @@ class MexBuilder(object): # Now let's compile for file_name in files_to_compile: - # Check if it is an actual file or a regular expression if file_name in self.c_files: match_list = [ file_name ] @@ -239,13 +243,9 @@ class MexBuilder(object): # Let's compile each match for cfile in match_list: - file_path = self.c_files[cfile] - if (self.mex_info is None) \ - or ( (self.mex_info is not None) \ - and (self.mex_info.isExcluded(file_path) is False) ): - ret_val = self._compileFile(file_path) - if ret_val is not 0: - listOfErrors.append("Error compiling MEX: %s (Return Value: %d)" % (file_name, ret_val)) + ret_val = self._compile_mex_file(cfile) + if ret_val is not 0: + listOfErrors.append("Error compiling MEX: %s (Return Value: %d)" % (file_name, ret_val)) print('') if len(listOfErrors) is not 0: print("Errors happened during compilation:") @@ -255,8 +255,8 @@ class MexBuilder(object): if __name__=="__main__": try: mex_builder = MexBuilder.getInstanceFromArgs(sys.argv) - mex_builder.findMexs() - mex_builder.compileFuncs() + mex_builder.find_mex_files() + mex_builder.compile_mex_files() except ValueError as ex: if (len(ex.args) is not 0) and (ex.args[0] is not ""): DCTOutput.printError(ex.args) diff --git a/zUtil_Python/dct_io_xml.py b/zUtil_Python/dct_io_xml.py index bbbeeb49398216aec484f4e8c3e90668b146c02d..7931d12c859ffab5bf2db1516f0c458da6fb6222 100755 --- a/zUtil_Python/dct_io_xml.py +++ b/zUtil_Python/dct_io_xml.py @@ -161,9 +161,10 @@ class MexConf(object): def __init__(self, tree): self.tree = tree - def isExcluded(self, testFile): + def isExcluded(self, test_file, dct_dir): for exclude in self.tree.findall("exclude_list/path"): - if re.search(exclude.text, testFile): + exclude_path = os.path.join(dct_dir, exclude.text) + if fnmatch.fnmatch(test_file, exclude_path): return True else: return False