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 _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