def setDefault(self): if self.getHostArch() == 'x64': self.X86_PROGRAMFILES = os.environ['ProgramFiles(x86)'] else: self.X86_PROGRAMFILES = os.environ['ProgramFiles'] cs_search_path = [ os.path.join( self.X86_PROGRAMFILES, 'Microsoft Visual Studio/2017/Professional/MSBuild/15.0/Bin/Roslyn' ), os.path.join( self.X86_PROGRAMFILES, 'Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/Roslyn' ), os.path.join(self.X86_PROGRAMFILES, 'MSBuild/14.0/Bin'), os.path.join(self.X86_PROGRAMFILES, 'MSBuild/12.0/Bin'), 'C:/Windows/Microsoft.NET/Framework64/v4.0.30319', 'C:/Windows/Microsoft.NET/Framework64/v3.5', 'C:/Windows/Microsoft.NET/Framework64/v3.0', 'C:/Windows/Microsoft.NET/Framework/v4.0.30319', 'C:/Windows/Microsoft.NET/Framework/v3.5', 'C:/Windows/Microsoft.NET/Framework/v3.0', ] csc_path = self.findPath(cs_search_path) if csc_path is None: return Log.d('Found csc.exe [%s]' % cs_search_path) self.CMD_CC = os.path.join(csc_path, 'csc.exe') self.refresh()
def signal(self): count = self.dec() Log.d(('signal %d ' + self.target) % count) if count == 0: Log.d('signal zero run preBuild ' + self.target) self.state_wait = False return self.preBuild() return 0
def __init__(self, max_thread): self.job_queue = JobQueue() self.lock = threading.Lock() self.max_thread = max_thread if max_thread == 0: #self.max_thread= os.cpu_count() self.max_thread = CpuCountLib.getCpuCount() self.thread_list = [] Log.v('Thread = %d' % self.max_thread)
def addThread(self): if len(self.thread_list) < self.max_thread: index = 0 with self.lock: index = len(self.thread_list) thread = WorkerThread(index, self.job_queue) self.thread_list.append(thread) Log.d('Start thread %d' % index) thread.start()
def dump(self): Log.p('-------------------') Log.p('SourceFile cache:') for l_name in self.cache: file = self.cache[l_name] Log.p('* %s' % l_name) for src in file.src_list: Log.p(' include "%s"' % src) Log.p('-------------------')
def completeTask(self, result_code): self.setCompleted(True) if result_code != 0: return result_code for task in self.callback_task: Log.d(' completeTask callback = ' + task.target) result_code = task.run() if result_code != 0: return result_code return 0
def preBuild(self): Log.d('Task prebuild= ' + self.target) if not os.path.exists(self.target): return self.build('not exists "%s"' % self.target) dest_time = self.tool.timestamp_cache.getTimeStamp(self.target) #print( 'TargetTime =' + str(dest_time) ) result = self.isBuild({}, dest_time) if result != None: return self.build(result) return self.completeTask(0)
def __init__(self, tool, parent=None): super().__init__(tool, parent) self.MSVC_DIR = None self.WINDOWS_SDK_DIR = None self.WINDOWS_SDK_VERSION = None self.CMD_CC = None self.CMD_LINK = None self.CMD_LIB = None if self.getHostPlatform() != 'Windows': return self.findVSPath() if self.MSVC_DIR is None: return self.SAVE_PATH = os.environ['PATH'] self.setDefault() self.ARCH_LIST = ['x64', 'x86'] if self.getUserOption('ARM', '0') == '1': if os.path.exists( os.path.join(self.MSVC_VC_DIR, 'bin/HostX64/arm64')): self.ARCH_LIST.append('arm64') if os.path.exists(os.path.join(self.MSVC_VC_DIR, 'bin/HostX64/arm')): self.ARCH_LIST.append('arm7') Log.d('MSVC = %d' % self.MSVC_VERSION) Log.d('SDK = ', self.WINDOWS_SDK_DIR) Log.d('SDK Version = ', self.WINDOWS_SDK_VERSION) Log.d('CPU Arch = ', ','.join(self.ARCH_LIST))
def dependTask(self): if len(self.task_list) != 0: for task in self.task_list: if not task.isCompleted(): self.inc() if self.task_count != 0: self.state_wait = True for task in self.task_list: if not task.isCompleted(): Log.d(' depend -> ' + task.target) task.onCompleteTask(self) self.tool.thread_pool.addJob(task) return 0 return self.preBuild()
def dump(self): Log.p('-------------------') Log.p('TimeStamp cache:') for l_name in self.cache: file_time = self.cache[l_name] ts = time.localtime(file_time) Log.p('* %s %s' % (time.strftime('%Y/%m/%d %H:%M:%S', ts), l_name)) Log.p('-------------------')
def execScript(self, file_name): try: with open(file_name, 'r', encoding='UTF-8') as fi: script = fi.read() fi.close() exec(script, { 'os': os, 'sys': sys, 'Log': Log, 'BuildUtility': BuildUtility }, { 'tool': self, 'genv': self.global_env }) except FileNotFoundError: Log.e('Script "%s" not found' % file_name) raise
def __init__(self, job_count=0, option=None): self.thread_pool = JobQueue.ThreadPool(job_count) self.timestamp_cache = Depend.TimeStampCache(self) self.source_cache = Depend.SourceFileCache(self) self.task_cache = Depend.TaskCache(self) self.global_env = PlatformCommon.TargetEnvironmentCommon(self) self.global_env.USER_OPTION = option self.platform_table = {} self.dir_stack = [] self.result_code = 0 #script_bin_path= os.path.dirname(__file__) script_bin_path = os.path.dirname(sys.argv[0]) sys.path.append(script_bin_path) StartupScript = os.path.join(script_bin_path, 'FLB_Default.py') if os.path.exists(StartupScript): self.execScript(StartupScript) Log.v(option)
def build(self, message): Log.p('ExeTask: ' + self.target) Log.v(' <== ' + message) result_code = BuildUtility.ExecCommand(self.command) if result_code == 0: Log.v(' Ok ' + self.target) return result_code
def setupHostPlatform(self): Log.d('system= ' + platform.system()) Log.d('machine= ' + platform.machine()) Log.d('processor= ' + platform.processor()) machine = platform.machine() table_arch = { 'x64': 'x64', 'AMD64': 'x64', 'x86_64': 'x64', 'x86': 'x86', 'i686': 'x86', 'i386': 'x86', 'armv8l': 'arm64', 'armv7l': 'arm7', 'armv6l': 'arm6', 'aarch64': 'arm64', 'arm64': 'arm64', } if machine in table_arch: self.HOST_ARCH = table_arch[machine] table_platform = { 'Windows': 'Windows', 'Linux': 'Linux', 'Unix': 'Linux', 'Darwin': 'macOS', } system = platform.system() if system in table_platform: self.HOST_PLATFORM = table_platform[system]
def build(self, message): Log.p('LibTask: ' + self.target) Log.v(' <== ' + message) result_code = BuildUtility.ExecCommand(self.command) self.tool.timestamp_cache.removeEntry(self.target) if result_code == 0: Log.v(' Ok ' + self.target) return result_code
def build(self, message): Log.p('ObjTask: ' + self.target) Log.v(' <== ' + message) self.env.makeOutputDirectory(self.target) result_code = BuildUtility.ExecCommand(self.command) self.tool.timestamp_cache.removeEntry(self.target) if result_code == 0: Log.v(' Ok ' + self.target) return self.completeTask(result_code)
def list(self): for l_name in self.cache: task = self.cache[l_name] Log.p('Task: "%s"' % l_name) #Log.p( ' target: %s' % task.target ) #if getattr( task, 'command', None ): # Log.p( ' cmd %s' % task.command ) for dep in task.task_list: Log.p(' --> ', dep.cache_name) for comp in task.callback_task: Log.p(' OC> ', comp.cache_name)
def run(self): while True: if self.queue.isBreak(): Log.d('Quit thread %d' % self.index) break job = self.queue.popJob() if job == None: Log.d('End thread %d' % self.index) break #print( ' Run %d' % self.index ) try: code = job.run() except BuildUtility.FLB_Error as err: Log.e(err) code = 100 except: Log.e('Exception! in thread %d' % self.index) raise if code != 0: self.queue.setBreak(code) break
def build(self, message): Log.p('ExeTask: ' + self.target) Log.v(' <== ' + message) self.env.makeOutputDirectory(self.target) #self.tool.thread_pool.addJob( CompileJob( self.tool, self.env, self.command ) ) command_list = commandSplitter(self.command) #print( command_list ) for command in command_list: if not isinstance(command[0], str): command[0](*command[1:]) else: result_code = BuildUtility.ExecCommand(command) if result_code != 0: return self.completeTask(result_code) self.tool.timestamp_cache.removeEntry(self.target) if result_code == 0: Log.v(' Ok ' + self.target) return self.completeTask(result_code)
def dumpQueue(self): Log.p('JobQueue:') with self.lock: for job in self.queue: Log.p(str(job))
def main(argv): makefile = 'FLB_Makefile.py' default_task = 'build' debug_flag = False dump_flag = False func_command = None env_dump = False job_count = 0 action_list = [] opt_dict = load_config() acount = len(argv) ai = 1 while ai < acount: arg = argv[ai] if arg[0] == '-': if arg == '-f': ai += 1 if ai < acount: makefile = argv[ai] elif arg == '--env': ai += 1 if ai < acount: platform = argv[ai] env_dump = True elif arg == '--opt': ai += 1 if ai < acount: opts = argv[ai].split('=') opt_dict[opts[0]] = opts[1] elif arg == '--job': ai += 1 if ai < acount: job_count = int(argv[ai]) elif arg == '--debug': debug_flag = True Log.DebugLevel = 2 elif arg == '-v' or arg == '--verbose': debug_flag = True Log.DebugLevel = 1 elif arg == '--dump': dump_flag = True elif arg == '--list': func_command = 'f_list' elif arg == '--platforms': func_command = 'f_platforms' else: usage() else: default_task = None action_list.append(arg) ai += 1 if default_task: action_list.append(default_task) if makefile != None: start_time_real = time.perf_counter() try: tool = BuildTool(job_count, opt_dict) tool.execScript(makefile) if func_command: getattr(tool, func_command)() else: for task_name in action_list: actions = task_name.split(',') tool.runSequentialTask(tool.nameToTaskList(actions)) tool.wait() if dump_flag: tool.dump() if tool.result_code: return tool.result_code except Exception as e: if not debug_flag: print(e) else: raise finally: Log.p('time %f' % (time.perf_counter() - start_time_real)) else: usage() Log.d('OK') return 0
def f_platforms(self): for platform in self.platform_table: env = self.createTargetEnvironment(platform) if env.isValid(): Log.p('[%s]--------' % platform) env.summary()
def usage(): Log.p('FlatBuildTool v1.43 Hiroyuki Ogasawara') Log.p('usage: python FlatBuildTool.py [<options>] [<target>...]') Log.p(' -f <BuildFile.py> default : FLB_Makefile.py') Log.p(' --dump') Log.p(' --job <thread> default : system thread count') Log.p(' --list display all targets') Log.p(' --platforms') Log.p(' --opt <env_name>=<value>') Log.p(' -v, --verbose') Log.p(' --debug') Log.p('parallel action: target1 target2 ...') Log.p('sequential action: target1,target2,...') sys.exit(0)
def addPlatform(self, platform_name, platform_env): Log.d('Load platform : ' + platform_name) self.platform_table[platform_name] = platform_env
def command(task): Log.p('Clean: ' + os.path.join(task.cwd, task.env.OUTPUT_OBJ_DIR)) BuildUtility.RemoveTree( os.path.join(task.cwd, task.env.OUTPUT_OBJ_DIR))
def preBuild(self): Log.d('Group task "%s" completed' % self.target) return self.completeTask(0)
def preBuild(self): if self.script: self.script(self) Log.d('Script task "%s" completed' % self.target) return self.completeTask(0)
def preBuild(self): Log.d('Sequential task "%s" completed' % self.target) return self.completeTask(0)
def summary(self): super().summary() Log.p('MSVC = %d' % self.MSVC_VERSION) Log.p('SDK = ', self.WINDOWS_SDK_DIR) Log.p('SDK Version = ', self.WINDOWS_SDK_VERSION) Log.p('CPU Arch = ', ','.join(self.ARCH_LIST))
def summary(self): Log.p('HostArch = ' + self.getHostArch()) Log.p('HostPlatform = ' + self.getHostPlatform())