def update_build_system(addon_obj, addon_name, wescamp_dir, build_sys_dir): """Initialize or update the build-system. addon_obj libgithub.Addon objectof the addon. addon_name Name of the addon. wescamp_dir The directory containing a checkout of wescamp. build_sys_dir Possible directory containing a checkout of build-system. returns Boolean indicating whether the add-on now has a build-system. """ logging.info("Checking if build system for add-on {0} needs to be updated".format(addon_name)) previously_initialized = os.path.exists(os.path.join(addon_obj.get_dir(), "Makefile")) # Grab the build system below_branch = os.path.basename(wescamp_dir.rstrip(os.sep)) possible_build_paths = [] if build_sys_dir: possible_build_paths.append(build_sys_dir) possible_build_paths.append(os.path.join(below_branch, "build-system")) build_system = libgithub.get_build_system(possible_build_paths) init_script = os.path.join(build_system.get_dir(), "init-build-sys.sh") # Grab master build system's version # Ugliness out, err, res = build_system._execute(["git", "show", "--pretty=oneline", "--summary"]) build_system_version = out.split()[0] if len(build_system_version) != 40: logging.warn("Incorrect SHA1 for build system checkout: {0}".format(build_system_version)) # Check if build system version in add-on is up-to-date if os.path.exists(os.path.join(addon_obj.get_dir(), BUILDSYS_FILE)): with open(os.path.join(addon_obj.get_dir(), BUILDSYS_FILE), "r") as stamp_file: addon_build_version = stamp_file.read() if addon_build_version == build_system_version: logging.info("Build system for add-on {0} is up-to-date".format(addon_name)) return True # Ugliness out, err, res = addon_obj._execute([init_script, "--{0}".format(git_version), addon_name, "."], check_error=False) if len(err): logging.warn("init-build-sys.sh in add-on {0}:\n{1}".format(addon_name, err)) if not out.strip().endswith("Done.") or res != 0: logging.error("Failed to init the build-system for add-on {0}".format(addon_name)) addon_obj._execute(["rm", "-rf", "po", "campaign.def", "Makefile"]) addon_obj._execute(["git", "reset", "--hard"]) return False # Store build system version with open(os.path.join(addon_obj.get_dir(), BUILDSYS_FILE), "w") as version_file: version_file.write(build_system_version) addon_obj._execute(["git", "add", "po", "campaign.def", "Makefile", BUILDSYS_FILE], check_error=True) if previously_initialized: logging.info("Updated build system for add-on {0}".format(addon_name)) addon_obj.commit("wescamp.py: Update build-system") else: logging.info("Initialized build system for add-on {0}".format(addon_name)) addon_obj.commit("wescamp.py: Initialize build-system") return True