[DEV] set it back (integration android)

This commit is contained in:
Edouard DUPIN 2015-09-15 22:01:19 +02:00
parent 979e71c101
commit 6ac4cc45fa
5 changed files with 87 additions and 98 deletions

View File

@ -178,10 +178,10 @@ class heritage:
append_to_list(self.src['dynamic'], elements) append_to_list(self.src['dynamic'], elements)
def add_lib_interpreted(self, type_interpretation, elements): def add_lib_interpreted(self, type_interpretation, elements):
debug.error("TODO ...") # TODO : Think at a better methodologie ...
if type(elements) == type(None): if type(elements) == type(None):
debug.error("try add element none in a list ...") debug.error("try add element none in a list ...")
append_to_list(self.src, elements) append_to_list(self.src['src'], elements)
def auto_add_build_header(self): def auto_add_build_header(self):
if self.include != "": if self.include != "":

View File

@ -14,14 +14,14 @@ from . import tools
from . import multiprocess from . import multiprocess
from . import depend from . import depend
enableResizeImage = True enable_resize_image = True
try: try:
if platform.system() == "Darwin": if platform.system() == "Darwin":
import CoreGraphics import CoreGraphics
else: else:
from PIL import Image from PIL import Image
except: except:
enableResizeImage = False enable_resize_image = False
debug.warning("Missing python tools : CoreGraphics (MacOs) or PIL") debug.warning("Missing python tools : CoreGraphics (MacOs) or PIL")
def get_pow_2_multiple(size): def get_pow_2_multiple(size):
@ -34,31 +34,31 @@ def get_pow_2_multiple(size):
# check if force requested # check if force requested
# check if time change # check if time change
# check if command line change # check if command line change
def resize(srcFile, destFile, x, y, cmd_file=None): def resize(src_file, dest_file, x, y, cmd_file=None):
if enableResizeImage == False: if enable_resize_image == False:
return return
if os.path.exists(srcFile) == False: if os.path.exists(src_file) == False:
debug.error("Request a resize an image that does not existed : '" + srcFile + "'") debug.error("Request a resize an image that does not existed : '" + src_file + "'")
cmd_line = "resize Image : " + srcFile + " ==> " + destFile + " newSize=(" + str(x) + "x" + str(y) + ")" cmd_line = "resize Image : " + src_file + " ==> " + dest_file + " newSize=(" + str(x) + "x" + str(y) + ")"
if False==depend.need_re_build(destFile, srcFile, file_cmd=cmd_file , cmdLine=cmd_line): if False==depend.need_re_build(dest_file, src_file, file_cmd=cmd_file , cmd_line=cmd_line):
return return
# add cmdLine ... # add cmdLine ...
x = get_pow_2_multiple(x) x = get_pow_2_multiple(x)
extension = destFile[destFile.rfind('.'):] extension = dest_file[dest_file.rfind('.'):]
if platform.system() == "Darwin": if platform.system() == "Darwin":
source_image = CoreGraphics.CGImageImport(CoreGraphics.CGDataProviderCreateWithFilename(srcFile)) source_image = CoreGraphics.CGImageImport(CoreGraphics.CGDataProviderCreateWithFilename(src_file))
source_width = source_image.getWidth() source_width = source_image.getWidth()
source_height = source_image.getHeight() source_height = source_image.getHeight()
if source_width <= x: if source_width <= x:
# for small image just copy: # for small image just copy:
tools.copy_file(srcFile, destFile) tools.copy_file(src_file, dest_file)
else: else:
if y <= 0: if y <= 0:
# keep ratio : # keep ratio :
y = int(float(x) * float(source_height) / float(source_width)) y = int(float(x) * float(source_height) / float(source_width))
y = get_pow_2_multiple(y) y = get_pow_2_multiple(y)
debug.print_element("resize Image (" + str(x) + "x" + str(y) + ")", srcFile, "==>", destFile) debug.print_element("resize Image (" + str(x) + "x" + str(y) + ")", src_file, "==>", dest_file)
debug.debug("Resize image: " + srcFile + " size=(" + str(source_width) + "x" + str(source_height) + ") -> (" + str(x) + "x" + str(y) + ")") debug.debug("Resize image: " + src_file + " size=(" + str(source_width) + "x" + str(source_height) + ") -> (" + str(x) + "x" + str(y) + ")")
source_image_rect = CoreGraphics.CGRectMake(0, 0, source_width, source_height) source_image_rect = CoreGraphics.CGRectMake(0, 0, source_width, source_height)
new_image = source_image.createWithImageInRect(source_image_rect) new_image = source_image.createWithImageInRect(source_image_rect)
colors_space = CoreGraphics.CGColorSpaceCreateDeviceRGB() colors_space = CoreGraphics.CGColorSpaceCreateDeviceRGB()
@ -67,27 +67,27 @@ def resize(srcFile, destFile, x, y, cmd_file=None):
context.setInterpolationQuality(CoreGraphics.kCGInterpolationHigh) context.setInterpolationQuality(CoreGraphics.kCGInterpolationHigh)
new_image_rect = CoreGraphics.CGRectMake(0, 0, x, y) new_image_rect = CoreGraphics.CGRectMake(0, 0, x, y)
context.drawImage(new_image_rect, new_image) context.drawImage(new_image_rect, new_image)
tools.create_directory_of_file(destFile) tools.create_directory_of_file(dest_file)
if extension == ".jpeg": if extension == ".jpeg":
context.writeToFile(destFile, CoreGraphics.kCGImageFormatJPEG) context.writeToFile(dest_file, CoreGraphics.kCGImageFormatJPEG)
elif extension == ".png": elif extension == ".png":
context.writeToFile(destFile, CoreGraphics.kCGImageFormatPNG) context.writeToFile(dest_file, CoreGraphics.kCGImageFormatPNG)
else: else:
debug.error(" can not manage extention ... : " + destFile) debug.error(" can not manage extention ... : " + dest_file)
else: else:
# open an image file (.bmp,.jpg,.png,.gif) you have in the working path # open an image file (.bmp,.jpg,.png,.gif) you have in the working path
im1 = Image.open(srcFile) im1 = Image.open(src_file)
if im1.size[0] <= x: if im1.size[0] <= x:
# for small image just copy: # for small image just copy:
tools.copy_file(srcFile, destFile) tools.copy_file(src_file, dest_file)
else: else:
if y <= 0: if y <= 0:
# keep ratio : # keep ratio :
y = int(float(x) * float(im1.size[1]) / float(im1.size[0])) y = int(float(x) * float(im1.size[1]) / float(im1.size[0]))
y = get_pow_2_multiple(y) y = get_pow_2_multiple(y)
debug.print_element("resize Image (" + str(x) + "x" + str(y) + ")", srcFile, "==>", destFile) debug.print_element("resize Image (" + str(x) + "x" + str(y) + ")", src_file, "==>", dest_file)
# use one of these filter options to resize the image # use one of these filter options to resize the image
tmpImage = im1.resize((x, y), Image.ANTIALIAS) tmpImage = im1.resize((x, y), Image.ANTIALIAS)
tools.create_directory_of_file(destFile) tools.create_directory_of_file(dest_file)
tmpImage.save(destFile) tmpImage.save(dest_file)
multiprocess.store_command(cmd_line, cmd_file) tools.store_command(cmd_line, cmd_file)

View File

@ -18,6 +18,7 @@ from . import debug
from . import heritage from . import heritage
from . import builder from . import builder
from . import multiprocess from . import multiprocess
from . import image
class Module: class Module:
@ -151,7 +152,7 @@ class Module:
if sizeX > 0: if sizeX > 0:
debug.verbose("Image file : " + display_source + " ==> " + destination + " resize=(" + str(sizeX) + "," + str(sizeY) + ")") debug.verbose("Image file : " + display_source + " ==> " + destination + " resize=(" + str(sizeX) + "," + str(sizeY) + ")")
fileName, fileExtension = os.path.splitext(os.path.join(self.origin_path,source)) fileName, fileExtension = os.path.splitext(os.path.join(self.origin_path,source))
image.resize(source, os.path.join(target.get_build_path_data(self.name), dst), sizeX, sizeY, file_cmd) image.resize(source, os.path.join(target.get_build_path_data(self.name), destination), sizeX, sizeY, file_cmd)
else: else:
debug.verbose("Might copy file : " + display_source + " ==> " + destination) debug.verbose("Might copy file : " + display_source + " ==> " + destination)
tools.copy_file(source, os.path.join(target.get_build_path_data(self.name), destination), file_cmd) tools.copy_file(source, os.path.join(target.get_build_path_data(self.name), destination), file_cmd)
@ -376,7 +377,7 @@ class Module:
# -- Sources compilation -- # -- Sources compilation --
# ---------------------------------------------------- # ----------------------------------------------------
if self.type != 'PREBUILD': if self.type != 'PREBUILD':
# build local sources in a specific order : # build local sources in a specific order:
for extention_local in self.extention_order_build: for extention_local in self.extention_order_build:
list_file = tools.filter_extention(self.src, [extention_local]) list_file = tools.filter_extention(self.src, [extention_local])
for file in list_file: for file in list_file:
@ -385,13 +386,13 @@ class Module:
try: try:
tmp_builder = builder.get_builder(fileExt); tmp_builder = builder.get_builder(fileExt);
res_file = tmp_builder.compile(file, res_file = tmp_builder.compile(file,
package_name, package_name,
target, target,
self.sub_heritage_list, self.sub_heritage_list,
flags = self.flags, flags = self.flags,
path = self.path, path = self.path,
name = self.name, name = self.name,
basic_path = self.origin_path) basic_path = self.origin_path)
if res_file["action"] == "add": if res_file["action"] == "add":
list_sub_file_needed_to_build.append(res_file["file"]) list_sub_file_needed_to_build.append(res_file["file"])
elif res_file["action"] == "path": elif res_file["action"] == "path":
@ -480,35 +481,57 @@ class Module:
elif self.type == 'BINARY' \ elif self.type == 'BINARY' \
or self.type == 'BINARY_SHARED' \ or self.type == 'BINARY_SHARED' \
or self.type == 'BINARY_STAND_ALONE': or self.type == 'BINARY_STAND_ALONE':
try: shared_mode = False
tmp_builder = builder.get_builder_with_output("bin"); if target.name=="Android":
parents = { 'src':[], debug.warning("Android mode ...")
'dynamic':[], # special case for android ...
'static':[] for elem in self.sub_heritage_list.src['src']:
} debug.warning(" " + elem[-4:])
parents_dynamic = [] if elem[-4:] == '.jar':
parents_static = [] # abstract GUI interface ...
#extract libs ... shared_mode = True
for elem in self.sub_heritage_list.src: break;
if elem[-len(target.suffix_lib_static):] == target.suffix_lib_static: if shared_mode == True:
parents_static.append(elem) try:
elif elem[-len(target.suffix_lib_dynamic):] == target.suffix_lib_dynamic: tmp_builder = builder.get_builder_with_output("so");
parents_dynamic.append(elem) list_file = tools.filter_extention(list_sub_file_needed_to_build, tmp_builder.get_input_type())
else: res_file = tmp_builder.link(list_file,
parents['src'].append(elem) package_name,
target,
static_mode = True self.sub_heritage_list,
if self.type == 'BINARY_SHARED': name = self.name,
static_mode = False basic_path = self.origin_path)
res_file = tmp_builder.link(list_sub_file_needed_to_build, self.local_heritage.add_sources(res_file)
package_name, except ValueError:
target, debug.error(" UN-SUPPORTED link format: '.so'")
self.sub_heritage_list, try:
name = self.name, tmp_builder = builder.get_builder_with_output("jar");
basic_path = self.origin_path, list_file = tools.filter_extention(list_sub_file_needed_to_build, tmp_builder.get_input_type())
static = static_mode) if len(list_file) > 0:
except ValueError: res_file = tmp_builder.link(list_file,
debug.error(" UN-SUPPORTED link format: '.bin'") package_name,
target,
self.sub_heritage_list,
name = self.name,
basic_path = self.origin_path)
self.local_heritage.add_sources(res_file)
except ValueError:
debug.error(" UN-SUPPORTED link format: '.jar'")
else:
try:
tmp_builder = builder.get_builder_with_output("bin");
static_mode = True
if self.type == 'BINARY_SHARED':
static_mode = False
res_file = tmp_builder.link(list_sub_file_needed_to_build,
package_name,
target,
self.sub_heritage_list,
name = self.name,
basic_path = self.origin_path,
static = static_mode)
except ValueError:
debug.error(" UN-SUPPORTED link format: '.bin'")
elif self.type == "PACKAGE": elif self.type == "PACKAGE":
if target.name=="Android": if target.name=="Android":
# special case for android wrapper: # special case for android wrapper:

View File

@ -18,7 +18,6 @@ from . import heritage
from . import tools from . import tools
from . import module from . import module
from . import system from . import system
from . import image
from . import multiprocess from . import multiprocess
class Target: class Target:
@ -187,39 +186,6 @@ class Target:
def get_build_mode(self): def get_build_mode(self):
return self.config["mode"] return self.config["mode"]
## @deprecated ...
def add_image_staging(self, inputFile, outputFile, sizeX, sizeY, cmdFile=None):
for source, dst, x, y, cmdFile2 in self.list_final_file:
if dst == outputFile :
debug.verbose("already added : " + outputFile)
return
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'")
self.list_final_file.append([inputFile,outputFile, sizeX, sizeY, cmdFile])
## @deprecated ...
def add_file_staging(self, inputFile, outputFile, cmdFile=None):
for source, dst, x, y, cmdFile2 in self.list_final_file:
if dst == outputFile :
debug.verbose("already added : " + outputFile)
return
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'");
self.list_final_file.append([inputFile, outputFile, -1, -1, cmdFile])
## @deprecated ...
def copy_to_staging(self, binary_name):
base_path = self.get_staging_path_data(binary_name)
for source, dst, x, y, cmdFile in self.list_final_file:
if cmdFile != None \
and cmdFile != "":
debug.verbose("cmd file " + cmdFile)
if x == -1:
debug.verbose("must copy file : '" + source + "' ==> '" + dst + "'");
tools.copy_file(source, os.path.join(base_path, dst), cmdFile)
else:
debug.verbose("resize image : '" + source + "' ==> '" + dst + "' size=(" + str(x) + "," + str(y) + ")");
image.resize(source, os.path.join(base_path, dst), x, y, cmdFile)
def clean_module_tree(self): def clean_module_tree(self):
self.build_tree_done = [] self.build_tree_done = []
self.list_final_file = [] self.list_final_file = []

View File

@ -45,7 +45,7 @@ def compile(file, binary, target, depancy, flags, path, name, basic_path):
# create the command line befor requesting start: # create the command line befor requesting start:
cmd = [ cmd = [
target.java, target.java,
"-d", target.get_build_path(name) "-d", target.get_build_path_object(name)
] ]
# add source dependency: # add source dependency:
list_sources_path = [] list_sources_path = []