Skip to content
Snippets Groups Projects
Commit a1904c3a authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Mex functions compile: added xml configuration


Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@113 4c865b51-4357-4376-afb4-474e03ccb993
parent 13dac616
No related branches found
No related tags found
No related merge requests found
conf.xml 0 → 100644
<config>
<root_dir>~vigano/matlabDCT</root_dir>
<mex_files>
<exclude_list>
<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_Condor/trial_medfilt2_mcc_component_data.c</path>
<path>zUtil_Condor/trial_medfilt2_main.c</path>
</exclude_list>
<file>
<path>zUtil_Distortion/distortion_correct_C.c</path>
</file>
<file>
<path>zUtil_DB/mym.cpp</path>
<includes>
<!-- Should be substituted by system package -->
<path>/data/id19/graintracking/code/mysql/include</path>
</includes>
<libraries>
<path>/usr/lib64/mysql/</path>
<!-- Should be substituted by system package -->
<path>/data/id19/graintracking/code/lib64/</path>
<lib>mysqlclient</lib>
<lib>z</lib>
</libraries>
</file>
</mex_files>
</config>
...@@ -5,7 +5,8 @@ import os ...@@ -5,7 +5,8 @@ import os
import sys import sys
import subprocess import subprocess
import string import string
from symbol import except_clause
from xml_dct_io import DCTConf
class MexBuilder(object): class MexBuilder(object):
...@@ -17,6 +18,11 @@ class MexBuilder(object): ...@@ -17,6 +18,11 @@ class MexBuilder(object):
self.compiler_path = compiler_path self.compiler_path = compiler_path
self.c_files = { } self.c_files = { }
self.c_fdirs = { } self.c_fdirs = { }
self.mex_info = None
try:
self.mex_info = DCTConf().getMexFiles()
except:
print("Error: Couldn't get mex files info. Using plain config.")
def findMexs(self): def findMexs(self):
print('Finding mex files, from: ' + self.indir) print('Finding mex files, from: ' + self.indir)
...@@ -32,29 +38,50 @@ class MexBuilder(object): ...@@ -32,29 +38,50 @@ class MexBuilder(object):
print('File: ' + file_name + ' ( ' + self.c_files[file_name] + ' )') print('File: ' + file_name + ' ( ' + self.c_files[file_name] + ' )')
print('') print('')
def _buildMakeCmd(self, cmd, includes, lib_paths, libs, verbose):
if verbose is True:
cmd.append('-v')
for include in includes:
cmd.append("-I" + include)
for lib_path in lib_paths:
cmd.append("-L" + lib_path)
for lib in libs:
cmd.append("-l" + lib)
print('\n file: ' + cmd[1] + ' (cmd: ' + string.join(cmd, ' ') + ' )')
subprocess.call(cmd)
def _compileFile(self, file_name, verbose):
try:
file_path = self.c_files[file_name]
root = self.c_fdirs[file_name]
cmd = [ self.compiler_path, file_path, '-outdir', root ]
if self.mex_info is None:
print("Warning: Mex info not loaded.")
self._buildMakeCmd(cmd, [], [], [], verbose)
else:
if self.mex_info.isExcluded(file_path) is False:
props = self.mex_info.getFileProperties(file_path)
if props is not None:
self._buildMakeCmd(cmd, props.get("includes"),
props.get("lib_paths"),
props.get("libs"), verbose)
else:
print("Warning: No Mex info on file:" + file_name)
self._buildMakeCmd(cmd, [], [], [], verbose)
except KeyError as exc:
print('ERROR. File not found: ' + file_name)
print(exc)
def compileFuncs(self, mfiles_to_consider, force_compile, verbose): def compileFuncs(self, mfiles_to_consider, force_compile, verbose):
print('Compiling mex files:') print('Compiling mex files:')
if ( len(mfiles_to_consider) is 0 if ( len(mfiles_to_consider) is 0
or ( len(mfiles_to_consider) is 1 and mfiles_to_consider[0] == 'all' ) ): or ( len(mfiles_to_consider) is 1 and mfiles_to_consider[0] == 'all' ) ):
for file_name in self.c_files: for file_name in self.c_files:
file_path = self.c_files[file_name] self._compileFile(file_name, verbose)
root = self.c_fdirs[file_name]
cmd = [ self.compiler_path, file_path, '-outdir', root ]
print(' file: ' + file_path + ' (cmd: ' + string.join(cmd, ' ') + ' )')
subprocess.call(cmd)
else: else:
for file_name in mfiles_to_consider: for file_name in mfiles_to_consider:
try: self._compileFile(file_name, verbose)
file_path = self.c_files[file_name]
root = self.c_fdirs[file_name]
cmd = [ self.compiler_path, file_path, '-outdir', root ]
if verbose is True:
cmd.append('-v')
print(' file: ' + file_path + ' (cmd: ' + string.join(cmd, ' ') + ' )')
subprocess.call(cmd)
except KeyError as exc:
print('ERROR. File not found: ' + file_name)
print(exc)
# os.path.getmtime() # os.path.getmtime()
print('Done.') print('Done.')
......
'''
Created on Dec 27, 2011
@author: vigano
'''
try:
import lxml.etree as ET
except ImportError as ex:
print("Couldn't import lxml. Trying with standard distribution.")
try:
import xml.etree.ElementTree as ET
except ImportError as ex1:
print(ex1)
raise ex1
class DCTXMLBase(object):
def __init__(self, xmlFile):
self.xmlFile = xmlFile
self.tree = ET.parse(xmlFile)
def save(self, newName = None):
if newName is not None:
self.xmlFile = newName
self.tree.write(self.xmlFile)
class DCTConf(DCTXMLBase):
def __init__(self):
DCTXMLBase.__init__(self, "conf.xml")
def getRootDir(self):
return self.tree.findtext("root_dir")
def setRootDir(self, newRoot):
self.tree.find("root_dir").text = newRoot
def getMexFiles(self):
return MexConf(self.tree.find("mex_files"))
class MexConf(object):
def __init__(self, tree):
self.tree = tree
def isExcluded(self, testFile):
for exclude in self.tree.findall("exclude_list/path"):
if exclude.text in testFile:
return True
else:
return False
def getFileProperties(self, filePath):
for fileEntry in self.tree.findall("file"):
if fileEntry.findtext("path") in filePath:
output = { }
output["includes"] = []
for include in fileEntry.findall("includes/path"):
output["includes"].append(include.text)
output["lib_paths"] = []
for lib_path in fileEntry.findall("libraries/path"):
output["lib_paths"].append(lib_path.text)
output["libs"] = []
for lib in fileEntry.findall("libraries/lib"):
output["libs"].append(lib.text)
return output
else:
return None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment