[DEV] compile java file only when needed and change basic version of sdk (15, 14 has been removed)

This commit is contained in:
Edouard DUPIN 2015-09-16 23:51:23 +02:00
parent 06481abcbf
commit dc921d651b
10 changed files with 102 additions and 25 deletions

View File

@ -11,6 +11,18 @@ import os
from . import debug from . import debug
from . import env from . import env
def _create_directory_of_file(file):
path = os.path.dirname(file)
try:
os.stat(path)
except:
os.makedirs(path)
def _file_write_data(path, data):
file = open(path, "w")
file.write(data)
file.close()
def _file_size(path): def _file_size(path):
if not os.path.isfile(path): if not os.path.isfile(path):
return 0 return 0
@ -28,6 +40,12 @@ def _file_read_data(path, binary=False):
file.close() file.close()
return data_file return data_file
def create_dependency_file(depend_file, list_files):
data = ""
for elem in list_files:
data += elem + "\n"
_create_directory_of_file(depend_file)
_file_write_data(depend_file, data)
def need_re_build(dst, src, depend_file=None, file_cmd="", cmd_line="", force_identical=False): def need_re_build(dst, src, depend_file=None, file_cmd="", cmd_line="", force_identical=False):
debug.extreme_verbose("Request check of dependency of :") debug.extreme_verbose("Request check of dependency of :")
@ -47,14 +65,16 @@ def need_re_build(dst, src, depend_file=None, file_cmd="", cmd_line="", force_id
and os.path.exists(dst) == False: and os.path.exists(dst) == False:
debug.extreme_verbose(" ==> must rebuild (dst does not exist)") debug.extreme_verbose(" ==> must rebuild (dst does not exist)")
return True return True
if dst != "" \ if src != "" \
and dst != None \ and src != None \
and os.path.exists(src) == False: and os.path.exists(src) == False:
debug.warning(" ==> unexistant file :'" + src + "'") debug.warning(" ==> unexistant file :'" + src + "'")
return True return True
# Check the basic date if the 2 files # Check the basic date if the 2 files
if dst != "" \ if dst != "" \
and dst != None \ and dst != None \
and src != "" \
and src != None \
and os.path.getmtime(src) > os.path.getmtime(dst): and os.path.getmtime(src) > os.path.getmtime(dst):
debug.extreme_verbose(" ==> must rebuild (source time greater)") debug.extreme_verbose(" ==> must rebuild (source time greater)")
return True return True

View File

@ -296,7 +296,6 @@ class Module:
tmp_file.write(' }, {\n') tmp_file.write(' }, {\n')
val += 1 val += 1
tmp_file.write(' "file":"' + elem[0] + '",\n') tmp_file.write(' "file":"' + elem[0] + '",\n')
#tmp_file.write(' "coverage":' + str(elem[1]) + ',\n')
tmp_file.write(' "executed":' + str(elem[2]) + ',\n') tmp_file.write(' "executed":' + str(elem[2]) + ',\n')
tmp_file.write(' "executable":' + str(elem[3]) + '\n') tmp_file.write(' "executable":' + str(elem[3]) + '\n')
tmp_file.write(' }\n') tmp_file.write(' }\n')
@ -392,7 +391,8 @@ class Module:
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,
module_src = self.src)
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":
@ -415,7 +415,8 @@ class Module:
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,
module_src = self.src)
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":

View File

@ -22,6 +22,7 @@ import shlex
from . import debug from . import debug
from . import tools from . import tools
from . import env from . import env
from . import depend
queueLock = threading.Lock() queueLock = threading.Lock()
workQueue = queue.Queue() workQueue = queue.Queue()
@ -70,7 +71,7 @@ def run_command_direct(cmd_line):
return False return False
def run_command(cmd_line, store_cmd_line="", build_id=-1, file="", store_output_file=""): def run_command(cmd_line, store_cmd_line="", build_id=-1, file="", store_output_file="", depend_data=None):
global errorOccured global errorOccured
global exitFlag global exitFlag
global currentIdExecution global currentIdExecution
@ -95,6 +96,8 @@ def run_command(cmd_line, store_cmd_line="", build_id=-1, file="", store_output_
if p.returncode == 0: if p.returncode == 0:
debug.debug(env.print_pretty(cmd_line)) debug.debug(env.print_pretty(cmd_line))
queueLock.acquire() queueLock.acquire()
if depend_data != None:
depend.create_dependency_file(depend_data['file'], depend_data['data'])
# TODO : Print the output all the time .... ==> to show warnings ... # TODO : Print the output all the time .... ==> to show warnings ...
if build_id >= 0 and (output != "" or err != ""): if build_id >= 0 and (output != "" or err != ""):
debug.warning("output in subprocess compiling: '" + file + "'") debug.warning("output in subprocess compiling: '" + file + "'")
@ -163,7 +166,7 @@ class myThread(threading.Thread):
cmdLine = data[1] cmdLine = data[1]
cmdStoreFile = data[3] cmdStoreFile = data[3]
debug.print_element( "[" + str(data[4]) + "][" + str(self.thread_id) + "] " + comment[0], comment[1], comment[2], comment[3]) debug.print_element( "[" + str(data[4]) + "][" + str(self.thread_id) + "] " + comment[0], comment[1], comment[2], comment[3])
run_command(cmdLine, cmdStoreFile, build_id=data[4], file=comment[3], store_output_file=data[5]) run_command(cmdLine, cmdStoreFile, build_id=data[4], file=comment[3], store_output_file=data[5], depend_data=data[6])
else: else:
debug.warning("unknow request command : " + data[0]) debug.warning("unknow request command : " + data[0])
else: else:
@ -218,18 +221,18 @@ def un_init():
def run_in_pool(cmd_line, comment, store_cmd_line="", store_output_file=""): def run_in_pool(cmd_line, comment, store_cmd_line="", store_output_file="", depend_data=None):
global currentIdExecution global currentIdExecution
if processorAvaillable <= 1: if processorAvaillable <= 1:
debug.print_element(comment[0], comment[1], comment[2], comment[3]) debug.print_element(comment[0], comment[1], comment[2], comment[3])
run_command(cmd_line, store_cmd_line, file=comment[3], store_output_file=store_output_file) run_command(cmd_line, store_cmd_line, file=comment[3], store_output_file=store_output_file, depend_data=depend_data)
return return
# multithreaded mode # multithreaded mode
init() init()
# Fill the queue # Fill the queue
queueLock.acquire() queueLock.acquire()
debug.verbose("add : in pool cmdLine") debug.verbose("add : in pool cmdLine")
workQueue.put(["cmdLine", cmd_line, comment, store_cmd_line, currentIdExecution, store_output_file]) workQueue.put(["cmdLine", cmd_line, comment, store_cmd_line, currentIdExecution, store_output_file, depend_data])
currentIdExecution +=1; currentIdExecution +=1;
queueLock.release() queueLock.release()

View File

@ -40,7 +40,7 @@ def get_output_type():
## ##
## @brief Commands for running gcc to compile a C file in object file. ## @brief Commands for running gcc to compile a C file in object file.
## ##
def compile(file, binary, target, depancy, flags, path, name, basic_path): def compile(file, binary, target, depancy, flags, path, name, basic_path, module_src):
file_src = target.get_full_name_source(basic_path, file) file_src = target.get_full_name_source(basic_path, file)
file_cmd = target.get_full_name_cmd(name, basic_path, file) file_cmd = target.get_full_name_cmd(name, basic_path, file)
file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type()) file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type())

View File

@ -39,7 +39,7 @@ def get_output_type():
## ##
## @brief Commands for running gcc to compile a C++ file in object file. ## @brief Commands for running gcc to compile a C++ file in object file.
## ##
def compile(file, binary, target, depancy, flags, path, name, basic_path): def compile(file, binary, target, depancy, flags, path, name, basic_path, module_src):
file_src = target.get_full_name_source(basic_path, file) file_src = target.get_full_name_source(basic_path, file)
file_cmd = target.get_full_name_cmd(name, basic_path, file) file_cmd = target.get_full_name_cmd(name, basic_path, file)
file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type()) file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type())

View File

@ -33,15 +33,40 @@ def get_input_type():
def get_output_type(): def get_output_type():
return ["class"] return ["class"]
def create_dependency_files(target, src, heritage_src, basic_path):
depend = []
for elem in src:
extention = elem.split('.')[-1]
if extention == 'jar' \
or extention == 'java':
debug.extreme_verbose("add java depedence ... " + elem)
depend.append(target.get_full_name_source(basic_path, elem))
for elem in heritage_src:
extention = elem.split('.')[-1]
if extention == 'jar' \
or extention == 'java':
debug.extreme_verbose("add java depedence ... " + elem)
depend.append(elem)
return depend
## ##
## @brief Commands for running gcc to compile a C++ file in object file. ## @brief Commands for running gcc to compile a C++ file in object file.
## ##
def compile(file, binary, target, depancy, flags, path, name, basic_path): def compile(file, binary, target, depancy, flags, path, name, basic_path, module_src):
file_src = target.get_full_name_source(basic_path, file) file_src = target.get_full_name_source(basic_path, file)
file_cmd = target.get_full_name_cmd(name, basic_path, file) file_cmd = target.get_full_name_cmd(name, basic_path, file)
file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type(), remove_suffix=True) file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type(), remove_suffix=True)
file_depend = target.get_full_dependency(name, basic_path, file) file_depend = target.get_full_dependency(name, basic_path, file)
file_warning = target.get_full_name_warning(name, basic_path, file) file_warning = target.get_full_name_warning(name, basic_path, file)
depend_files = create_dependency_files(target, module_src, depancy.src['src'], basic_path)
"""
debug.warning("file_src = " + file_src)
debug.warning("file_cmd = " + file_cmd)
debug.warning("file_dst = " + file_dst)
debug.warning("file_depend = " + file_depend)
debug.warning("file_warning = " + file_warning)
"""
# create the command line befor requesting start: # create the command line befor requesting start:
cmd = [ cmd = [
target.java, target.java,
@ -88,6 +113,11 @@ def compile(file, binary, target, depancy, flags, path, name, basic_path):
tools.create_directory_of_file(file_dst) tools.create_directory_of_file(file_dst)
comment = ["java", name, "<==", file] comment = ["java", name, "<==", file]
#process element #process element
multiprocess.run_in_pool(cmdLine, comment, file_cmd, store_output_file=file_warning) multiprocess.run_in_pool(cmdLine,
comment,
file_cmd,
store_output_file = file_warning,
depend_data = {"file":file_depend,
"data":depend_files})
return {"action":"add", "file":file_dst} return {"action":"add", "file":file_dst}

View File

@ -33,15 +33,33 @@ def get_input_type():
def get_output_type(): def get_output_type():
return ["h"] return ["h"]
def create_dependency_files(target, src, heritage_src, basic_path):
depend = []
for elem in src:
extention = elem.split('.')[-1]
if extention == 'jar' \
or extention == 'java':
debug.extreme_verbose("add java depedence ... " + elem)
depend.append(target.get_full_name_source(basic_path, elem))
for elem in heritage_src:
extention = elem.split('.')[-1]
if extention == 'jar' \
or extention == 'java':
debug.extreme_verbose("add java depedence ... " + elem)
depend.append(elem)
return depend
## ##
## @brief Commands for running gcc to compile a C++ file in object file. ## @brief Commands for running gcc to compile a C++ file in object file.
## ##
def compile(file, binary, target, depancy, flags, path, name, basic_path): def compile(file, binary, target, depancy, flags, path, name, basic_path, module_src):
# file_src = target.get_full_name_source(basic_path, file) # file_src = target.get_full_name_source(basic_path, file)
file_cmd = target.get_full_name_cmd(name, basic_path, file) file_cmd = target.get_full_name_cmd(name, basic_path, file)
# file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type()) # file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type())
file_depend = target.get_full_dependency(name, basic_path, file) file_depend = target.get_full_dependency(name, basic_path, file)
file_warning = target.get_full_name_warning(name, basic_path, file) file_warning = target.get_full_name_warning(name, basic_path, file)
depend_files = create_dependency_files(target, module_src, depancy.src['src'], basic_path)
# create the command line befor requesting start: # create the command line befor requesting start:
cmd = [ cmd = [
target.javah, target.javah,
@ -52,20 +70,25 @@ def compile(file, binary, target, depancy, flags, path, name, basic_path):
cmd.append("-verbose") cmd.append("-verbose")
cmd.append("-classpath") cmd.append("-classpath")
cmd.append(target.get_build_path(name)) cmd.append(target.get_build_path_object(name))
class_to_build = file[:-6] class_to_build = file[:-6]
cmd.append(class_to_build) cmd.append(class_to_build)
# Create cmd line # Create cmd line
cmdLine=tools.list_to_str(cmd) cmd_line = tools.list_to_str(cmd)
file_dst = target.get_build_path(name) + "/tmp_header/" + class_to_build.replace(".", "_") + ".h" file_dst = target.get_build_path(name) + "/generate_header/" + class_to_build.replace(".", "_") + ".h"
# check the dependency for this file : # check the dependency for this file :
#if depend.need_re_build(file_dst, file_src, file_depend, file_cmd, cmdLine) == False: if depend.need_re_build(file_dst, None, file_depend, file_cmd, cmd_line) == False:
# return file_dst return {"action":"path", "path":target.get_build_path(name) + target.path_generate_code}
#tools.create_directory_of_file(file_dst) #tools.create_directory_of_file(file_dst)
comment = ["javah", class_to_build.replace(".", "_") + ".h", "<==", class_to_build] comment = ["javah", class_to_build.replace(".", "_") + ".h", "<==", class_to_build]
#process element #process element
multiprocess.run_in_pool(cmdLine, comment, file_cmd, store_output_file=file_warning) multiprocess.run_in_pool(cmd_line,
comment,
file_cmd,
store_output_file = file_warning,
depend_data = {"file":file_depend,
"data":depend_files})
debug.verbose("file= " + file_dst) debug.verbose("file= " + file_dst)
#return file_dst #return file_dst
return {"action":"path", "path":target.get_build_path(name) + target.path_generate_code} return {"action":"path", "path":target.get_build_path(name) + target.path_generate_code}

View File

@ -41,7 +41,7 @@ def get_output_type():
## ##
## @brief Commands for running gcc to compile a m file in object file. ## @brief Commands for running gcc to compile a m file in object file.
## ##
def compile(file, binary, target, depancy, flags, path, name, basic_path): def compile(file, binary, target, depancy, flags, path, name, basic_path, module_src):
file_src = target.get_full_name_source(basic_path, file) file_src = target.get_full_name_source(basic_path, file)
file_cmd = target.get_full_name_cmd(name, basic_path, file) file_cmd = target.get_full_name_cmd(name, basic_path, file)
file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type()) file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type())

View File

@ -41,7 +41,7 @@ def get_output_type():
## ##
## @brief Commands for running gcc to compile a m++ file in object file. ## @brief Commands for running gcc to compile a m++ file in object file.
## ##
def compile(file, binary, target, depancy, flags, path, name, basic_path): def compile(file, binary, target, depancy, flags, path, name, basic_path, module_src):
file_src = target.get_full_name_source(basic_path, file) file_src = target.get_full_name_source(basic_path, file)
file_cmd = target.get_full_name_cmd(name, basic_path, file) file_cmd = target.get_full_name_cmd(name, basic_path, file)
file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type()) file_dst = target.get_full_name_destination(name, basic_path, file, get_output_type())

View File

@ -83,8 +83,8 @@ class Target(target.Target):
#self.path_doc="/doc" #self.path_doc="/doc"
#self.suffix_package='.pkg' #self.suffix_package='.pkg'
# board id at 14 is for android 4.0 and more ... # board id at 15 is for android 4.0.3 and more ... (note: API 14 has been removed ...)
self.boardId = 14 self.boardId = 15
self.global_flags_cc.append("-D__ANDROID_BOARD_ID__=" + str(self.boardId)) self.global_flags_cc.append("-D__ANDROID_BOARD_ID__=" + str(self.boardId))
if arch == "armv5" or arch == "armv7": if arch == "armv5" or arch == "armv7":
self.global_include_cc.append("-I" + self.path_ndk +"/platforms/android-" + str(self.boardId) + "/arch-arm/usr/include/") self.global_include_cc.append("-I" + self.path_ndk +"/platforms/android-" + str(self.boardId) + "/arch-arm/usr/include/")