#!/usr/bin/env python import sys import re import os import copy # DL sources: # http://www.boost.org/users/history/ # https://dl.bintray.com/boostorg/release/1.66.0/source/ # ./bootstrap.sh # ./b2 -a -n -j1 > ../build.txt # grep -nriE "(g\+\+|/bin/ar)" ../build.txt > ../build2.txt # ./parseBuildOutputToLutin.py build.txt boost build_output_file = sys.argv[1] global_lib_name = sys.argv[2] 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): #create_directory_of_file(path) file = open(path, "w") file.write(data) file.close() return True list_of_library_generated = [] def genrate_version(version): file_write_data("version.txt", version); list_of_flags_default = { "c":[], "cpp":[], "S":[] } def genrate_lutin_file(lib_name, list_of_files, list_of_flags): tmp_base = "lib" + global_lib_name + "_" if len(lib_name) > len(tmp_base)\ and lib_name[:len(tmp_base)] == tmp_base: lib_name = lib_name[len(tmp_base):] lib_name = global_lib_name + "-" + lib_name; list_of_library_generated.append(lib_name.replace("_","-")) # remove all unneeded element flags: #-I list_of_include = copy.deepcopy(list_of_flags_default) # -D list_of_define = copy.deepcopy(list_of_flags_default) # other list_of_other = [] # dependency: list_of_dependency = [] #print("list of flags: ") for type in ["c", "cpp", "S"]: for elem in list_of_flags[type]: if elem in ["-m64", "-O3", "-O2", "-O1", "-O0", "-fPIC"]: continue if elem == "-pthread": list_of_dependency.append("pthread") continue if elem in ["-fabi-version=0", '-I"/usr/include"']: # just remove it .. continue if elem[:2] == "-D": #print("DEFINE: " + elem) list_of_define[type].append(elem) continue if elem[:2] == "-I": if elem == '-I"."' \ or elem == '-I.': continue if elem[:9] in '-I"bin.v2': continue if elem[:4] in '-I"/': if "/usr/include/python3.6" == elem[3:-1]: list_of_include[type].append(elem[3:-1]+"m") # TODO: depend on python lib else: list_of_include[type].append(elem[3:-1]) continue # TODO : Do it better : print("INCLUDE: " + elem ) if os.path.isdir(global_lib_name + "/" + global_lib_name + "/" +elem[3:-1]): list_of_include[type].append(global_lib_name + "/" + global_lib_name + "/" +elem[3:-1]) else: list_of_include[type].append(global_lib_name + "/" +elem[3:-1]) continue if elem[:2] in '-l': list_of_dependency.append(elem[2:]) continue #print("???: " + elem) list_of_other.append(elem) out = ""; out += "{\n"; out += " \"type\":\"LIBRARY\",\n"; out += " \"group-id\":\"org." + global_lib_name + "\",\n"; out += " \"description\":\"" + global_lib_name + ":" + lib_name.replace("_","-") + " library\",\n"; out += " \"license\":\"boost-v1.0\",\n"; out += " \"license-file\":\"file://boost/LICENSE_1_0.txt\",\n"; #out += " \"maintainer\":\"UNKNOW\",\n"; #out += " \"author\":\"UNKNOW\",\n"; out += " \"version\":\"file://version.txt\",\n"; if len(list_of_files) != 0: out += " \"source\": [\n"; start = False; for item in list_of_files: if start: out += ",\n"; start = True; out += " \"" + global_lib_name + "/" + item +"\""; out += "\n"; out += " ],\n"; out += " \"compilation-version\": {\n"; out += " \"c++\": 2011\n"; out += " },\n"; count_flags = 0; for type in ["c", "cpp", "S"]: count_flags += len(list_of_define[type]); count_flags += len(list_of_other) if count_flags != 0: out += " \"flag\": {\n"; start_group = False; c_already_done = False; for type in ["c", "cpp", "S"]: start = False; if len(list_of_define[type]) != 0: if start_group: out += ",\n"; start_group = True; if type == "cpp": out += " \"c++\": [\n" elif type == "S": out += " \"s\": [\n" else: out += " \"" + type + "\": [\n" for item in list_of_define[type]: if start: out += ",\n"; start = True; out += " \"" + item +"\"" if "c" == type: c_already_done = True; for item in list_of_other: if start: out += ",\n"; start = True; out += " \"" + item +"\""; out += "\n"; out += " ]" if len(list_of_other) != count_flags: out += ",\n" if c_already_done == False: out += " \"c\": [\n" for item in list_of_other: if start: out += ",\n"; start = True; out += " \"" + item +"\""; out += "\n"; out += " ]" else: out += "\n" out += "\n"; out += " },\n"; count_flags = 0; for type in ["c", "cpp", "S"]: count_flags += len(list_of_include[type]); if count_flags != 0: out += " \"path\": {\n"; start_group = False; for type in ["c", "cpp", "S"]: if len(list_of_include[type]) != 0: if start_group: out += ",\n"; start_group = True; if type == "cpp": out += " \"c++\": [\n" elif type == "S": out += " \"s\": [\n" else: out += " \"" + type + "\": [\n" start = False; for item in list_of_include[type]: if start: out += ",\n"; start = True; out += " \"" + item +"\"" out += "\n"; out += " ]" out += "\n"; out += " },\n"; out += " \"dependency\": [\n"; out += " \"z\",\n"; out += " \"m\",\n"; out += " \"" + global_lib_name + "-include\""; for item in list_of_dependency: out += ",\n"; out += " \"" + item +"\"" out += "\n"; out += " ]\n"; out += "}\n" file_write_data("GLD_" + lib_name.replace("_","-") + ".json", out); def generate_global_include_module(): out = ""; out += "{\n"; out += " \"type\":\"LIBRARY\",\n"; out += " \"group-id\":\"org." + global_lib_name + "\",\n"; out += " \"description\":\"" + global_lib_name + " include library\",\n"; out += " \"licence\":\"boost-v1.0\",\n"; out += " \"licence-file\":\"file://boost/LICENCE_1_0.txt\",\n"; #out += " \"maintainer\":\"UNKNOW\",\n"; #out += " \"author\":\"UNKNOW\",\n"; out += " \"version\":\"file://version.txt\",\n"; out += " \"compilation-version\": {\n"; out += " \"c++\": 2011\n"; out += " },\n"; out += " \"header\":[\n"; out += " {\n"; out += " \"path\":\"" + global_lib_name + "/" + global_lib_name + "/*\",\n"; out += " \"recursive\":true,\n"; out += " \"to\":\"" + global_lib_name + "\"\n"; out += " }\n"; out += " ]\n"; out += "}\n"; file_write_data("GLD_" + global_lib_name + "-include.json", out); def generate_global_module(list_of_module): out = "" out += "{\n"; out += " \"type\":\"PACKAGE\",\n"; out += " \"group-id\":\"org." + global_lib_name + "\",\n"; out += " \"description\":\"" + global_lib_name + " PACKAGE library\",\n"; out += " \"licence\":\"boost-v1.0\",\n"; out += " \"licence-file\":\"file://boost/LICENCE_1_0.txt\",\n"; #out += " \"maintainer\":\"UNKNOW\",\n"; #out += " \"author\":\"UNKNOW\",\n"; out += " \"version\":\"file://version.txt\",\n"; out += " \"compilation-version\": {\n"; out += " \"c++\": 2011\n"; out += " },\n"; out += " \"dependency\": [\n"; out += " \"" + global_lib_name + "-include\"" for item in list_of_module: out += ",\n"; out += " \"" + item +"\"" out += "\n"; out += " ]\n"; out += "}\n"; file_write_data("GLD_" + global_lib_name + ".json", out); with open(build_output_file) as commit: lines = commit.readlines() if len(lines) == 0: print("Empty build ....") sys.exit(1) list_of_file = [] list_of_flags = copy.deepcopy(list_of_flags_default) # first line for line in lines: #print("line : " + line[-6:-2]) """ if len(line) > 6 \ and line[-6:-2] == ".cpp": print("element : " + line) """ # "g++" -O3 -finline-functions -Wno-inline -Wall -pthread -m64 -DBOOST_ALL_NO_LIB=1 -DBOOST_THREAD_USE_LIB=1 -DNDEBUG -I"." -c -o "bin.v2/lib*.o m = re.search('^(.*)"(g\+\+|gcc|clang)"(.*) \-c \-o (.*)\.o" "((.*)\.(cpp|c|cxx|S))"$', line) if m != None: """ print("element : " + str(len(m.groups()))) for elem in m.groups(): print(" " + elem) """ if len(m.groups()) == 7: #print("element : " + line) ## print(" value : " + m.groups()[1]) type_of_file = m.groups()[4].split(".")[-1] for flag in m.groups()[2].split(" "): if flag in ["", "-x", "c", "assembler-with-cpp"]: continue if "assembler-with-cpp" == flag: print("element : " + line) if flag not in list_of_flags[type_of_file]: #print(" " + flag) list_of_flags[type_of_file].append(flag) list_of_file.append(m.groups()[4]) continue m = re.search('^(.*)/usr/bin/ar"(.*)"((.*)/([a-zA-Z0-9_\-.]*)\.a)"(.*)$', line) if m != None: ## we do not use AR element ==> in boost just a double compilation ... """ print("element : " + str(len(m.groups()))) for elem in m.groups(): print(" " + elem) """ if len(m.groups()) == 6: #print("element : " + line) ## print(" to: " + m.groups()[4] + " (.a)") # Remove it only keep the .so list_of_file = [] list_of_flags = copy.deepcopy(list_of_flags_default) continue # ln -f -s 'libboost_wave.so.1.66.0' 'stage/lib/libboost_wave.so' #"g++" -o "bin.v2/libs/type_erasure/build/gcc-gnu-7.2.1/release/threadapi-pthread/threading-multi/libboost_type_erasure.so.1.66.0" -Wl,-h -Wl,libboost_type_erasure.so.1.66.0 -shared -Wl,--start-group "bin.v2/libs/type_erasure/build/gcc-gnu-7.2.1/release/threadapi-pthread/threading-multi/dynamic_binding.o" "bin.v2/libs/thread/build/gcc-gnu-7.2.1/release/threadapi-pthread/threading-multi/libboost_thread.so.1.66.0" "bin.v2/libs/chrono/build/gcc-gnu-7.2.1/release/threadapi-pthread/threading-multi/libboost_chrono.so.1.66.0" "bin.v2/libs/system/build/gcc-gnu-7.2.1/release/threadapi-pthread/threading-multi/libboost_system.so.1.66.0" -Wl,-Bstatic -Wl,-Bdynamic -lrt -Wl,--end-group -pthread -fPIC -m64 #m = re.search('(.*/([a-zA-Z0-9_\-\.]*?)\.so)', line) m = re.search('^(.*)"(g\+\+|gcc|clang)"(.*)$', line) if m != None: #print("element : " + str(len(m.groups()))) for elem in m.groups(): #print(" " + elem) list_elem = elem.split('" "') list_elem[-1] = list_elem[-1].split('"')[0] for val in list_elem: if val[-2:] == ".o": continue lib_name = val.split('/')[-1].split(".so")[0] if lib_name[:3] == "lib": lib_name = lib_name[3:].replace("_","-") #print(" " + lib_name) list_of_flags["cpp"].append('-l' + lib_name) m = re.search('^(.*)\'((.*)/([a-zA-Z0-9_\-.]*)\.so)\'$', line) if m != None: """ print("element : " + str(len(m.groups()))) for elem in m.groups(): print(" " + elem) """ if len(m.groups()) == 4: #print("element : " + line) #print(" to: " + m.groups()[3] + " (.so)") #if "libboost_container" == m.groups()[3]: # exit(0) genrate_lutin_file(m.groups()[3], list_of_file, list_of_flags) ##for item in list_of_file: ## print(" " + item) list_of_file = [] list_of_flags = copy.deepcopy(list_of_flags_default) continue #create version file genrate_version("1.76.0") # generate a global inclue generate_global_include_module() # generate a global library generate_global_module(list_of_library_generated)