From f0065d7a6973628803a17c57f2265512aba3234c Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Tue, 31 Jul 2012 01:06:26 +0100 Subject: combo-layer: allow splitting out local config Allow splitting the local parts of the configuration (mostly local_repo_dir and last_revision, although there is no limitation) to a side-by-side -local.conf file, with component sections optionally tagged with the combo layer branch name. This effectively allows you to: * avoid polluting the history by committing the updated last revision to the combo repository for every update * avoid putting local repo paths into the combo repository * manage multiple branches of the combo repository whilst avoiding the possibility of mixing the configuration for one branch with another. An example split configuration (note, values may be artificial): ------------------- combo-layer.conf ------------------- [bitbake] src_uri = git://git.openembedded.org/bitbake dest_dir = bitbake hook = scripts/combo-layer-hook-default.sh [oe-core] src_uri = git://git.openembedded.org/openembedded-core dest_dir = . hook = scripts/combo-layer-hook-default.sh -------------------------------------------------------- ---------------- combo-layer-local.conf ---------------- [bitbake] local_repo_dir = ../repos/bitbake [oe-core] local_repo_dir = ../repos/oe-core [bitbake|master] branch = master last_revision = db689a99beffea1a285cdfc74a58fe73f1666987 [oe-core|master] branch = master last_revision = 121a1499a81706366acc0081272a6bff634d4d62 [bitbake|denzil] branch = 1.12 last_revision = 24b631acdaa143a4de39c6e1328849660c66f219 [oe-core|denzil] branch = denzil last_revision = 741146fa90f28f7ce8d82ee7f7e254872d519724 -------------------------------------------------------- It is assumed that the local config file will be added to .gitignore. Signed-off-by: Paul Eggleton Signed-off-by: Richard Purdie --- scripts/combo-layer | 73 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 8 deletions(-) (limited to 'scripts/combo-layer') diff --git a/scripts/combo-layer b/scripts/combo-layer index 95653b0c21..516fffbec6 100755 --- a/scripts/combo-layer +++ b/scripts/combo-layer @@ -39,6 +39,15 @@ def logger_create(): logger = logger_create() +def get_current_branch(repodir=None): + try: + branchname = runcmd("git symbolic-ref HEAD 2>/dev/null", repodir).strip() + if branchname.startswith("refs/heads/"): + branchname = branchname[11:] + return branchname + except subprocess.CalledProcessError: + return "" + class Configuration(object): """ Manages the configuration @@ -49,30 +58,78 @@ class Configuration(object): def __init__(self, options): for key, val in options.__dict__.items(): setattr(self, key, val) - self.parser = ConfigParser.ConfigParser() - self.parser.readfp(open(self.conffile)) - self.repos = {} - for repo in self.parser.sections(): - self.repos[repo] = {} - for (name, value) in self.parser.items(repo): + + def readsection(parser, section, repo): + for (name, value) in parser.items(section): if value.startswith("@"): self.repos[repo][name] = eval(value.strip("@")) else: self.repos[repo][name] = value + logger.debug("Loading config file %s" % self.conffile) + self.parser = ConfigParser.ConfigParser() + with open(self.conffile) as f: + self.parser.readfp(f) + + self.repos = {} + for repo in self.parser.sections(): + self.repos[repo] = {} + readsection(self.parser, repo, repo) + + # Load local configuration, if available + self.localconffile = None + self.localparser = None + self.combobranch = None + if self.conffile.endswith('.conf'): + lcfile = self.conffile.replace('.conf', '-local.conf') + if os.path.exists(lcfile): + # Read combo layer branch + self.combobranch = get_current_branch() + logger.debug("Combo layer branch is %s" % self.combobranch) + + self.localconffile = lcfile + logger.debug("Loading local config file %s" % self.localconffile) + self.localparser = ConfigParser.ConfigParser() + with open(self.localconffile) as f: + self.localparser.readfp(f) + + for section in self.localparser.sections(): + if '|' in section: + sectionvals = section.split('|') + repo = sectionvals[0] + if sectionvals[1] != self.combobranch: + continue + else: + repo = section + if repo in self.repos: + readsection(self.localparser, section, repo) + def update(self, repo, option, value): - self.parser.set(repo, option, value) - self.parser.write(open(self.conffile, "w")) + if self.localparser: + parser = self.localparser + section = "%s|%s" % (repo, self.combobranch) + conffile = self.localconffile + else: + parser = self.parser + section = repo + conffile = self.conffile + parser.set(section, option, value) + with open(conffile, "w") as f: + parser.write(f) def sanity_check(self): required_options=["src_uri", "local_repo_dir", "dest_dir", "last_revision"] msg = "" + missing_options = [] for name in self.repos: for option in required_options: if option not in self.repos[name]: msg = "%s\nOption %s is not defined for component %s" %(msg, option, name) + missing_options.append(option) if msg != "": logger.error("configuration file %s has the following error: %s" % (self.conffile,msg)) + if self.localconffile and 'last_revision' in missing_options: + logger.error("local configuration file %s may be missing configuration for combo branch %s" % (self.localconffile, self.combobranch)) sys.exit(1) # filterdiff is required by action_splitpatch, so check its availability -- cgit 1.2.3-korg