From b6a5f7e539f67f73760a0fdea39a56aa8845cdb3 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 4 Oct 2016 21:08:06 +0200 Subject: [PATCH] [DEV] update build to support configure instead of create in module ==> permit to get back the version ... order issue --- doc/030_Create_a_new_module.md | 41 +++++++++++++++------------ lutin/module.py | 29 +++++++++++++++++-- lutin/z_target/lutinTarget_Windows.py | 2 ++ test/test-c/lutin_test-c.py | 6 ++-- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/doc/030_Create_a_new_module.md b/doc/030_Create_a_new_module.md index 83b4fe1..e8e69f9 100644 --- a/doc/030_Create_a_new_module.md +++ b/doc/030_Create_a_new_module.md @@ -82,11 +82,12 @@ def get_version(): # create the module # @param[in] target reference on the Target that is currently build -# @param[in] module_name Name of the module that is extract from the file name (to be generic) -def create(target, module_name): - my_module = module.Module(__file__, module_name, get_type()) +# @param[in] my_module Module handle that migh be configured +# @return True The module is welled configure +# @return False The module is Not availlable (for this target or ...) +def configure(target, my_module): ... - return my_module + return True ``` Thes it is simple to specify build for: @@ -164,7 +165,7 @@ Add file to compile: {#lutin_module_int This is simple: (you just need to specify all the file to compile) ```{.py} -def create(target, module_name): +def configure(target, my_module): ... # add the file to compile: @@ -187,7 +188,7 @@ This permit to check error inclusion directly in developpement and separate the Add file to external include: ```{.py} -def create(target, module_name): +def configure(target, my_module): ... my_module.add_header_file([ @@ -200,7 +201,7 @@ def create(target, module_name): You can add a path to your local include: ```{.py} -def create(target, module_name): +def configure(target, my_module): ... my_module.add_path(os.path.join(tools.get_current_path(__file__), "lib-name")) @@ -214,7 +215,7 @@ Add Sub-dependency: {#lutin_module_int All library need to add at minimum of a simple library (C lib) and other if needed. To do it jus call: ```{.py} -def create(target, module_name): +def configure(target, my_module): ... # add dependency of the generic C library: @@ -231,7 +232,7 @@ def create(target, module_name): The system can have optinnal sub-library, then if you just want to add an optionnal dependency: ```{.py} -def create(target, module_name): +def configure(target, my_module): ... # Add an optionnal dependency (set flag in CPP build if the subLib exist) ==> flag is locally set @@ -248,7 +249,7 @@ Compilation adn link flags/libs: {#lutin_module_int It is possible to define local and external flags (external are set internal too): ```{.py} -def create(target, module_name): +def configure(target, my_module): ... # external flags: my_module.add_flag('link-lib', "pthread", export=True) @@ -264,7 +265,7 @@ build mode (release/debug): {#lutin_module_int To add somes element dependent of the build mode: ```{.py} -def create(target, module_name): +def configure(target, my_module): ... if target.get_mode() == "release": @@ -281,7 +282,7 @@ build type target: {#lutin_module_int To add somes element dependent of the target type: ```{.py} -def create(target, module_name): +def configure(target, my_module): ... if "Windows" in target.get_type(): @@ -309,7 +310,7 @@ Add some data in the install path (share path): {#lutin_module_in You can install a simple file: ```{.py} -def create(target, module_name): +def configure(target, my_module): ... # copy file in the share/binanyName/ path (no sub path) @@ -321,7 +322,7 @@ def create(target, module_name): Copy multiple files (change path) ```{.py} -def create(target, module_name): +def configure(target, my_module): ... my_module.copy_path('data/*', 'destinationPath') @@ -414,17 +415,20 @@ def get_compagny_name(): # Note: this fucntion is optionnal. def get_maintainer(): return ["Mr NAME SurName "] + # return "authors.txt" # Version of the library # Note: this fucntion is optionnal. def get_version(): return [0,1,"dev"] + # return "version.txt" # create the module # @param[in] target reference on the Target that is currently build -# @param[in] module_name Name of the module that is extract from the file name (to be generic) -def create(target, module_name): - my_module = module.Module(__file__, module_name, get_type()) +# @param[in] my_module Module handle that migh be configured +# @return True The module is welled configure +# @return False The module is Not availlable (for this target or ...) +def configure(target, my_module): # add the file to compile: my_module.add_src_file([ @@ -485,7 +489,8 @@ def create(target, module_name): my_module.copy_path('data/*', 'destinationPath') - return my_module + # Return True if the module is compatible with the target or ... + return True ``` diff --git a/lutin/module.py b/lutin/module.py index b6ef1b9..bf9eec3 100644 --- a/lutin/module.py +++ b/lutin/module.py @@ -1451,7 +1451,32 @@ def load_module(target, name): # get basic module properties: property = get_module_option(os.path.dirname(mod[1]), the_module, name) # configure the module: - if "create" in dir(the_module): + if "configure" in dir(the_module): + # create the module: + tmp_element = Module(the_module_file, name, property["type"]) + # overwrite some package default property (if not set by user) + if property["compagny-type"] != None: + tmp_element._pkg_set_if_default("COMPAGNY_TYPE", property["compagny-type"]) + if property["compagny-name"] != None: + tmp_element._pkg_set_if_default("COMPAGNY_NAME", property["compagny-name"]) + if property["maintainer"] != None: + tmp_element._pkg_set_if_default("MAINTAINER", property["maintainer"]) + if property["name"] != None: + tmp_element._pkg_set_if_default("NAME", property["name"]) + if property["description"] != None: + tmp_element._pkg_set_if_default("DESCRIPTION", property["description"]) + if property["license"] != None: + tmp_element._pkg_set_if_default("LICENSE", property["license"]) + if property["version"] != None: + tmp_element._pkg_set_if_default("VERSION", property["version"]) + # call user to configure it: + ret = the_module.configure(target, tmp_element) + if ret == False: + # the user request remove the capabilities of this module for this platform + tmp_element = None + elif "create" in dir(the_module): + # parse in a second time to permit to implement retro-compat build + debug.warning("[DEPRECATED] (" + name + ") module creation: function 'create', use 'configure' ... (remove compatibility in next major version (2.x)") tmp_element = the_module.create(target, name) if tmp_element != None: # overwrite some package default property (if not set by user) @@ -1542,7 +1567,7 @@ def get_module_option(path, the_module, name): if "get_type" in list_of_function_in_factory: type = the_module.get_type() else: - debug.debug(" function get_type() must be provided in the module: " + name) + debug.error(" function get_type() must be provided in the module: " + name) if "get_sub_type" in list_of_function_in_factory: sub_type = the_module.get_sub_type() diff --git a/lutin/z_target/lutinTarget_Windows.py b/lutin/z_target/lutinTarget_Windows.py index d0e6adc..9884982 100644 --- a/lutin/z_target/lutinTarget_Windows.py +++ b/lutin/z_target/lutinTarget_Windows.py @@ -175,6 +175,7 @@ class Target(target.Target): if host.OS == "Windows": debug.error("action not implemented ...") return + debug.debug(" think to configure your wine : 'winecfg' : https://www.winehq.org/docs/wineusr-guide/config-wine-main") appl_path = os.path.join(self.get_staging_path(pkg_name), pkg_name + ".app", pkg_name + self.suffix_binary) cmd = "wine " + appl_path + " " for elem in option_list: @@ -183,3 +184,4 @@ class Target(target.Target): debug.debug("------------------------------------------------------------------------") debug.info("-- Run package '" + pkg_name + "' Finished") debug.debug("------------------------------------------------------------------------") + diff --git a/test/test-c/lutin_test-c.py b/test/test-c/lutin_test-c.py index 8426442..c7fbcb9 100644 --- a/test/test-c/lutin_test-c.py +++ b/test/test-c/lutin_test-c.py @@ -1,5 +1,4 @@ #!/usr/bin/python -import lutin.module as module import lutin.tools as tools import lutin.debug as debug import os @@ -8,10 +7,9 @@ def get_type(): return "BINARY" def get_desc(): - return "Text C compilation" + return "Test C compilation" -def create(target, module_name): - my_module = module.Module(__file__, module_name, get_type()) +def configure(target, my_module): my_module.add_extra_compile_flags() my_module.add_src_file([ 'test.c'