From db0c2a8e115a68552b80d3d5cef0b807b5673de6 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 22 Jun 2015 23:16:08 +0200 Subject: [PATCH] [DEV] correct some builder interface --- lutin/module.py | 14 ++- lutin/system.py | 12 +- lutin/target.py | 7 +- lutin/z_system/lutinSystem_Android_ADMOD.py | 115 ++++++++++++++++++++ lutin/z_system/lutinSystem_Android_SDK.py | 4 + 5 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 lutin/z_system/lutinSystem_Android_ADMOD.py diff --git a/lutin/module.py b/lutin/module.py index df4d00a..26cb96e 100644 --- a/lutin/module.py +++ b/lutin/module.py @@ -211,9 +211,11 @@ class Module: self.sub_heritage_list.add_heritage_list(inherit_list) # do sub library action for automatic generating ... if self.type in target.action_on_state: - for action in target.action_on_state[self.type]: - elem = action(target, self, package_name); - + for lvl in range(0,100): + for level, action_name, action in target.action_on_state[self.type]: + if level == lvl: + debug.debug("level=" + str(level) + " Do Action : " + action_name) + elem = action(target, self, package_name); if self.type != 'PREBUILD': # build local sources in a specific order : @@ -602,8 +604,10 @@ class Module: debug.error("not know pkg element : '" + variable + "'") def pkg_add(self, variable, value): - # TODO : Check values... - self.package_prop[variable].append(value) + if variable in self.package_prop: + self.package_prop[variable].append(value) + else: + self.package_prop[variable] = [value] def ext_project_add_module(self, target, projectMng, added_module = []): if self.name in added_module: diff --git a/lutin/system.py b/lutin/system.py index f3284b9..989028a 100644 --- a/lutin/system.py +++ b/lutin/system.py @@ -31,6 +31,7 @@ class System: self.export_libs_ld=[] self.export_libs_ld_shared=[] self.export_src=[] + self.action_on_state={} def append_and_check(self, listout, newElement, order): for element in listout: @@ -66,6 +67,11 @@ class System: def add_export_SRC(self, list): self.append_to_internalList(self.export_src, list) + def add_action(self, name_of_state="PACKAGE", level=5, name="no-name", action=None): + if name_of_state not in self.action_on_state: + self.action_on_state[name_of_state] = [[level, name, action]] + else: + self.action_on_state[name_of_state].append([level, name, action]) @@ -79,7 +85,11 @@ def createModuleFromSystem(target, dict): myModule.add_export_flag('m', dict["system"].export_flags_m) myModule.add_export_flag('mm', dict["system"].export_flags_mm) myModule.add_src_file(dict["system"].export_src) - # add the currrent module at the + + for elem in dict["system"].action_on_state: + level, name, action = dict["system"].action_on_state[elem] + target.add_action(elem, level, name, action) + return myModule diff --git a/lutin/target.py b/lutin/target.py index c23ec8c..a6d7563 100644 --- a/lutin/target.py +++ b/lutin/target.py @@ -432,11 +432,12 @@ class Target: return [heritage.HeritageList(), False] debug.error("not know module name : '" + moduleName + "' to '" + actionName + "' it") - def add_action(self, name_of_state="PACKAGE", action=None): + def add_action(self, name_of_state="PACKAGE", level=5, name="no-name", action=None): + debug.verbose("add action : " + name) if name_of_state not in self.action_on_state: - self.action_on_state[name_of_state] = [action] + self.action_on_state[name_of_state] = [[level, name, action]] else: - self.action_on_state[name_of_state].append(action) + self.action_on_state[name_of_state].append([level, name, action]) targetList=[] diff --git a/lutin/z_system/lutinSystem_Android_ADMOD.py b/lutin/z_system/lutinSystem_Android_ADMOD.py new file mode 100644 index 0000000..617a135 --- /dev/null +++ b/lutin/z_system/lutinSystem_Android_ADMOD.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license APACHE v2.0 (see license file) +## + +from lutin import debug +from lutin import system +from lutin import tools +import os + +class System(system.System): + def __init__(self, target): + system.System.__init__(self) + # create some HELP: + self.help="ADMOD: Android SDK ad-mod interface (auto-create interface for admod)\n" + # todo : Check if present ... + self.valid = True + # todo : create a searcher of the presence of the library: + self.add_export_SRC(target.folder_sdk + "/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar") + self.add_action("PACKAGE", 10, "admod-auto-wrapper", tool_generate_main_java_class) + + + +################################################################## +## +## Android specific section +## +################################################################## +def tool_generate_main_java_class(target, module, package_name): + if "ADMOD_ID" not in module.package_prop: + debug.warning("Missing parameter ADMOD_ID wen you resuested dependency of ADMOD") + return + + module.package_prop["RIGHT"].append("INTERNET") + module.package_prop["RIGHT"].append("ACCESS_NETWORK_STATE") + + module.pkg_add("GENERATE_SECTION__IMPORT", [ + "import com.google.android.gms.ads.AdRequest;", + "import com.google.android.gms.ads.AdSize;", + "import com.google.android.gms.ads.AdView;", + "import android.widget.LinearLayout;", + "import android.widget.Button;" + ]) + module.pkg_add("GENERATE_SECTION__DECLARE", [ + "/** The view to show the ad. */", + "private AdView adView;", + "private LinearLayout mLayout = null;" + ]) + list_create = [ + "mLayout = new LinearLayout(this);" + "mLayout.setOrientation(android.widget.LinearLayout.VERTICAL);", + "LinearLayout.LayoutParams paramsWindows = new LinearLayout.LayoutParams(", + " LinearLayout.LayoutParams.FILL_PARENT,", + " LinearLayout.LayoutParams.FILL_PARENT);", + "", + "setContentView(mLayout, paramsWindows);", + "", + "LinearLayout.LayoutParams paramsAdds = new LinearLayout.LayoutParams(", + " LinearLayout.LayoutParams.FILL_PARENT,", + " LinearLayout.LayoutParams.WRAP_CONTENT);", + "paramsAdds.weight = 0;", + "", + "LinearLayout.LayoutParams paramsGLView = new LinearLayout.LayoutParams(", + " LinearLayout.LayoutParams.FILL_PARENT,", + " LinearLayout.LayoutParams.FILL_PARENT);", + "paramsGLView.weight = 1;", + "paramsGLView.height = 0;", + "", + "mLayout.setGravity(android.view.Gravity.TOP);", + "", + "// Create an adds.", + "adView = new AdView(this);", + "adView.setAdSize(AdSize.SMART_BANNER);", + "adView.setAdUnitId(\"" + module.package_prop["ADMOD_ID"] + "\");", + "", + "// Create an ad request. Check logcat output for the hashed device ID to get test ads on a physical device.", + "AdRequest adRequest = new AdRequest.Builder()", + " .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)", + " .build();", + "", + "// Add the AdView to the view hierarchy. The view will have no size until the ad is loaded."] + if "ADMOD_POSITION" in module.package_prop \ + and module.package_prop["ADMOD_POSITION"] == "top": + list_create.append("mLayout.addView(adView, paramsAdds);") + list_create.append("mLayout.addView(mGLView, paramsGLView);") + else: + list_create.append("mLayout.addView(mGLView, paramsGLView);") + list_create.append("mLayout.addView(adView, paramsAdds);") + list_create.append("") + list_create.append("// Start loading the ad in the background.") + list_create.append("adView.loadAd(adRequest);") + module.pkg_add("GENERATE_SECTION__ON_CREATE", list_create) + module.pkg_add("GENERATE_SECTION__ON_RESUME", [ + "if (adView != null) {", + " adView.resume();", + "}" + ]) + module.pkg_add("GENERATE_SECTION__ON_PAUSE", [ + "if (adView != null) {", + " adView.pause();", + "}" + ]) + module.pkg_add("GENERATE_SECTION__ON_DESTROY", [ + "// Destroy the AdView.", + "if (adView != null) {", + " adView.destroy();", + "}" + ]) + + + diff --git a/lutin/z_system/lutinSystem_Android_SDK.py b/lutin/z_system/lutinSystem_Android_SDK.py index d56dfdc..99398a3 100644 --- a/lutin/z_system/lutinSystem_Android_SDK.py +++ b/lutin/z_system/lutinSystem_Android_SDK.py @@ -17,8 +17,12 @@ class System(system.System): system.System.__init__(self) # create some HELP: self.help="SDK: Android SDK basic interface java\n" + # TODO : Check if the android sdk android.jar is present ... self.valid = True # todo : create a searcher of the presence of the library: self.add_export_SRC(target.folder_sdk + "/platforms/android-" + str(target.boardId) + "/android.jar") + self.add_export_flag_LD("-ldl") + self.add_export_flag_LD("-llog") + self.add_export_flag_LD("-landroid")