def build_deploy_webpage(fips_dir, proj_dir, rebuild): # if webpage dir exists, clear it first ws_dir = util.get_workspace_dir(fips_dir) webpage_dir = '{}/fips-deploy/oryol-webpage'.format(ws_dir) if rebuild: if os.path.isdir(webpage_dir): shutil.rmtree(webpage_dir) if not os.path.isdir(webpage_dir): os.makedirs(webpage_dir) # compile samples if BuildEmscripten and emscripten.check_exists(fips_dir): project.gen(fips_dir, proj_dir, EmscConfig) project.build(fips_dir, proj_dir, EmscConfig) if BuildWasm and emscripten.check_exists(fips_dir): project.gen(fips_dir, proj_dir, WasmConfig) project.build(fips_dir, proj_dir, WasmConfig) # export sample assets if ExportAssets: export_assets(fips_dir, proj_dir, webpage_dir) # deploy the webpage deploy_webpage(fips_dir, proj_dir, webpage_dir) log.colored(log.GREEN, 'Generated Samples web page under {}.'.format(webpage_dir))
def configure(fips_dir, proj_dir, cfg_name) : """run ccmake or cmake-gui on the provided project and config :param fips_dir: absolute fips path :param proj_dir: absolute project dir :cfg_name: build config name """ dep.fetch_imports(fips_dir, proj_dir) proj_name = util.get_project_name_from_dir(proj_dir) util.ensure_valid_project_dir(proj_dir) dep.gather_and_write_imports(fips_dir, proj_dir) # load configs, if more then one, only use first one configs = config.load(fips_dir, proj_dir, cfg_name) if configs : cfg = configs[0] log.colored(log.YELLOW, '=== configuring: {}'.format(cfg['name'])) # generate build files if not gen_project(fips_dir, proj_dir, cfg, True) : log.error("Failed to generate '{}' of project '{}'".format(cfg['name'], proj_name)) # run ccmake or cmake-gui build_dir = util.get_build_dir(fips_dir, proj_name, cfg) if ccmake.check_exists(fips_dir) : ccmake.run(build_dir) elif cmake_gui.check_exists(fips_dir) : cmake_gui.run(build_dir) else : log.error("Neither 'ccmake' nor 'cmake-gui' found (run 'fips diag')") else : log.error("No configs found for '{}'".format(cfg_name))
def gdb(fips_dir, proj_dir, cfg_name, target=None, target_args=None) : """debug a single target with gdb""" # prepare proj_name = util.get_project_name_from_dir(proj_dir) util.ensure_valid_project_dir(proj_dir) # load the config(s) configs = config.load(fips_dir, proj_dir, cfg_name) if configs : for cfg in configs : # check if config is valid config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors = True) if config_valid : deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name']) log.colored(log.YELLOW, "=== gdb: {}".format(cfg['name'])) cmdLine = ['gdb', "-ex", "run", "--args", target] if target_args : cmdLine.extend(target_args) try: subprocess.call(args = cmdLine, cwd = deploy_dir) except OSError : log.error("Failed to execute gdb (not installed?)") else : log.error("Config '{}' not valid in this environment".format(cfg['name'])) else : log.error("No valid configs found for '{}'".format(cfg_name)) return True
def build_deploy_webpage(fips_dir, proj_dir) : # if webpage dir exists, clear it first ws_dir = util.get_workspace_dir(fips_dir) webpage_dir = '{}/fips-deploy/oryol-webpage'.format(ws_dir) if os.path.isdir(webpage_dir) : shutil.rmtree(webpage_dir) os.makedirs(webpage_dir) # compile emscripten, pnacl and android samples if BuildEmscripten and emscripten.check_exists(fips_dir) : project.gen(fips_dir, proj_dir, 'emsc-ninja-release') project.build(fips_dir, proj_dir, 'emsc-ninja-release') if BuildWasm and emscripten.check_exists(fips_dir) : project.gen(fips_dir, proj_dir, 'wasm-ninja-release') project.build(fips_dir, proj_dir, 'wasm-ninja-release') if BuildPNaCl and nacl.check_exists(fips_dir) : project.gen(fips_dir, proj_dir, 'pnacl-ninja-release') project.build(fips_dir, proj_dir, 'pnacl-ninja-release') # export sample assets export_assets(fips_dir, proj_dir, webpage_dir) # deploy the webpage deploy_webpage(fips_dir, proj_dir, webpage_dir) log.colored(log.GREEN, 'Generated Samples web page under {}.'.format(webpage_dir))
def check_imports(fips_dir, proj_dir) : """recursively check imports""" log.colored(log.YELLOW, '=== imports:') if util.is_valid_project_dir(proj_dir) : dep.check_imports(fips_dir, proj_dir) else : log.warn('currently not in a project directory')
def check_fips(fips_dir) : """check whether fips is uptodate""" log.colored(log.YELLOW, '=== fips:') if git.check_branch_out_of_sync(fips_dir, 'master') : log.warn("'fips' is not update, please run 'git pull' in fips directory!") else : log.colored(log.GREEN, ' uptodate')
def check_imports(fips_dir, proj_dir) : """do various checks on the imports of a project :param fips_dir: absolute fips directory :param proj_dir: absolute project directory :returns: True if checks were valid """ # check whether any imported projects are in sync with the remote git repo success, imported_projects = get_all_imports_exports(fips_dir, proj_dir) num_imports = 0 for imp_proj_name in imported_projects : imp_proj_dir = imported_projects[imp_proj_name]['proj_dir'] # don't git-check the top-level project directory if imp_proj_dir != proj_dir : num_imports += 1 log.info("git status of '{}':".format(imp_proj_name)) if os.path.isdir(imp_proj_dir) : if os.path.isdir("{}/.git".format(imp_proj_dir)) : if git.check_out_of_sync(imp_proj_dir) : log.warn(" '{}' is out of sync with remote git repo".format(imp_proj_dir)) else : log.colored(log.GREEN, ' uptodate') else : log.colored(log.GREEN, " '{}' is not a git repository".format(imp_proj_dir)) else : log.warn(" '{}' does not exist, please run 'fips fetch'".format(imp_proj_dir)) if success and num_imports == 0 : log.info(' none') # gather imports, this will dump warnings gather_imports(fips_dir, proj_dir)
def gen_project(fips_dir, proj_dir, cfg, force) : """private: generate build files for one config""" proj_name = util.get_project_name_from_dir(proj_dir) build_dir = util.get_build_dir(fips_dir, proj_name, cfg) defines = {} defines['FIPS_USE_CCACHE'] = 'ON' if settings.get(proj_dir, 'ccache') else 'OFF' defines['FIPS_AUTO_IMPORT'] = 'OFF' if dep.get_policy(proj_dir, 'no_auto_import') else 'ON' if cfg['platform'] == 'ios': ios_team_id = settings.get(proj_dir, 'iosteam') if ios_team_id: defines['FIPS_IOS_TEAMID'] = ios_team_id do_it = force if not os.path.isdir(build_dir) : os.makedirs(build_dir) do_it = True if do_it : # if Ninja build tool and on Windows, need to copy # the precompiled ninja.exe to the build dir log.colored(log.YELLOW, "=== generating: {}".format(cfg['name'])) log.info("config file: {}".format(cfg['path'])) toolchain_path = config.get_toolchain(fips_dir, proj_dir, cfg) if toolchain_path : log.info("Using Toolchain File: {}".format(toolchain_path)) if cfg['build_tool'] == 'ninja' : ninja.prepare_ninja_tool(fips_dir, build_dir) cmake_result = cmake.run_gen(cfg, fips_dir, proj_dir, build_dir, toolchain_path, defines) if cfg['build_tool'] == 'vscode_cmake': vscode.write_workspace_settings(fips_dir, proj_dir, cfg) return cmake_result else : return True
def check_local_changes(fips_dir, proj_dir) : """this is a variation of check_imports which just checks for local (uncommitted or unpushed) changes. :param fips_dir: absolute fips directory :param proj_dir: absolute project directory :returns: True if checks were valid """ success, imported_projects = get_all_imports_exports(fips_dir, proj_dir) num_imports = 0 for imp_proj_name in imported_projects : imp_proj_dir = imported_projects[imp_proj_name]['proj_dir'] # don't git-check the top-level project directory if imp_proj_dir != proj_dir : num_imports += 1 log.info("checking '{}':".format(imp_proj_name)) if os.path.isdir(imp_proj_dir) : if git.has_local_changes(imp_proj_dir) : log.warn(" '{}' has local changes (uncommitted and/or unpushed)".format(imp_proj_dir)) else : log.colored(log.GREEN, ' no local changes') else : log.warn(" '{}' does not exist, please run 'fips fetch'".format(imp_proj_dir)) if success and num_imports == 0 : log.info(' none')
def run(fips_dir, proj_dir, args): """run the 'nebula' verb""" try: cfg_file = expanduser("~") + "/.config/nebula/gscept.cfg" if len(args) > 0: noun = args[0] if noun == 'set': if len(args) == 3: key = argToKey(args[1]) setKey(cfg_file, key, args[2]) else: log.error("Expected setting and value") elif noun == 'get': if len(args) == 2: key = argToKey(args[1]) value = getKey(cfg_file, key) log.info(value) else: workval = getKey(cfg_file, "workdir") rootval = getKey(cfg_file, "path") log.colored(log.YELLOW, "Current settings") log.optional("Project directory", workval) log.optional("Nebula root director", rootval) except (RuntimeError, KeyError): log.error("failed manipulating settings")
def configure(fips_dir, proj_dir, cfg_name): """run ccmake or cmake-gui on the provided project and config :param fips_dir: absolute fips path :param proj_dir: absolute project dir :cfg_name: build config name """ dep.fetch_imports(fips_dir, proj_dir) proj_name = util.get_project_name_from_dir(proj_dir) util.ensure_valid_project_dir(proj_dir) dep.gather_and_write_imports(fips_dir, proj_dir, cfg_name) # load configs, if more then one, only use first one configs = config.load(fips_dir, proj_dir, cfg_name) if configs: cfg = configs[0] log.colored(log.YELLOW, '=== configuring: {}'.format(cfg['name'])) # generate build files if not gen_project(fips_dir, proj_dir, cfg, True): log.error("Failed to generate '{}' of project '{}'".format( cfg['name'], proj_name)) # run ccmake or cmake-gui build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name']) if ccmake.check_exists(fips_dir): ccmake.run(build_dir) elif cmake_gui.check_exists(fips_dir): cmake_gui.run(build_dir) else: log.error( "Neither 'ccmake' nor 'cmake-gui' found (run 'fips diag')") else: log.error("No configs found for '{}'".format(cfg_name))
def build_deploy_webpage(fips_dir, proj_dir): # if webpage dir exists, clear it first ws_dir = util.get_workspace_dir(fips_dir) webpage_dir = '{}/fips-deploy/oryol-webpage'.format(ws_dir) if os.path.isdir(webpage_dir): shutil.rmtree(webpage_dir) os.makedirs(webpage_dir) # compile emscripten, pnacl and android samples if BuildEmscripten and emscripten.check_exists(fips_dir): project.gen(fips_dir, proj_dir, 'emsc-make-release') project.build(fips_dir, proj_dir, 'emsc-make-release') if BuildPNaCl and nacl.check_exists(fips_dir): project.gen(fips_dir, proj_dir, 'pnacl-make-release') project.build(fips_dir, proj_dir, 'pnacl-make-release') if BuildAndroid and android.check_exists(fips_dir): project.gen(fips_dir, proj_dir, 'android-make-release') project.build(fips_dir, proj_dir, 'android-make-release') # export sample assets export_assets(fips_dir, proj_dir, webpage_dir) # deploy the webpage deploy_webpage(fips_dir, proj_dir, webpage_dir) log.colored(log.GREEN, 'Generated Samples web page under {}.'.format(webpage_dir))
def gen_project(fips_dir, proj_dir, cfg, force): """private: generate build files for one config""" proj_name = util.get_project_name_from_dir(proj_dir) build_dir = util.get_build_dir(fips_dir, proj_name, cfg) defines = {} defines['FIPS_USE_CCACHE'] = 'ON' if settings.get(proj_dir, 'ccache') else 'OFF' do_it = force if not os.path.isdir(build_dir): os.makedirs(build_dir) do_it = True if do_it: # if Ninja build tool and on Windows, need to copy # the precompiled ninja.exe to the build dir if cfg['build_tool'] == 'ninja': ninja.prepare_ninja_tool(fips_dir, build_dir) log.colored(log.YELLOW, "=== generating: {}".format(cfg['name'])) toolchain_path = config.get_toolchain(fips_dir, proj_dir, cfg) if toolchain_path: log.info("Using Toolchain File: {}".format(toolchain_path)) return cmake.run_gen(cfg, fips_dir, proj_dir, build_dir, toolchain_path, defines) else: return True
def check_imports(fips_dir, proj_dir) : """do various checks on the imports of a project :param fips_dir: absolute fips directory :param proj_dir: absolute project directory :returns: True if checks were valid """ # check whether any imported projects are in sync with the remote git repo success, imported_projects = get_all_imports_exports(fips_dir, proj_dir) num_imports = 0 for imp_proj_name in imported_projects : imp_proj_dir = util.get_project_dir(fips_dir, imp_proj_name) # don't git-check the top-level project directory if imp_proj_dir != proj_dir : num_imports += 1 log.info("git status of '{}':".format(imp_proj_name)) if os.path.isdir(imp_proj_dir) : if git.check_out_of_sync(imp_proj_dir) : log.warn(" '{}' is out of sync with remote git repo".format(imp_proj_dir)) else : log.colored(log.GREEN, ' uptodate') else : log.warn(" '{}' does not exist, please run 'fips fetch'".format(imp_proj_dir)) if success and num_imports == 0 : log.info(' none') # gather imports, this will dump warnings gather_imports(fips_dir, proj_dir)
def activate(fips_dir, emsdk_version): if emsdk_version is None: emsdk_version = EMSDK_DEFAULT_VERSION log.colored( log.YELLOW, "=== activating emscripten SDK version '{}'".format(emsdk_version)) run(fips_dir, "activate --embedded {}".format(emsdk_version))
def setup(fips_dir) : """setup the Android SDK and NDK""" log.colored(log.YELLOW, '=== setup Android SDK/NDK :') # first make sure that java is present, otherwise the Android # SDK setup will finish without errors, but is not actually usable if not java.check_exists(fips_dir) or not javac.check_exists(fips_dir) : log.error("please install Java JDK 8 (see './fips diag tools')") ensure_sdk_dirs(fips_dir) # download the command line tools archive tools_archive_path = get_tools_archive_path(fips_dir) tools_url = get_tools_url() log.info("downloading '{}'...".format(tools_url)) urlretrieve(tools_url, tools_archive_path, util.url_download_hook) log.info("\nunpacking '{}'...".format(tools_archive_path)) uncompress(fips_dir, tools_archive_path) # install the required SDK components through sdkmanager install_package(fips_dir, '"platforms;android-28"') install_package(fips_dir, '"build-tools;29.0.3"') install_package(fips_dir, 'platform-tools') install_package(fips_dir, 'ndk-bundle') # check for potentially breaking changes in build setup fips_cmake = fips_dir + '/cmake-toolchains/android.toolchain.orig' ndk_cmake = get_sdk_dir(fips_dir) + '/ndk-bundle/build/cmake/android.toolchain.cmake' if compute_sha256(ndk_cmake, strip_whitespace) != compute_sha256(fips_cmake, strip_whitespace) : log.warn('android.toolchain.cmake in fips might be outdated...') log.colored(log.GREEN, "done.")
def check_fips(fips_dir): """check whether fips is uptodate""" log.colored(log.YELLOW, '=== fips:') if git.check_branch_out_of_sync(fips_dir, 'master'): log.warn("'fips' is not update, please run 'fips update fips'!") else: log.colored(log.GREEN, ' uptodate')
def clean(fips_dir, proj_dir, cfg_name): """clean build files :param fips_dir: absolute path of fips :param proj_dir: absolute project path :param cfg_name: config name (or pattern) """ proj_name = util.get_project_name_from_dir(proj_dir) configs = config.load(fips_dir, proj_dir, cfg_name) if configs: num_cleaned_configs = 0 for cfg in configs: build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name']) build_dir_exists = os.path.isdir(build_dir) deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name']) deploy_dir_exists = os.path.isdir(deploy_dir) if build_dir_exists or deploy_dir_exists: log.colored(log.YELLOW, "=== clean: {}".format(cfg['name'])) num_cleaned_configs += 1 if build_dir_exists: shutil.rmtree(build_dir) log.info(" deleted '{}'".format(build_dir)) if deploy_dir_exists: shutil.rmtree(deploy_dir) log.info(" deleted '{}'".format(deploy_dir)) if num_cleaned_configs == 0: log.colored(log.YELLOW, "=== clean: nothing to clean for {}".format(cfg_name)) else: log.error("No valid configs found for '{}'".format(cfg_name))
def gdb(fips_dir, proj_dir, cfg_name, target=None, target_args=None): """debug a single target with gdb""" # prepare proj_name = util.get_project_name_from_dir(proj_dir) util.ensure_valid_project_dir(proj_dir) # load the config(s) configs = config.load(fips_dir, proj_dir, cfg_name) if configs: for cfg in configs: # check if config is valid config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors=True) if config_valid: deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name']) log.colored(log.YELLOW, "=== gdb: {}".format(cfg['name'])) cmdLine = ['gdb', "-ex", "run", "--args", target] if target_args: cmdLine.extend(target_args) try: subprocess.call(args=cmdLine, cwd=deploy_dir) except OSError: log.error("Failed to execute gdb (not installed?)") else: log.error("Config '{}' not valid in this environment".format( cfg['name'])) else: log.error("No valid configs found for '{}'".format(cfg_name)) return True
def check_local_changes(fips_dir, proj_dir): """check if any imports have local, uncommitted changes""" log.colored(log.YELLOW, '=== local changes:') if util.is_valid_project_dir(proj_dir): dep.check_local_changes(fips_dir, proj_dir) else: log.warn('currently not in a project directory')
def check_imports(fips_dir, proj_dir): """recursively check imports""" log.colored(log.YELLOW, '=== imports:') if util.is_valid_project_dir(proj_dir): dep.check_imports(fips_dir, proj_dir) else: log.warn('currently not in a project directory')
def list_registry(fips_dir): """list registry entries""" log.colored(log.YELLOW, '=== registry:') registry.load(fips_dir) for key in registry.registry: log.info('{}{}{} => {}'.format(log.BLUE, key, log.DEF, registry.registry[key]))
def list_targets(fips_dir, proj_dir, args): log.colored(log.YELLOW, "=== targets:") if util.is_valid_project_dir(proj_dir): # get config name if len(args) == 0: cfg_name = settings.get(proj_dir, 'config') else: cfg_name = args[0] log.info('{} config:{} {}'.format(log.BLUE, log.DEF, cfg_name)) # get the target list success, targets = project.get_target_list(fips_dir, proj_dir, cfg_name) if success: # split targets by type for type in ['lib', 'module', 'sharedlib', 'app']: type_targets = [tgt for tgt in targets if targets[tgt] == type] if len(type_targets) > 0: log.colored(log.BLUE, ' {}:'.format(type)) for tgt in type_targets: log.info(' ' + tgt) else: log.info( " can't fetch project target list, please run 'fips gen' first!" ) else: log.info(' currently not in a valid project directory')
def setup(fips_dir, proj_dir): """setup the Android SDK and NDK""" log.colored(log.YELLOW, '=== setup Android SDK/NDK :') # first make sure that java is present, otherwise the Android # SDK setup will finish without errors, but is not actually usable if not javac.check_exists(fips_dir): log.error("please install Java JDK (see './fips diag tools')") ensure_sdk_dirs(fips_dir) # download the command line tools archive tools_archive_path = get_tools_archive_path(fips_dir) tools_url = get_tools_url() log.info("downloading '{}'...".format(tools_url)) urllib.urlretrieve(tools_url, tools_archive_path, util.url_download_hook) log.info("\nunpacking '{}'...".format(tools_archive_path)) uncompress(fips_dir, tools_archive_path) # install the required SDK components through sdkmanager install_package(fips_dir, '"platforms;android-21"') install_package(fips_dir, '"build-tools;27.0.3"') install_package(fips_dir, 'platform-tools') install_package(fips_dir, 'ndk-bundle') log.colored(log.GREEN, "done.")
def bootstrap(fips_dir): log.colored(log.YELLOW, "=== bootstrapping build...".format(get_sdk_dir(fips_dir))) dawn_dir = get_dawn_dir(fips_dir) gclient_src = dawn_dir + '/scripts/standalone.gclient' gclient_dst = dawn_dir + '/.gclient' if not os.path.isfile(gclient_dst): shutil.copy(gclient_src, gclient_dst) gclient(fips_dir, ['sync']) log.info('>> generating debug build files') cmake(fips_dir, 'Debug', ['-G', 'Ninja', '-DCMAKE_BUILD_TYPE=Debug', '../..']) log.info('>> generating release build files') cmake(fips_dir, 'Release', ['-G', 'Ninja', '-DCMAKE_BUILD_TYPE=Release', '../..']) log.info('>> building debug version...') cmake(fips_dir, 'Debug', ['--build', '.']) log.info('>> building release version...') cmake(fips_dir, 'Release', ['--build', '.']) # create dummy link directories so that Xcode doesn't complain log.info('>> creating dummy link dirs...') for mode in ['Debug', 'Release']: for dir in [ '/src/dawn', '/src/common', '/src/dawn_native', '/src/dawn_platform', '/src/dawn_wire', '/src/utils', '/third_party/shaderc/libshaderc_spvc', '/third_party/glfw/src' ]: dummy_dir = get_build_dir(fips_dir, mode) + dir + '/' + mode log.info(' {}'.format(dummy_dir)) make_dirs(dummy_dir)
def build(fips_dir, proj_dir, cfg_name, target=None, build_tool_args=None): """perform a build of config(s) in project :param fips_dir: absolute path of fips :param proj_dir: absolute path of project dir :param cfg_name: config name or pattern :param target: optional target name (build all if None) :param build_tool_args: optional string array of cmdline args forwarded to the build tool :returns: True if build was successful """ # prepare dep.fetch_imports(fips_dir, proj_dir) proj_name = util.get_project_name_from_dir(proj_dir) util.ensure_valid_project_dir(proj_dir) dep.gather_and_write_imports(fips_dir, proj_dir, cfg_name) # load the config(s) configs = config.load(fips_dir, proj_dir, cfg_name) num_valid_configs = 0 if configs: for cfg in configs: # check if config is valid config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors=True) if config_valid: log.colored(log.YELLOW, "=== building: {}".format(cfg['name'])) if not gen_project(fips_dir, proj_dir, cfg, False): log.error("Failed to generate '{}' of project '{}'".format( cfg['name'], proj_name)) # select and run build tool build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name']) num_jobs = settings.get(proj_dir, 'jobs') result = cmake.run_build(fips_dir, target, cfg['build_type'], build_dir, num_jobs, build_tool_args) if result: num_valid_configs += 1 else: log.error( "Failed to build config '{}' of project '{}'".format( cfg['name'], proj_name)) else: log.error("Config '{}' not valid in this environment".format( cfg['name'])) else: log.error("No valid configs found for '{}'".format(cfg_name)) if num_valid_configs != len(configs): log.error('{} out of {} configs failed!'.format( len(configs) - num_valid_configs, len(configs))) return False else: log.colored(log.GREEN, '{} configs built'.format(num_valid_configs)) return True
def install(fips_dir, emsdk_version): if not clone_or_update_emsdk(fips_dir): log.error('Failed to install or update emscripten SDK') if emsdk_version is None: emsdk_version = EMSDK_DEFAULT_VERSION log.colored(log.YELLOW, "=== installing emscripten tools for '{}'".format(emsdk_version)) run(fips_dir, "install --shallow --disable-assertions {}".format(emsdk_version)) activate(fips_dir, emsdk_version)
def list_configs(fips_dir, proj_dir): """list available configs""" log.colored(log.YELLOW, '=== configs:') configs = config.list(fips_dir, proj_dir, '*') for folder in configs: log.colored(log.BLUE, 'from {}:'.format(folder)) for cfg in configs[folder]: log.info(' {}'.format(cfg))
def install(fips_dir): log.colored(log.YELLOW, "=== installing Dawn SDK".format(get_sdk_dir(fips_dir))) if not ninja.check_exists(fips_dir): log.error('ninja build tool is needed to build Dawn') fetch_dawn(fips_dir) fetch_depot_tools(fips_dir) bootstrap(fips_dir)
def list_configs(fips_dir, proj_dir) : """list available configs""" log.colored(log.YELLOW, '=== configs:') configs = config.list(fips_dir, proj_dir, '*') for folder in configs : log.colored(log.BLUE, 'from {}:'.format(folder)) for cfg in configs[folder] : log.info(' {}'.format(cfg))
def build(fips_dir, proj_dir, cfg_name, target=None) : """perform a build of config(s) in project :param fips_dir: absolute path of fips :param proj_dir: absolute path of project dir :param cfg_name: config name or pattern :param target: optional target name (build all if None) :returns: True if build was successful """ # prepare dep.fetch_imports(fips_dir, proj_dir) proj_name = util.get_project_name_from_dir(proj_dir) util.ensure_valid_project_dir(proj_dir) dep.gather_and_write_imports(fips_dir, proj_dir) # load the config(s) configs = config.load(fips_dir, proj_dir, cfg_name) num_valid_configs = 0 if configs : for cfg in configs : # check if config is valid config_valid, _ = config.check_config_valid(fips_dir, cfg, print_errors=True) if config_valid : log.colored(log.YELLOW, "=== building: {}".format(cfg['name'])) if not gen_project(fips_dir, proj_dir, cfg, False) : log.error("Failed to generate '{}' of project '{}'".format(cfg['name'], proj_name)) # select and run build tool build_dir = util.get_build_dir(fips_dir, proj_name, cfg) num_jobs = settings.get(proj_dir, 'jobs') result = False if cfg['build_tool'] == make.name : result = make.run_build(fips_dir, target, build_dir, num_jobs) elif cfg['build_tool'] == ninja.name : result = ninja.run_build(fips_dir, target, build_dir, num_jobs) elif cfg['build_tool'] == xcodebuild.name : result = xcodebuild.run_build(fips_dir, target, cfg['build_type'], build_dir, num_jobs) else : result = cmake.run_build(fips_dir, target, cfg['build_type'], build_dir) if result : num_valid_configs += 1 else : log.error("Failed to build config '{}' of project '{}'".format(cfg['name'], proj_name)) else : log.error("Config '{}' not valid in this environment".format(cfg['name'])) else : log.error("No valid configs found for '{}'".format(cfg_name)) if num_valid_configs != len(configs) : log.error('{} out of {} configs failed!'.format(len(configs) - num_valid_configs, len(configs))) return False else : log.colored(log.GREEN, '{} configs built'.format(num_valid_configs)) return True
def install(fips_dir): log.colored(log.YELLOW, '=== installing WASI SDK:') ensure_sdk_dirs(fips_dir) sdk_url = get_url() archive_path = get_archive_path(fips_dir) log.info("downloading '{}'...".format(sdk_url)) urlretrieve(sdk_url, archive_path, util.url_download_hook) log.info("\nunpacking '{}'...".format(archive_path)) with tarfile.open(archive_path, "r:gz") as tar: tar.extractall(path=get_sdk_dir(fips_dir))
def clone_or_update_emsdk(fips_dir): # returns True on success emsdk_dir = get_emsdk_dir(fips_dir) if emsdk_dir_exists(fips_dir): log.colored(log.YELLOW, "=== updating emscripten SDK at '{}'".format(emsdk_dir)) return git.update_force_and_ignore_local_changes(emsdk_dir) else: log.colored(log.YELLOW, "=== cloning emscripten SDK to '{}'".format(emsdk_dir)) make_dirs(fips_dir) sdkroot_dir = get_sdkroot_dir(fips_dir) return git.clone(EMSDK_URL, None, 1, "emsdk", sdkroot_dir)
def run(fips_dir, proj_dir, args): if len(args) > 0 and args[0] == 'fips': if git.has_local_changes(fips_dir): log.warn(" '{}' has local changes, skipping...".format(fips_dir)) else: log.colored(log.BLUE, " updating '{}'...".format(fips_dir)) git.update(fips_dir) else: if len(args) > 0: proj_name = args[0] proj_dir = util.get_project_dir(fips_dir, proj_name) dep.update_imports(fips_dir, proj_dir)
def uninstall(fips_dir): log.colored(log.YELLOW, "=== uninstalling WASI SDK") if sdk_dir_exists(fips_dir): sdk_dir = get_sdk_dir(fips_dir) if util.confirm(log.RED + "Delete directory '{}?".format(sdk_dir) + log.DEF): log.info("Deleting '{}'...".format(sdk_dir)) shutil.rmtree(sdk_dir) else: log.info("'No' selected, nothing deleted") else: log.warn("WASI SDK is not installed, nothing to do")
def list_settings(proj_dir) : """list settings file content""" log.colored(log.YELLOW, '=== settings:') if util.is_valid_project_dir(proj_dir) : all_settings = settings.get_all_settings(proj_dir) for key, value in all_settings.items(): is_default = ' (default value)' if value == settings.get_default(key) else '' if type(value) is bool: value = 'on' if value else 'off' log.info(' {}{}:{} {}{}'.format(log.BLUE, key, log.DEF, value, is_default)) else : log.info(' currently not in a valid project directory')
def list_settings(proj_dir) : """list settings file content""" log.colored(log.YELLOW, '=== settings:') if util.is_valid_project_dir(proj_dir) : for key in ['config', 'target', 'jobs', 'ccache'] : value = settings.get(proj_dir, key) if type(value) is bool : value = 'on' if value else 'off' default = ' (default value)' if value == settings.get_default(key) else '' log.info(' {}{}:{} {}{}'.format(log.BLUE, key, log.DEF, value, default)) else : log.info(' currently not in a valid project directory')
def uninstall(fips_dir): emsdk_dir = get_emsdk_dir(fips_dir) log.colored(log.YELLOW, "=== uninstalling emscripten SDK".format(emsdk_dir)) # check for any "old" SDK installation remove_old_sdks(fips_dir) if emsdk_dir_exists(fips_dir): if util.confirm(log.RED + "Delete emsdk directory at '{}'?".format(emsdk_dir) + log.DEF): log.info("Deleting '{}'...".format(emsdk_dir)) shutil.rmtree(emsdk_dir, onerror=remove_readonly) else: log.info("'No' selected, nothing deleted") else: log.warn('emscripten SDK is not installed, nothing to do')
def make_clean(fips_dir, proj_dir, cfg_name): """perform a 'make clean' on the project :param fips_dir: absolute path of fips :param proj_dir: absolute path of project dir :param cfg_name: config name or pattern """ proj_name = util.get_project_name_from_dir(proj_dir) configs = config.load(fips_dir, proj_dir, cfg_name) num_valid_configs = 0 if configs: for cfg in configs: config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors=True) if config_valid: log.colored(log.YELLOW, "=== cleaning: {}".format(cfg['name'])) build_dir = util.get_build_dir(fips_dir, proj_name, cfg['name']) result = False if cfg['build_tool'] == make.name: result = make.run_clean(fips_dir, build_dir) elif cfg['build_tool'] == ninja.name: result = ninja.run_clean(fips_dir, build_dir) elif cfg['build_tool'] == xcodebuild.name: result = xcodebuild.run_clean(fips_dir, build_dir) else: result = cmake.run_clean(fips_dir, build_dir) if result: num_valid_configs += 1 else: log.error( "Failed to clean config '{}' of project '{}'".format( cfg['name'], proj_name)) else: log.error("Config '{}' not valid in this environment".format( cfg['name'])) else: log.error("No valid configs found for '{}'".format(cfg_name)) if num_valid_configs != len(configs): log.error('{} out of {} configs failed!'.format( len(configs) - num_valid_configs, len(configs))) return False else: log.colored(log.GREEN, '{} configs cleaned'.format(num_valid_configs)) return True
def check_tools(fips_dir) : """check whether required command line tools can be found""" log.colored(log.YELLOW, '=== tools:') tools = [ git, cmake, ccmake, cmake_gui, make, ninja, xcodebuild, java, ant, node, python2, ccache ] platform = util.get_host_platform() for tool in tools: if platform in tool.platforms : if tool.check_exists(fips_dir) : log.ok(tool.name, 'found') else : if tool.optional : log.optional(tool.name, 'OPTIONAL, NOT FOUND ({})'.format(tool.not_found)) else : log.failed(tool.name, 'NOT FOUND ({})'.format(tool.not_found))
def build_deploy_webpage(fips_dir, proj_dir) : # if webpage dir exists, clear it first ws_dir = util.get_workspace_dir(fips_dir) webpage_dir = '{}/fips-deploy/oryol-wasm-buildsuite'.format(ws_dir) if not os.path.exists(webpage_dir) : os.makedirs(webpage_dir) config = 'wasmasmjs-make-release' project.clean(fips_dir, proj_dir, config) project.gen(fips_dir, proj_dir, config) for target in Samples : project.build(fips_dir, proj_dir, config, target) copy_build_files(fips_dir, proj_dir, webpage_dir) if ExportAssets : export_assets(fips_dir, proj_dir, webpage_dir) log.colored(log.GREEN, 'Done. ({})'.format(webpage_dir))
def make_clean(fips_dir, proj_dir, cfg_name) : """perform a 'make clean' on the project :param fips_dir: absolute path of fips :param proj_dir: absolute path of project dir :param cfg_name: config name or pattern """ proj_name = util.get_project_name_from_dir(proj_dir) configs = config.load(fips_dir, proj_dir, cfg_name) num_valid_configs = 0 if configs : for cfg in configs : config_valid, _ = config.check_config_valid(fips_dir, cfg, print_errors=True) if config_valid : log.colored(log.YELLOW, "=== cleaning: {}".format(cfg['name'])) build_dir = util.get_build_dir(fips_dir, proj_name, cfg) result = False if cfg['build_tool'] == make.name : result = make.run_clean(fips_dir, build_dir) elif cfg['build_tool'] == ninja.name : result = ninja.run_clean(fips_dir, build_dir) elif cfg['build_tool'] == xcodebuild.name : result = xcodebuild.run_clean(fips_dir, build_dir) else : result = cmake.run_clean(fips_dir, build_dir) if result : num_valid_configs += 1 else : log.error("Failed to clean config '{}' of project '{}'".format(cfg['name'], proj_name)) else : log.error("Config '{}' not valid in this environment".format(cfg['name'])) else : log.error("No valid configs found for '{}'".format(cfg_name)) if num_valid_configs != len(configs) : log.error('{} out of {} configs failed!'.format(len(configs) - num_valid_configs, len(configs))) return False else : log.colored(log.GREEN, '{} configs cleaned'.format(num_valid_configs)) return True
def build_deploy_webpage(fips_dir, proj_dir) : # if webpage dir exists, clear it first ws_dir = util.get_workspace_dir(fips_dir) webpage_dir = '{}/fips-deploy/yakc-webpage/virtualkc'.format(ws_dir) if os.path.isdir(webpage_dir) : shutil.rmtree(webpage_dir) os.makedirs(webpage_dir) # compile emscripten, pnacl and android samples if emscripten.check_exists(fips_dir) : project.gen(fips_dir, proj_dir, 'yakc-emsc-make-release') project.build(fips_dir, proj_dir, 'yakc-emsc-make-release') # build the webpage via jekyll subprocess.call('jekyll build', cwd=proj_dir+'/web', shell=True) # deploy the webpage deploy_webpage(fips_dir, proj_dir, webpage_dir) log.colored(log.GREEN, 'Generated web page under {}.'.format(webpage_dir))
def show_help(args) : """show help text""" if len(args) > 0 : # show help for one verb verb_name = args[0] if verb_name in verb.verbs : verb.verbs[verb_name].help() else : log.error("unknown verb '{}'".format(verb)) else : # show generic help log.info("fips: the high-level, multi-platform build system wrapper\n" "v{}\n" "https://www.github.com/floooh/fips\n".format(VERSION)) for proj_name in verb.proj_verbs : if proj_name != 'fips' : log.colored(log.BLUE, "=== imported from '{}':".format(proj_name)) for verb_name in verb.proj_verbs[proj_name] : verb.verbs[verb_name].help() log.info(' ')
def build_deploy_webpage(fips_dir, proj_dir) : # if webpage dir exists, clear it first ws_dir = util.get_workspace_dir(fips_dir) webpage_dir = '{}/fips-deploy/oryol-samples-webpage'.format(ws_dir) if os.path.isdir(webpage_dir) : shutil.rmtree(webpage_dir) os.makedirs(webpage_dir) if emscripten.check_exists(fips_dir) : project.gen(fips_dir, proj_dir, BuildConfig) project.build(fips_dir, proj_dir, BuildConfig) # export sample assets if ExportAssets : export_assets(fips_dir, proj_dir, webpage_dir) # deploy the webpage deploy_webpage(fips_dir, proj_dir, webpage_dir) log.colored(log.GREEN, 'Generated Samples web page under {}.'.format(webpage_dir))
def list_imports(fips_dir, proj_dir) : """list project imports""" log.colored(log.YELLOW, '=== imports:') if util.is_valid_project_dir(proj_dir) : success, result = dep.get_all_imports_exports(fips_dir, proj_dir) if not success : log.warn("missing import project directories, please run 'fips fetch'") for dep_proj_name in result : # top level project is in result, but has no URL set, filter # this from the output log.colored(log.BLUE, "project '{}' imports:".format(dep_proj_name)) cur_dep = result[dep_proj_name] if cur_dep['imports'] : for imp_proj in cur_dep['imports'] : git_url = cur_dep['imports'][imp_proj]['git'] git_branch = cur_dep['imports'][imp_proj]['branch'] log.info(" '{}' from '{}' at branch '{}'".format(imp_proj, git_url, git_branch)) else : log.info(" nothing") else : log.info(' currently not in a valid project directory')
def gen_project(fips_dir, proj_dir, cfg, force) : """private: generate build files for one config""" proj_name = util.get_project_name_from_dir(proj_dir) build_dir = util.get_build_dir(fips_dir, proj_name, cfg) defines = {} defines['FIPS_USE_CCACHE'] = 'ON' if settings.get(proj_dir, 'ccache') else 'OFF' do_it = force if not os.path.isdir(build_dir) : os.makedirs(build_dir) do_it = True if do_it : # if Ninja build tool and on Windows, need to copy # the precompiled ninja.exe to the build dir if cfg['build_tool'] == 'ninja' : ninja.prepare_ninja_tool(fips_dir, build_dir) log.colored(log.YELLOW, "=== generating: {}".format(cfg['name'])) toolchain_path = config.get_toolchain_for_platform(fips_dir, cfg['platform']) return cmake.run_gen(cfg, proj_dir, build_dir, toolchain_path, defines) else : return True
def _rec_update_imports(fips_dir, proj_dir, handled) : """same as _rec_fetch_imports() but for updating the imported projects """ ws_dir = util.get_workspace_dir(fips_dir) proj_name = util.get_project_name_from_dir(proj_dir) if proj_name not in handled : handled.append(proj_name) imports = get_imports(fips_dir, proj_dir) for dep in imports: dep_proj_name = dep if dep not in handled: dep_proj_dir = util.get_project_dir(fips_dir, dep_proj_name) log.colored(log.YELLOW, "=== dependency: '{}':".format(dep_proj_name)) dep_ok = False if os.path.isdir(dep_proj_dir) : # directory did not exist, do a fresh git clone dep = imports[dep_proj_name] git_commit = None if 'rev' not in dep else dep['rev'] if git.has_local_changes(dep_proj_dir) : log.warn(" '{}' has local changes, skipping...".format(dep_proj_dir)) else : log.colored(log.BLUE, " updating '{}'...".format(dep_proj_dir)) git.update(dep_proj_dir) if git_commit: log.colored(log.YELLOW, "=== revision: '{}':".format(git_commit)) dep_ok = git.checkout(dep_proj_dir, git_commit) else: dep_ok = True else : log.warn(" '{}' does not exist, please run 'fips fetch'".format(dep_proj_dir)) # recuse if dep_ok : handled = _rec_update_imports(fips_dir, dep_proj_dir, handled) # done, return the new handled array return handled
def list_exports(fips_dir, proj_dir) : """list project exports""" log.colored(log.YELLOW, '=== exports:') if util.is_valid_project_dir(proj_dir) : success, result = dep.get_all_imports_exports(fips_dir, proj_dir) if not success : log.warn("missing import project directories, please un 'fips fetch'") for dep_proj_name in result : cur_dep = result[dep_proj_name] log.colored(log.BLUE, "project '{}' exports:".format(dep_proj_name)) cur_modules = cur_dep['exports']['modules'] cur_hdrs = cur_dep['exports']['header-dirs'] cur_libs = cur_dep['exports']['lib-dirs'] cur_defs = cur_dep['exports']['defines'] if not (cur_modules or cur_hdrs or cur_libs or cur_defs) : log.info(" nothing") if cur_modules : log.info(" modules:") for mod in cur_modules : log.info(" {} => {}".format(mod, cur_modules[mod])) if cur_hdrs : log.info(" header search dirs:") for hdr in cur_hdrs : log.info(" {}".format(hdr)) if cur_libs : log.info(" lib search dirs:") for lib in cur_libs : log.info(" {}".format(lib)) if cur_defs : log.info(" defines:") for define in cur_defs : log.info(" {} => {}".format(define, cur_defs[define])) else : log.info(' currently not in a valid project directory')
def _rec_fetch_imports(fips_dir, proj_dir, handled) : """internal recursive function to fetch project imports, keeps an array of already handled dirs to break cyclic dependencies :param proj_dir: current project directory :param handled: array of already handled dirs :returns: updated array of handled dirs """ ws_dir = util.get_workspace_dir(fips_dir) proj_name = util.get_project_name_from_dir(proj_dir) if proj_name not in handled : handled.append(proj_name) imports = get_imports(fips_dir, proj_dir) for dep in imports: dep_proj_name = dep if dep not in handled: dep_proj_dir = util.get_project_dir(fips_dir, dep_proj_name) log.colored(log.YELLOW, "=== dependency: '{}':".format(dep_proj_name)) dep_ok = False if not os.path.isdir(dep_proj_dir) : # directory did not exist, do a fresh git clone git_url = imports[dep_proj_name]['git'] git_branch = imports[dep_proj_name]['branch'] if git.clone(git_url, git_branch, dep_proj_name, ws_dir) : dep_ok = True else : log.error('failed to git clone {} into {}'.format(git_url, dep_proj_dir)) else : # directory already exists log.info("dir '{}' exists".format(dep_proj_dir)) dep_ok = True # recuse if dep_ok : handled = _rec_fetch_imports(fips_dir, dep_proj_dir, handled) # done, return the new handled array return handled
def setup(fips_dir, proj_dir) : """main setup function""" log.colored(log.YELLOW, '=== setup NaCl SDK:') ensure_sdk_dirs(fips_dir) # download SDK archive if not os.path.isfile(get_archive_path(fips_dir)) : log.info("downloading...") urllib.urlretrieve(get_sdk_url(), get_archive_path(fips_dir), util.url_download_hook) else : log.info("'nacl_sdk.zip' already exists") # uncompress SDK archive log.info("unpacking...") uncompress(fips_dir, get_archive_path(fips_dir)) # setup SDK log.info("setup NaCl SDK...") update_nacl_sdk(fips_dir) log.colored(log.GREEN, "done.")
def setup(fips_dir, proj_dir) : """setup the emscripten SDK from scratch""" log.colored(log.YELLOW, '=== setup emscripten SDK:') ensure_sdk_dirs(fips_dir) # download SDK archive if not os.path.isfile(get_archive_path(fips_dir)) : log.info("downloading '{}'...".format(get_archive_name())) urllib.request.urlretrieve(get_sdk_url(), get_archive_path(fips_dir), util.url_download_hook) else : log.info("'{}' already exists".format(get_archive_name())) # uncompress SDK archive log.info("uncompressing '{}'...".format(get_archive_name())) uncompress(get_archive_path(fips_dir), get_sdk_dir(fips_dir), 'emsdk_portable') # setup SDK log.info("setup emscripten SDK...") finish(get_emsdk_dir(fips_dir)) log.colored(log.GREEN, "done.")
def gen(fips_dir, proj_dir, cfg_name) : """generate build files with cmake :param fips_dir: absolute path to fips :param proj_dir: absolute path to project :param cfg_name: config name or pattern (e.g. osx-make-debug) :returns: True if successful """ # prepare dep.fetch_imports(fips_dir, proj_dir) proj_name = util.get_project_name_from_dir(proj_dir) util.ensure_valid_project_dir(proj_dir) dep.gather_and_write_imports(fips_dir, proj_dir) # load the config(s) configs = config.load(fips_dir, proj_dir, cfg_name) num_valid_configs = 0 if configs : for cfg in configs : # check if config is valid config_valid, _ = config.check_config_valid(fips_dir, cfg, print_errors = True) if config_valid : if gen_project(fips_dir, proj_dir, cfg, True) : num_valid_configs += 1 else : log.error("failed to generate build files for config '{}'".format(cfg['name']), False) else : log.error("'{}' is not a valid config".format(cfg['name']), False) else : log.error("No configs found for '{}'".format(cfg_name)) if num_valid_configs != len(configs) : log.error('{} out of {} configs failed!'.format(len(configs) - num_valid_configs, len(configs))) return False else : log.colored(log.GREEN, '{} configs generated'.format(num_valid_configs)) return True
def valgrind(fips_dir, proj_dir, cfg_name, target, target_args) : """debug a single target with valgrind""" # prepare proj_name = util.get_project_name_from_dir(proj_dir) util.ensure_valid_project_dir(proj_dir) # load the config(s) configs = config.load(fips_dir, proj_dir, cfg_name) if configs : for cfg in configs : # check if config is valid config_valid, _ = config.check_config_valid(fips_dir, proj_dir, cfg, print_errors = True) if config_valid : deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg['name']) valgrind_bin = settings.get(proj_dir, 'valgrind') if not valgrind_bin : valgrind_bin = 'valgrind' log.colored(log.YELLOW, "=== valgrind: {} ({})".format(cfg['name'], valgrind_bin)) cmd_line = valgrind_bin if target_args : cmd_line += ' ' + ' '.join(target_args) else : cmd_line += ' ' + '--leak-check=no' cmd_line += ' ' + '--show-reachable=yes' cmd_line += ' ' + '--track-fds=yes' cmd_line += ' ' + '--run-libc-freeres=no' cmd_line += ' ' + "--log-file={}/valgrind-{}.log".format(proj_dir, target) cmd_line += ' ' + "./{}".format(target) #log.colored(log.GREEN, "cmdline: {}".format(cmd_line)) subprocess.call(args = cmd_line, cwd = deploy_dir, shell = True) else : log.error("Config '{}' not valid in this environment".format(cfg['name'])) else : log.error("No valid configs found for '{}'".format(cfg_name)) return True
def list_targets(fips_dir, proj_dir, args) : log.colored(log.YELLOW, "=== targets:") if util.is_valid_project_dir(proj_dir) : # get config name if len(args) == 0 : cfg_name = settings.get(proj_dir, 'config') else : cfg_name = args[0] log.info('{} config:{} {}'.format(log.BLUE, log.DEF, cfg_name)) # get the target list success, targets = project.get_target_list(fips_dir, proj_dir, cfg_name) if success : # split targets by type for type in ['lib', 'module', 'sharedlib', 'app'] : type_targets = [tgt for tgt in targets if targets[tgt] == type] if len(type_targets) > 0 : log.colored(log.BLUE, ' {}:'.format(type)) for tgt in type_targets : log.info(' ' + tgt) else : log.info(" can't fetch project target list, please run 'fips gen' first!") else : log.info(' currently not in a valid project directory')
def setup(fips_dir, proj_dir) : """setup the Android SDK and NDK""" log.colored(log.YELLOW, '=== setup Android SDK/NDK :') # first make sure that java is present, otherwise the Android # SDK setup will finish without errors, but is not actually usable if not java.check_exists(fips_dir) : log.error("please install java first (see './fips diag tools')") ensure_sdk_dirs(fips_dir) # download and setup the Android SDK sdk_archive_path = get_androidsdk_archive_path(fips_dir) if not os.path.isfile(sdk_archive_path) : sdk_url = get_sdk_url() log.info("downloading '{}'...".format(sdk_url)) urllib.urlretrieve(sdk_url, sdk_archive_path, util.url_download_hook) else : log.info("'{}' already exists".format(sdk_archive_path)) log.info("\nunpacking '{}'...".format(sdk_archive_path)) uncompress(fips_dir, sdk_archive_path) log.info("downloading additional SDK files...") update_android_sdk(fips_dir, proj_dir) # download the Android NDK ndk_archive_path = get_androidndk_archive_path(fips_dir) if not os.path.isfile(ndk_archive_path) : ndk_url = get_ndk_url() log.info("downloading '{}'...".format(ndk_url)) urllib.urlretrieve(ndk_url, ndk_archive_path, util.url_download_hook) else : log.info("'{}' already exists".format(ndk_archive_path)) log.info("\nunpacking '{}'...".format(ndk_archive_path)) uncompress(fips_dir, ndk_archive_path) log.colored(log.GREEN, "done.")
def clean(fips_dir, proj_dir, cfg_name) : """clean build files :param fips_dir: absolute path of fips :param proj_dir: absolute project path :param cfg_name: config name (or pattern) """ proj_name = util.get_project_name_from_dir(proj_dir) configs = config.load(fips_dir, proj_dir, cfg_name) if configs : for cfg in configs : log.colored(log.YELLOW, "=== clean: {}".format(cfg['name'])) build_dir = util.get_build_dir(fips_dir, proj_name, cfg) if os.path.isdir(build_dir) : shutil.rmtree(build_dir) log.info(" deleted '{}'".format(build_dir)) deploy_dir = util.get_deploy_dir(fips_dir, proj_name, cfg) if os.path.isdir(deploy_dir) : shutil.rmtree(deploy_dir) log.info(" deleted '{}'".format(deploy_dir)) else : log.error("No valid configs found for '{}'".format(cfg_name))
def check_configs(fips_dir, proj_dir) : """find configs and check if they are valid""" log.colored(log.YELLOW, '=== configs:') dirs = [ fips_dir ] configs = config.load(fips_dir, proj_dir, '*') for cfg in configs : log.colored(log.BLUE, cfg['name']) valid, errors = config.check_config_valid(fips_dir, cfg) if valid : log.colored(log.GREEN, ' ok') else : for error in errors : log.info(' {}'.format(error))
def _rec_fetch_imports(fips_dir, proj_dir, handled) : """internal recursive function to fetch project imports, keeps an array of already handled dirs to break cyclic dependencies :param proj_dir: current project directory :param handled: array of already handled dirs :returns: updated array of handled dirs """ ws_dir = util.get_workspace_dir(fips_dir) proj_name = util.get_project_name_from_dir(proj_dir) if proj_name not in handled : handled.append(proj_name) imports = get_imports(fips_dir, proj_dir) for dep in imports: dep_proj_name = dep if dep not in handled: dep_proj_dir = util.get_project_dir(fips_dir, dep_proj_name) log.colored(log.YELLOW, "=== dependency: '{}':".format(dep_proj_name)) dep_ok = False if not os.path.isdir(dep_proj_dir) : # directory did not exist, do a fresh git clone dep = imports[dep_proj_name] git_commit = None if 'rev' not in dep else dep['rev'] if git_commit : if 'depth' in dep : # when using rev, we may not want depth because the revision may not be reachable log.colored(log.YELLOW, "=== 'depth' was ignored because parameter 'rev' is specified.") dep['depth'] = None git_depth = git.clone_depth if not git_commit and 'depth' not in dep else dep['depth'] git_url = dep['git'] git_branch = dep['branch'] if git.clone(git_url, git_branch, git_depth, dep_proj_name, ws_dir) : if git_commit : log.colored(log.YELLOW, "=== revision: '{}':".format(git_commit)) dep_ok = git.checkout(dep_proj_dir, git_commit) else : dep_ok = True else : log.error('failed to git clone {} into {}'.format(git_url, dep_proj_dir)) else : # directory already exists log.info("dir '{}' exists".format(dep_proj_dir)) dep_ok = True # recuse if dep_ok : handled = _rec_fetch_imports(fips_dir, dep_proj_dir, handled) # done, return the new handled array return handled