def command_env_clean(): rmdir(os.path.join(TURBULENZROOT, ENV))
def execute(mode="Release"): # Detect the current path curpath = OS.getcwd() UT.info('Building LLVM (curpath = %s)' % curpath) # Detect the OS osn = UT.os_name() # Clean and create the 'CACHE' and 'deps' folders if not OS.path.isdir('CACHE'): OS.mkdir('CACHE') if not OS.path.isdir('deps'): OS.mkdir('deps') # Create directory and configure if not OS.path.isdir('build_llvm'): OS.mkdir('build_llvm') OS.chdir('build_llvm') # Download LLVM's sources if not OS.path.isfile('%s/CACHE/%s' % (curpath, LLVM_SRC_TAR_XZ)): print('LLVM_SRC_URL: %s' % LLVM_SRC_URL) UT.execute('curl -L -o %s/CACHE/%s %s' % (curpath, LLVM_SRC_TAR_XZ, LLVM_SRC_URL)) if not OS.path.isfile('%s/CACHE/%s' % (curpath, LLVM_CFE_TAR_XZ)): print('LLVM_CFE_URL: %s' % LLVM_CFE_URL) UT.execute('curl -L -o %s/CACHE/%s %s' % (curpath, LLVM_CFE_TAR_XZ, LLVM_CFE_URL)) # Unpack the downloaded 'xz' archives UT.execute('7z x -y %s/CACHE/%s -o%s/CACHE' % (curpath, LLVM_SRC_TAR_XZ, curpath)) UT.execute('7z x -y %s/CACHE/%s -o%s/CACHE' % (curpath, LLVM_CFE_TAR_XZ, curpath)) # Unpack the extracted 'tar' archives UT.execute('7z x -y %s/CACHE/%s' % (curpath, LLVM_SRC_TAR), False) UT.execute('7z x -y %s/CACHE/%s' % (curpath, LLVM_CFE_TAR), False) # Delete the 'tar' archives OS.remove('%s/CACHE/%s' % (curpath, LLVM_SRC_TAR)) OS.remove('%s/CACHE/%s' % (curpath, LLVM_CFE_TAR)) # Move the clang sources into the proper LLVM subdirectory if OS.path.isdir('%s/build_llvm/%s/tools/clang/%s' % (curpath, LLVM_SRC, LLVM_CFE)): UT.rmdir('%s/build_llvm/%s/tools/clang/%s' % (curpath, LLVM_SRC, LLVM_CFE)) SH.move('%s/build_llvm/%s' % (curpath, LLVM_CFE), '%s/build_llvm/%s/tools/clang' % (curpath, LLVM_SRC)) # Prepare the 'ninja' makefile with 'cmake' cmd = ('cmake -G Ninja ' + '-DCMAKE_CXX_FLAGS="-march=native" ' + '-DCMAKE_BUILD_TYPE=%s ' + '-DCMAKE_INSTALL_PREFIX=%s/deps/tob_libraries/llvm ' + '-DLLVM_TARGETS_TO_BUILD="X86;AArch64" ' + '-DLLVM_BUILD_TESTS=False ' + '-DLLVM_INCLUDE_TESTS=False ' + '-DLLVM_INCLUDE_BENCHMARKS=False ' + '-DLLVM_ENABLE_ASSERTIONS=True ' + '-DLLVM_BUILD_DOCS=False ' + '-DLLVM_ENABLE_DOXYGEN=False ' + '-DLLVM_ENABLE_DUMP=True ' + '-DLLVM_ENABLE_RTTI=True ' + LLVM_SRC) % (mode, curpath) # Generate the 'ninja' makefiles UT.execute(cmd) # Compile LLVM with 'ninja' UT.execute('ninja') # Install LLVM with 'ninja' UT.execute('ninja install') # Get back to the main directory OS.chdir(curpath) # Notify we successfully compiled LLVM UT.succ('LLVM has been successfully compiled!')
def command_apps(options): app_dirs = [ 'samples', 'apps/inputapp', 'apps/multiworm', 'apps/sampleapp', 'apps/templateapp', 'apps/viewer', 'apps/tictactoe', 'apps/protolibsampleapp' ] app_dirs = [ os.path.join(TURBULENZROOT, p) for p in app_dirs ] all_apps = {} for d in app_dirs: all_apps[os.path.split(d)[1]] = d parser = argparse.ArgumentParser(description=" Builds or cleans specified app(s), by name or path. If no app is" " given, builds or cleans all the listed apps (except samples).") parser.add_argument('--clean', action='store_true', help="Clean specified apps (same as apps-clean)") parser.add_argument('--refcheck', action='store_true', help="Build with reference checking") parser.add_argument('--verbose', action='store_true', help="Display verbose build output") parser.add_argument('--compactor', default='uglifyjs', help="Select a compactor for the code build", choices=['uglifyjs', 'yui', 'closure', 'none']) parser.add_argument('--mode', action='append', help="Add build mode (default canvas & canvas-debug)", choices=['all', 'plugin', 'plugin-debug', 'canvas', 'canvas-debug']) parser.add_argument('--assets-path', action='append', help="Specify additional asset root paths") parser.add_argument('app', default='all_apps', nargs='?', help="Select an individual app to build") parser.add_argument('--options', nargs='*', help="Additional options to pass to the build process") args = parser.parse_args(options) if args.app == 'all_apps': # If no app given, build all apps except samples apps = [ app for app in all_apps.keys() if app != 'samples' ] else: if args.app not in all_apps and not os.path.exists(args.app): print "ERROR: app name not recognised: %s" % args.app apps = [ args.app ] if not args.mode: modes = ['canvas-debug', 'canvas'] elif 'all' in args.mode: modes = ['all'] else: modes = args.mode options = ' '.join(args.options) if args.options else '' start_time = time.time() # Build / clean each app for app in apps: try: app_dir = all_apps[app] except KeyError: app_dir = app print "APP: %s, DIR: %s, BUILDOPTIONS: %s" \ % (app, app_dir, options) if args.clean: for mode in modes: cmd = _get_make_command() + " -C " + app_dir + " clean" cmd += " MODE=%s" % mode #cmd += " BUILDVERBOSE=%d" % args.verbose cmd += " CMDVERBOSE=%d" % args.verbose cmd += " --no-print-directory" if 0 != call(cmd, shell=True): return 1 rmdir('%s/_build' % app_dir) rmdir('%s/staticmax' % app_dir) rm('%s/mapping_table.json' % app_dir) elif args.refcheck: make_cmd = "%s -C %s jslib TS_REFCHECK=1 -j %s" \ % (_get_make_command(), app_dir, _get_num_cpus() + 1) print "BUILD CMD IS: %s" % make_cmd if 0 != call(make_cmd, shell=True): return 1 else: if 0 != command_jslib([]): return 1 buildassets_cmd = ['python', os.path.join(TURBULENZROOT, 'scripts', 'buildassets.py')] buildassets_cmd.extend(['--root', TURBULENZROOT]) # Add asset paths, start with user supplied paths, then app specific, then default assets # Build assets searches the paths in order in the case of duplicate source names if args.assets_path: for p in args.assets_path: buildassets_cmd.extend(['--assets-path', p]) app_assets = os.path.abspath(os.path.join(app_dir, 'assets')) if os.path.isdir(app_assets): buildassets_cmd.extend(['--assets-path', app_assets]) buildassets_cmd.extend(['--assets-path', os.path.join(TURBULENZROOT, 'assets') ]) if args.verbose: buildassets_cmd.append('--verbose') try: sh(buildassets_cmd, cwd=app_dir, console=True) except CalledProcessError as e: return e.retcode for mode in modes: cmd = _get_make_command() + " -C " + app_dir + " build" cmd += " -j %d" % (_get_num_cpus() + 1) cmd += " MODE=%s" % mode cmd += " COMPACTOR=" + args.compactor #cmd += " BUILDVERBOSE=%d" % args.verbose cmd += " CMDVERBOSE=%d" % args.verbose cmd += " --no-print-directory" if 0 != call(cmd, shell=True): return 1 print "BUILD TOOK: %.6f seconds" % (time.time() - start_time)
def command_docs_clean(): rmdir(os.path.join(TURBULENZROOT, 'build', 'docs', 'doctrees')) rmdir(os.path.join(TURBULENZROOT, 'build', 'docs'))
def command_docs_clean(): rmdir('build/docs') rmdir('build/docs/doctrees')
def command_env_clean(): rmdir(ENV)
def command_apps(options): app_dirs = ['samples', 'apps/inputapp', 'apps/multiworm', 'apps/sampleapp', 'apps/templateapp', 'apps/viewer', 'apps/tictactoe', 'apps/protolibsampleapp'] app_dirs = [os.path.join(TURBULENZROOT, p) for p in app_dirs] all_apps = {} for d in app_dirs: all_apps[os.path.split(d)[1]] = d parser = argparse.ArgumentParser(description=" Builds or cleans specified app(s), by name or path. If no app is" " given, builds or cleans all the listed apps (except samples).") parser.add_argument('--clean', action='store_true', help="Clean specified apps (same as apps-clean)") parser.add_argument('--refcheck', action='store_true', help="Build with reference checking") parser.add_argument('--verbose', action='store_true', help="Display verbose build output") parser.add_argument('--compactor', default='uglifyjs', help="Select a compactor for the code build", choices=['uglifyjs', 'yui', 'closure', 'none']) parser.add_argument('--mode', action='append', help="Add build mode (default canvas & canvas-debug)", choices=['all', 'plugin', 'plugin-debug', 'canvas', 'canvas-debug']) parser.add_argument('--assets-path', action='append', help="Specify additional asset root paths") parser.add_argument('app', default='all_apps', nargs='?', help="Select an individual app to build") parser.add_argument('--d3d11', action='store_true', help="Build shaders for d3d11") parser.add_argument('--d3d9', action='store_true', help="Build shaders for d3d11") parser.add_argument('--cgfx-flag', action='append', help="flag for cgfx2json") parser.add_argument('--options', nargs='*', help="Additional options to pass to the build process") args = parser.parse_args(options) if args.app == 'all_apps': # If no app given, build all apps except samples apps = [app for app in all_apps.keys() if app != 'samples'] else: if args.app not in all_apps and not os.path.exists(args.app): print "ERROR: app name not recognised: %s" % args.app apps = [args.app] if not args.mode: modes = ['canvas-debug', 'canvas'] elif 'all' in args.mode: modes = ['all'] else: modes = args.mode if 'plugin-debug' in modes: warning('**DEPRECATED** plugin-debug has been deprecated as a build mode. ' 'Please use canvas-debug for debugging. Removing from list of modes.') modes = [m for m in modes if m != 'plugin-debug'] if not modes: error("No remaining modes to build.") return options = ' '.join(args.options) if args.options else '' asset_options = [] if args.cgfx_flag: asset_options.extend([ '--cgfx-flag=%s' % c for c in args.cgfx_flag ]) if args.d3d11: d3d11_flags = _d3d11_cgfx2json_flags() asset_options.extend([ "--cgfx-flag=%s" % f for f in d3d11_flags ]) if args.d3d9: d3d9_flags = _d3d9_cgfx2json_flags() asset_options.extend([ "--cgfx-flag=%s" % f for f in d3d9_flags ]) start_time = time.time() # Build / clean each app for app in apps: try: app_dir = all_apps[app] except KeyError: app_dir = app print "APP: %s, DIR: %s, BUILDOPTIONS: %s" \ % (app, app_dir, options) if args.clean: for mode in modes: cmd = _get_make_command() + " -C " + app_dir + " clean" cmd += " MODE=%s" % mode #cmd += " BUILDVERBOSE=%d" % args.verbose cmd += " CMDVERBOSE=%d" % args.verbose cmd += " --no-print-directory" if 0 != call(cmd, shell=True): return 1 rmdir('%s/_build' % app_dir, False) rmdir('%s/staticmax' % app_dir, False) rm('%s/mapping_table.json' % app_dir, False) elif args.refcheck: make_cmd = "%s -C %s jslib TS_REFCHECK=1 -j %s" \ % (_get_make_command(), app_dir, _get_num_cpus() + 1) print "BUILD CMD IS: %s" % make_cmd if 0 != call(make_cmd, shell=True): return 1 else: if 0 != command_jslib([]): return 1 buildassets_cmd = ['python', os.path.join(TURBULENZROOT, 'scripts', 'buildassets.py')] buildassets_cmd.extend(['--root', TURBULENZROOT]) buildassets_cmd.extend(asset_options) # Add asset paths, start with user supplied paths, then app specific, then default assets # Build assets searches the paths in order in the case of duplicate source names if args.assets_path: for p in args.assets_path: buildassets_cmd.extend(['--assets-path', p]) app_assets = os.path.abspath(os.path.join(app_dir, 'assets')) if os.path.isdir(app_assets): buildassets_cmd.extend(['--assets-path', app_assets]) buildassets_cmd.extend(['--assets-path', os.path.join(TURBULENZROOT, 'assets')]) if args.verbose: buildassets_cmd.append('--verbose') try: sh(buildassets_cmd, cwd=app_dir, console=True) except CalledProcessError as e: return e.retcode for mode in modes: cmd = _get_make_command() + " -C " + app_dir + " build" cmd += " -j %d" % (_get_num_cpus() + 1) cmd += " MODE=%s" % mode cmd += " COMPACTOR=" + args.compactor #cmd += " BUILDVERBOSE=%d" % args.verbose cmd += " CMDVERBOSE=%d" % args.verbose cmd += " --no-print-directory" if 0 != call(cmd, shell=True): return 1 print "BUILD TOOK: %.6f seconds" % (time.time() - start_time)
def command_docs_clean(): rmdir(os.path.join(TURBULENZROOT, 'build', 'docs', 'doctrees'), False) rmdir(os.path.join(TURBULENZROOT, 'build', 'docs'), False)
def command_env_clean(): rmdir(os.path.join(TURBULENZROOT, ENV), False)
def command_apps(options): app_dirs = [ 'samples', 'apps/inputapp', 'apps/multiworm', 'apps/sampleapp', 'apps/templateapp', 'apps/viewer' ] all_apps = {} for d in app_dirs: all_apps[os.path.split(d)[1]] = d parser = argparse.ArgumentParser( description= " Builds or cleans specified app(s), by name or path. If no app is" " given, builds or cleans all the listed apps (except samples).") parser.add_argument('--clean', action='store_true', help="Clean specified apps (same as apps-clean)") parser.add_argument('--refcheck', action='store_true', help="Build with reference checking") parser.add_argument('--verbose', action='store_true', help="Display verbose build output") parser.add_argument('--compactor', default='uglifyjs', help="Select a compactor for the code build", choices=['uglifyjs', 'yui', 'closure', 'none']) parser.add_argument( '--mode', action='append', help="Add build mode (default canvas & canvas-debug)", choices=['all', 'plugin', 'plugin-debug', 'canvas', 'canvas-debug']) parser.add_argument('--assets-path', action='append', help="Specify additional asset root paths") parser.add_argument('app', default='all_apps', nargs='?', help="Select an individual app to build") parser.add_argument('--options', nargs='*', help="Additional options to pass to the build process") args = parser.parse_args(options) if args.app == 'all_apps': # If no app given, build all apps except samples apps = [app for app in all_apps.keys() if app != 'samples'] else: if args.app not in all_apps and not os.path.exists(args.app): print "ERROR: app name not recognised: %s" % args.app apps = [args.app] if not args.mode: modes = ['canvas-debug', 'canvas'] elif 'all' in args.mode: modes = ['all'] else: modes = args.mode options = ' '.join(args.options) if args.options else '' start_time = time.time() # Build / clean each app for app in apps: try: app_dir = all_apps[app] except KeyError: app_dir = app print "APP: %s, DIR: %s, BUILDOPTIONS: %s" \ % (app, app_dir, options) if args.clean: for mode in modes: cmd = _get_make_command() + " -C " + app_dir + " clean" cmd += " MODE=%s" % mode #cmd += " BUILDVERBOSE=%d" % args.verbose cmd += " CMDVERBOSE=%d" % args.verbose cmd += " --no-print-directory" if 0 != call(cmd, shell=True): return 1 rmdir('%s/_build' % app_dir) rmdir('%s/staticmax' % app_dir) rmdir('%s/mapping_table.json' % app_dir) elif args.refcheck: make_cmd = "%s -C %s jslib TS_REFCHECK=1 -j %s" \ % (_get_make_command(), app_dir, _get_num_cpus() + 1) print "BUILD CMD IS: %s" % make_cmd if 0 != call(make_cmd, shell=True): return 1 else: if 0 != command_jslib([]): return 1 buildassets_cmd = [ 'python', os.path.join(TURBULENZROOT, 'scripts', 'buildassets.py') ] buildassets_cmd.extend([ '--root', TURBULENZROOT, '--assets-path', os.path.join(TURBULENZROOT, 'assets') ]) if args.assets_path: for p in args.assets_path: buildassets_cmd.extend(['--assets-path', p]) if args.verbose: buildassets_cmd.append('--verbose') try: sh(buildassets_cmd, cwd=app_dir, console=True) except CalledProcessError as e: return e.retcode for mode in modes: cmd = _get_make_command() + " -C " + app_dir + " build" cmd += " -j %d" % (_get_num_cpus() + 1) cmd += " MODE=%s" % mode cmd += " COMPACTOR=" + args.compactor #cmd += " BUILDVERBOSE=%d" % args.verbose cmd += " CMDVERBOSE=%d" % args.verbose cmd += " --no-print-directory" if 0 != call(cmd, shell=True): return 1 print "BUILD TOOK: %.6f seconds" % (time.time() - start_time)
def execute(branch='master', mode="Release"): # Detect the current path curpath = OS.getcwd() UT.info('Building Capstone (curpath = %s)' % curpath) # Detect the operating system name osn = UT.os_name() # Determine the cpu core count ncpu = UT.cpu_count() # Determine cmake's 'generator' parameter generator = UT.cmake_generator() # Create directory and configure if not OS.path.isdir('build_capstone'): OS.mkdir('build_capstone') OS.chdir('build_capstone') # Clone the Capstone repository if not OS.path.isdir('capstone'): UT.execute('git clone %s capstone' % CAPSTONE_URL) OS.chdir('capstone') # Checkout the proper branch UT.execute('git checkout %s' % branch) # Pull the latest changes UT.execute('git pull') # Create the 'tob_libraries' capstone directory if not OS.path.isdir('%s/deps/tob_libraries/capstone' % curpath): OS.mkdir('%s/deps/tob_libraries/capstone' % curpath) else: UT.rmdir('%s/deps/tob_libraries/capstone' % curpath) OS.mkdir('%s/deps/tob_libraries/capstone' % curpath) # Copy the 'include' folder if branch == 'v3': UT.find_and_copy( 'include', '.', '%s/deps/tob_libraries/capstone/include/capstone' % curpath) else: UT.find_and_copy('include', '.', '%s/deps/tob_libraries/capstone/include' % curpath) # Create the build directory if not OS.path.isdir('build'): OS.mkdir('build') OS.chdir('build') # Generate the cmake configuration command cmd = ('cmake -G "%s" ' + '-DCMAKE_CXX_FLAGS="-march=native" ' + '-DCMAKE_BUILD_TYPE=%s ' + '-DCAPSTONE_BUILD_CSTOOL=no ' + '-DCAPSTONE_BUILD_TESTS=no ' + '-DCAPSTONE_TMS320C64X_SUPPORT=0 ' + '-DCAPSTONE_MOS65XX_SUPPORT=0 ' + '-DCAPSTONE_SPARC_SUPPORT=0 ' + '-DCAPSTONE_ARM64_SUPPORT=0 ' + '-DCAPSTONE_M680X_SUPPORT=0 ' + '-DCAPSTONE_XCORE_SUPPORT=0 ' + '-DCAPSTONE_M68K_SUPPORT=0 ' + '-DCAPSTONE_MIPS_SUPPORT=0 ' + '-DCAPSTONE_SYSZ_SUPPORT=0 ' + '-DCAPSTONE_PPC_SUPPORT=0 ' + '-DCAPSTONE_ARM_SUPPORT=0 ' + '-DCAPSTONE_EVM_SUPPORT=0 ' + '-DCAPSTONE_X86_M680X=0 ' + '..') % (generator, mode) # Execute cmake UT.execute(cmd) # Compile for the proper OS if osn.startswith('Windows'): # Compile Capstone (x86 only) UT.execute('cmake --build . --config Release -- /maxcpucount:%d' % ncpu) # Copy the 'capstone.dll' and 'capstone.lib' files if not UT.find_and_copy( 'capstone.dll', '.', '%s/deps/tob_libraries/capstone/capstone.dll' % curpath): UT.fail('Failed to find and copy: capstone.dll') if not UT.find_and_copy( 'capstone.lib', '.', '%s/deps/tob_libraries/capstone/capstone_static.lib' % curpath): UT.fail('Failed to find and copy: capstone.lib') elif osn.startswith('Linux'): # Compile Capstone (x86 only) UT.execute('make -j%d' % ncpu) # Copy the 'libcapstone.so' and 'libcapstone.a' files if not UT.find_and_copy( 'libcapstone.so', '.', '%s/deps/tob_libraries/capstone/libcapstone.so' % curpath): UT.fail('Failed to find and copy: libcapstone.so') if not UT.find_and_copy( 'libcapstone.a', '.', '%s/deps/tob_libraries/capstone/libcapstone_static.a' % curpath): UT.fail('Failed to find and copy: libcapstone.a') elif osn.startswith('Darwin'): # Compile Capstone (x86 only) UT.execute('make -j%d' % ncpu) # Copy the 'capstone.dll' and 'capstone.lib' files if not UT.find_and_copy( 'libcapstone.dylib', '.', '%s/deps/tob_libraries/capstone/libcapstone.dylib' % curpath): UT.fail('Failed to find and copy: libcapstone.dylib') if not UT.find_and_copy( 'libcapstone.a', '.', '%s/deps/tob_libraries/capstone/libcapstone_static.a' % curpath): UT.fail('Failed to find and copy: libcapstone.a') # Copy the 'FindCapstone.cmake' file SH.copyfile( '%s/scripts/FindCapstone.cmake' % curpath, '%s/deps/tob_libraries/cmake_modules/FindCAPSTONE.cmake' % curpath) # Get back to the main directory OS.chdir(curpath) # Notify we successfully compiled Capstone UT.succ('Capstone has been successfully compiled!')