[DEV] add add_src_path and add_header_path

This commit is contained in:
Edouard DUPIN 2016-11-09 23:33:38 +01:00
parent 92a0e5198c
commit edfe7a1c96
3 changed files with 101 additions and 23 deletions

View File

@ -54,12 +54,25 @@ class Module:
def __init__(self, file, module_name, module_type):
## Remove all variable to prevent error of multiple deffinition of the module ...
debug.verbose("Create a new module : '" + module_name + "' TYPE=" + module_type)
self._origin_file=''
self._origin_path=''
self._origin_file = file;
self._origin_path = tools.get_current_path(self._origin_file)
# type of the module:
self._type='LIBRARY'
if module_type == 'BINARY' \
or module_type == 'BINARY_SHARED' \
or module_type == 'BINARY_STAND_ALONE' \
or module_type == 'LIBRARY' \
or module_type == 'LIBRARY_DYNAMIC' \
or module_type == 'LIBRARY_STATIC' \
or module_type == 'PACKAGE' \
or module_type == 'PREBUILD' \
or module_type == 'DATA':
self._type=module_type
else :
debug.error('for module "%s"' %module_name)
debug.error(' ==> error : "%s" ' %module_type)
raise 'Input value error'
# Name of the module
self._name=module_name
self._name = module_name
# Tools list:
self._tools = []
# Dependency list:
@ -86,25 +99,9 @@ class Module:
self._paths = []
# The module has been already build ...
self._isbuild = False
## end of basic INIT ...
if module_type == 'BINARY' \
or module_type == 'BINARY_SHARED' \
or module_type == 'BINARY_STAND_ALONE' \
or module_type == 'LIBRARY' \
or module_type == 'LIBRARY_DYNAMIC' \
or module_type == 'LIBRARY_STATIC' \
or module_type == 'PACKAGE' \
or module_type == 'PREBUILD' \
or module_type == 'DATA':
self._type=module_type
else :
debug.error('for module "%s"' %module_name)
debug.error(' ==> error : "%s" ' %module_type)
raise 'Input value error'
self._origin_file = file;
self._origin_path = tools.get_current_path(self._origin_file)
# configure default heritage
self._local_heritage = None
# TODO : Do a better dynamic property system => not really versatil
# TODO : Do a better dynamic property system => not really versatile
self._package_prop = { "COMPAGNY_TYPE" : "",
"COMPAGNY_NAME" : "",
"COMPAGNY_NAME2" : "",
@ -1082,6 +1079,25 @@ class Module:
##
def add_src_file(self, list):
tools.list_append_to(self._src, list, True)
##
## @brief Add all files in a specific path as source file to compile
## @param[in] self (handle) Class handle
## @param[in] base_path (string) Path where to search files
## @param[in] regex (string) regular expression of the search
## @param[in] recursive (bool) Search in resursive mode
## @return None
##
def add_src_path(self, base_path, regex="*", recursive=False):
if len(base_path) == 0:
debug.error("[" + self.get_name() + "] ==> no path set for function add_src_path")
if base_path[0] == '/' \
or base_path[0] == '\\':
debug.error("[" + self.get_name() + "] ==> use relative path for function add_src_path")
list_of_file = tools.get_list_of_file_in_path(os.path.join(self._origin_path, base_path), regex=regex, recursive=recursive, remove_path=self._origin_path)
debug.debug("[" + self.get_name() + "] add " + str(len(list_of_file)) + " file(s)")
self.add_src_file(list_of_file)
##
## @brief An an header file in the install directory
## @param[in] self (handle) Class handle
@ -1090,6 +1106,8 @@ class Module:
## @param[in] clip_path (string) Remove a part of the path set in the list and install data in generic include path
## @param[in] recursive (bool) when use regexp in file list ==> we can add recursive property
##
## @note see add_header_path for a simple integration
##
## @code
## my_module.add_header_file([
## 'include/ewol/widget.h',
@ -1183,6 +1201,21 @@ class Module:
tools.list_append_to(self._header, new_list, True)
##
## @brief An an header path in the install directory
## @param[in] self (handle) Class handle
## @param[in] base_path (string) Path where to search files
## @param[in] regex (string) regular expression of the search
## @param[in] clip_path (string) Remove a part of the path set in the list and install data in generic include path
## @param[in] recursive (bool) Search in resursive mode
## @return None
##
def add_header_path(self, base_path, regex="*", clip_path=None, recursive=False):
if base_path[-1] == '/' \
or base_path[-1] == '\\':
self.add_header_file(base_path + regex, clip_path=clip_path, recursive=recursive)
else:
self.add_header_file(base_path + "/" + regex, clip_path=clip_path, recursive=recursive)
##
## @brief Many library need to generate dynamic file configuration, use this to generat your configuration and add it in the include path
## @param[in] self (handle) Class handle
## @param[in] data_file (string) Data of the file that is generated

View File

@ -170,6 +170,51 @@ def copy_file(src, dst, cmd_file=None, force=False, force_identical=False, in_li
"need_copy":True}
return True
##
## @brief Get list of all Files in a specific path (with a regex)
## @param[in] path (string) Full path of the machine to search files (start with / or x:)
## @param[in] regex (string) Regular expression to search data
## @param[in] recursive (bool) List file with recursive search
## @param[in] remove_path (string) Data to remove in the path
## @return (list) return files requested
##
def get_list_of_file_in_path(path, regex="*", recursive = False, remove_path=""):
out = []
debug.verbose(" List all in : '" + str(path) + "'")
if os.path.isdir(os.path.realpath(path)):
tmp_path = os.path.realpath(path)
tmp_rule = regex
else:
debug.error("path does not exist : '" + str(path) + "'")
debug.verbose(" " + str(tmp_path) + ":")
for root, dirnames, filenames in os.walk(tmp_path):
deltaRoot = root[len(tmp_path):]
while len(deltaRoot) > 0 \
and ( deltaRoot[0] == '/' \
or deltaRoot[0] == '\\' ):
deltaRoot = deltaRoot[1:]
if recursive == False \
and deltaRoot != "":
return
debug.verbose(" root='" + str(deltaRoot) + "'")
debug.extreme_verbose(" files=" + str(filenames))
tmpList = filenames
if len(tmp_rule) > 0:
tmpList = fnmatch.filter(filenames, tmp_rule)
# Import the module :
for cycleFile in tmpList:
#for cycleFile in filenames:
add_file = os.path.join(tmp_path, deltaRoot, cycleFile)
if len(remove_path) != 0:
if add_file[:len(remove_path)] != remove_path:
debug.error("Request remove start of a path that is not the same: '" + add_file[:len(remove_path)] + "' demand remove of '" + str(remove_path) + "'")
else:
add_file = add_file[len(remove_path)+1:]
debug.verbose(" '" + add_file + "'")
out.append(add_file)
return out;
##
## @brief Copy a compleate directory in a specific folder
## @param[in] src Input folder path

View File

@ -40,7 +40,7 @@ class Target(lutinTarget_Linux.Target):
self.xx_version = [0,0,0]
self.ld = self.cross + "ld"
self.nm = self.cross + "nm"
self.strip = self.cross + "strip"
self.strip = ""#self.cross + "strip"
self.dlltool = self.cross + "dlltool"
self._update_path_tree()