[DEV] add macro concept
This commit is contained in:
parent
0e7458cc06
commit
f24e1a6d90
@ -11,6 +11,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import fnmatch
|
import fnmatch
|
||||||
# Local import
|
# Local import
|
||||||
|
from . import macro
|
||||||
from . import target
|
from . import target
|
||||||
from . import builder
|
from . import builder
|
||||||
from . import system
|
from . import system
|
||||||
@ -148,6 +149,7 @@ def init():
|
|||||||
module.import_path(list_of_lutin_files)
|
module.import_path(list_of_lutin_files)
|
||||||
system.import_path(list_of_lutin_files)
|
system.import_path(list_of_lutin_files)
|
||||||
target.import_path(list_of_lutin_files)
|
target.import_path(list_of_lutin_files)
|
||||||
|
macro.import_path(list_of_lutin_files)
|
||||||
|
|
||||||
builder.init()
|
builder.init()
|
||||||
is_init = True
|
is_init = True
|
||||||
|
76
lutin/macro.py
Normal file
76
lutin/macro.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##
|
||||||
|
## @author Edouard DUPIN
|
||||||
|
##
|
||||||
|
## @copyright 2012, Edouard DUPIN, all right reserved
|
||||||
|
##
|
||||||
|
## @license APACHE v2.0 (see license file)
|
||||||
|
##
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import inspect
|
||||||
|
import fnmatch
|
||||||
|
import datetime
|
||||||
|
# Local import
|
||||||
|
from . import debug
|
||||||
|
from . import tools
|
||||||
|
from . import env
|
||||||
|
|
||||||
|
|
||||||
|
__macro_list=[]
|
||||||
|
__start_macro_name="Macro_"
|
||||||
|
|
||||||
|
##
|
||||||
|
## @brief Import all File that start with env.get_build_system_base_name() + __start_macro_name + XXX and register in the list of Target
|
||||||
|
## @param[in] path_list ([string,...]) List of file that start with env.get_build_system_base_name() in the running worktree (Parse one time ==> faster)
|
||||||
|
##
|
||||||
|
def import_path(path_list):
|
||||||
|
global __macro_list
|
||||||
|
global_base = env.get_build_system_base_name()
|
||||||
|
debug.debug("TARGET: Init with Files list:")
|
||||||
|
for elem in path_list:
|
||||||
|
sys.path.append(os.path.dirname(elem))
|
||||||
|
# Get file name:
|
||||||
|
filename = os.path.basename(elem)
|
||||||
|
# Remove .py at the end:
|
||||||
|
filename = filename[:-3]
|
||||||
|
# Remove global base name:
|
||||||
|
filename = filename[len(global_base):]
|
||||||
|
# Check if it start with the local patern:
|
||||||
|
if filename[:len(__start_macro_name)] != __start_macro_name:
|
||||||
|
debug.extreme_verbose("MACRO: NOT-Integrate: '" + filename + "' from '" + elem + "' ==> rejected")
|
||||||
|
continue
|
||||||
|
# Remove local patern
|
||||||
|
target_name = filename[len(__start_macro_name):]
|
||||||
|
debug.verbose("MACRO: Integrate: '" + target_name + "' from '" + elem + "'")
|
||||||
|
__macro_list.append([target_name, elem])
|
||||||
|
debug.verbose("New list MACRO: ")
|
||||||
|
for elem in __macro_list:
|
||||||
|
debug.verbose(" " + str(elem[0]))
|
||||||
|
|
||||||
|
##
|
||||||
|
## @brief Load a specific target
|
||||||
|
##
|
||||||
|
def load_macro(name):
|
||||||
|
global __macro_list
|
||||||
|
debug.debug("load macro: " + name)
|
||||||
|
if len(__macro_list) == 0:
|
||||||
|
debug.error("No macro to compile !!!")
|
||||||
|
debug.debug("list macro: " + str(__macro_list))
|
||||||
|
for mod in __macro_list:
|
||||||
|
if mod[0] == name:
|
||||||
|
debug.verbose("add to path: '" + os.path.dirname(mod[1]) + "'")
|
||||||
|
sys.path.append(os.path.dirname(mod[1]))
|
||||||
|
debug.verbose("import macro : '" + env.get_build_system_base_name() + __start_macro_name + name + "'")
|
||||||
|
the_macro = __import__(env.get_build_system_base_name() + __start_macro_name + name)
|
||||||
|
return the_macro
|
||||||
|
raise KeyError("No entry for : " + name)
|
||||||
|
|
||||||
|
def list_all_macro():
|
||||||
|
global __macro_list
|
||||||
|
tmp_list_name = []
|
||||||
|
for mod in __macro_list:
|
||||||
|
tmp_list_name.append(mod[0])
|
||||||
|
return tmp_list_name
|
@ -75,6 +75,8 @@ class Module:
|
|||||||
self._name = module_name
|
self._name = module_name
|
||||||
# Tools list:
|
# Tools list:
|
||||||
self._tools = []
|
self._tools = []
|
||||||
|
# list of action to do:
|
||||||
|
self._actions = []
|
||||||
# Dependency list:
|
# Dependency list:
|
||||||
self._depends = []
|
self._depends = []
|
||||||
# Dependency list (optionnal module):
|
# Dependency list (optionnal module):
|
||||||
@ -161,6 +163,14 @@ class Module:
|
|||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
##
|
||||||
|
## @brief Get origin path of the module declaration
|
||||||
|
## @param[in] self (handle) Class handle
|
||||||
|
## @return (string) path of the module
|
||||||
|
##
|
||||||
|
def get_origin_path(self):
|
||||||
|
return self._origin_path
|
||||||
|
|
||||||
##
|
##
|
||||||
## @brief Get type of the module ("BINARY", "LIBRARY", ...)
|
## @brief Get type of the module ("BINARY", "LIBRARY", ...)
|
||||||
## @param[in] self (handle) Class handle
|
## @param[in] self (handle) Class handle
|
||||||
@ -511,7 +521,10 @@ class Module:
|
|||||||
return copy.deepcopy(self._sub_heritage_list)
|
return copy.deepcopy(self._sub_heritage_list)
|
||||||
# create the package heritage
|
# create the package heritage
|
||||||
self._local_heritage = heritage.heritage(self, target)
|
self._local_heritage = heritage.heritage(self, target)
|
||||||
|
if len(self._actions) != 0:
|
||||||
|
debug.warning("execute actions: " + str(len(self._actions)))
|
||||||
|
for action in self._actions:
|
||||||
|
action["action"](target, self, action["data"]);
|
||||||
if package_name == None \
|
if package_name == None \
|
||||||
and ( self._type == 'BINARY'
|
and ( self._type == 'BINARY'
|
||||||
or self._type == 'BINARY_SHARED' \
|
or self._type == 'BINARY_SHARED' \
|
||||||
@ -602,6 +615,8 @@ class Module:
|
|||||||
"need_copy":ret_write}
|
"need_copy":ret_write}
|
||||||
if elem_generate["install"] == True:
|
if elem_generate["install"] == True:
|
||||||
have_only_generate_file = True
|
have_only_generate_file = True
|
||||||
|
# TODO : Do it better, we force the include path in the heritage to permit to have a correct inclusion ...
|
||||||
|
self._local_heritage.include = target.get_build_path_include(self._name)
|
||||||
if have_only_generate_file == True:
|
if have_only_generate_file == True:
|
||||||
self._add_path(generate_path)
|
self._add_path(generate_path)
|
||||||
|
|
||||||
@ -1264,6 +1279,20 @@ class Module:
|
|||||||
"install":install_element
|
"install":install_element
|
||||||
});
|
});
|
||||||
|
|
||||||
|
##
|
||||||
|
## @brief Add action to do for the module
|
||||||
|
## @param[in] action (function handle) Function to call to execure action
|
||||||
|
## @param[in] data (*) Data to set at the action function
|
||||||
|
## @return None
|
||||||
|
##
|
||||||
|
def add_action(self, action, data=None, name=None):
|
||||||
|
debug.verbose("add action : " + str(name))
|
||||||
|
self._actions.append({
|
||||||
|
"name":name,
|
||||||
|
"action":action,
|
||||||
|
"data":data
|
||||||
|
})
|
||||||
|
|
||||||
##
|
##
|
||||||
## @brief copy image in the module datas
|
## @brief copy image in the module datas
|
||||||
## @param[in] self (handle) Class handle
|
## @param[in] self (handle) Class handle
|
||||||
@ -1328,6 +1357,7 @@ class Module:
|
|||||||
|
|
||||||
self._print_list('depends',self._depends)
|
self._print_list('depends',self._depends)
|
||||||
self._print_list('depends_optionnal', self._depends_optionnal)
|
self._print_list('depends_optionnal', self._depends_optionnal)
|
||||||
|
print(' action count=' + str(self._actions))
|
||||||
|
|
||||||
for element in self._flags["local"]:
|
for element in self._flags["local"]:
|
||||||
value = self._flags["local"][element]
|
value = self._flags["local"][element]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user