1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-08 17:19:20 +00:00

hob: use both pre and post files for hob configuration

We need to set various variables *before* parse begins, the simplest way
to ensure this is to use a pre configuration file for the relevant
configuration entries.

This series adapts hob to use both pre and post files to store its
configuration. Any variables which affect initial parse are set in the pre
file and all others in the post file.

Unfortunately this requires hob related code to have even more hard-coded
data as to what is relevant but this is the simplest way to solve issues
with variables and parse order at this time.

Addresses [YOCTO #1281]

(Bitbake rev: 02ab0e11d8dd42f5ca440b3d8d2073e23f55113a)

Signed-off-by: Joshua Lock <josh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Joshua Lock
2011-09-01 20:38:10 -07:00
committed by Richard Purdie
parent ba91445de5
commit cffbab5c06
4 changed files with 83 additions and 48 deletions
+63 -31
View File
@@ -40,12 +40,13 @@ class Configurator(gobject.GObject):
def __init__(self): def __init__(self):
gobject.GObject.__init__(self) gobject.GObject.__init__(self)
self.local = None
self.bblayers = None self.bblayers = None
self.enabled_layers = {} self.enabled_layers = {}
self.loaded_layers = {} self.loaded_layers = {}
self.config = {} self.config = {}
self.orig_config = {} self.orig_config = {}
self.preconf = None
self.postconf = None
# NOTE: cribbed from the cooker... # NOTE: cribbed from the cooker...
def _parse(self, f, data, include=False): def _parse(self, f, data, include=False):
@@ -55,18 +56,16 @@ class Configurator(gobject.GObject):
parselog.critical("Unable to parse %s: %s" % (f, exc)) parselog.critical("Unable to parse %s: %s" % (f, exc))
sys.exit(1) sys.exit(1)
def _loadLocalConf(self, path): def _loadConf(self, path):
def getString(var): def getString(var):
return bb.data.getVar(var, data, True) or "" return bb.data.getVar(var, data, True) or ""
self.local = path
if self.orig_config: if self.orig_config:
del self.orig_config del self.orig_config
self.orig_config = {} self.orig_config = {}
data = bb.data.init() data = bb.data.init()
data = self._parse(self.local, data) data = self._parse(path, data)
# We only need to care about certain variables # We only need to care about certain variables
mach = getString('MACHINE') mach = getString('MACHINE')
@@ -76,6 +75,8 @@ class Configurator(gobject.GObject):
if sdkmach and sdkmach != self.config.get('SDKMACHINE', ''): if sdkmach and sdkmach != self.config.get('SDKMACHINE', ''):
self.config['SDKMACHINE'] = sdkmach self.config['SDKMACHINE'] = sdkmach
distro = getString('DISTRO') distro = getString('DISTRO')
if not distro:
distro = "defaultsetup"
if distro and distro != self.config.get('DISTRO', ''): if distro and distro != self.config.get('DISTRO', ''):
self.config['DISTRO'] = distro self.config['DISTRO'] = distro
bbnum = getString('BB_NUMBER_THREADS') bbnum = getString('BB_NUMBER_THREADS')
@@ -109,10 +110,10 @@ class Configurator(gobject.GObject):
self.orig_config = copy.deepcopy(self.config) self.orig_config = copy.deepcopy(self.config)
def setLocalConfVar(self, var, val): def setConfVar(self, var, val):
self.config[var] = val self.config[var] = val
def getLocalConfVar(self, var): def getConfVar(self, var):
if var in self.config: if var in self.config:
return self.config[var] return self.config[var]
else: else:
@@ -135,9 +136,17 @@ class Configurator(gobject.GObject):
self.emit("layers-loaded") self.emit("layers-loaded")
def _addConfigFile(self, path): def _addConfigFile(self, path):
conffiles = ["local.conf", "hob-pre.conf", "hob-post.conf"]
pref, sep, filename = path.rpartition("/") pref, sep, filename = path.rpartition("/")
if filename == "local.conf" or filename == "hob.local.conf":
self._loadLocalConf(path) if filename == "hob-pre.conf":
self.preconf = path
if filename == "hob-post.conf":
self.postconf = path
if filename in conffiles:
self._loadConf(path)
elif filename == "bblayers.conf": elif filename == "bblayers.conf":
self._loadLayerConf(path) self._loadLayerConf(path)
@@ -220,22 +229,8 @@ class Configurator(gobject.GObject):
with open(conffile, "w") as new: with open(conffile, "w") as new:
new.write("".join(contents)) new.write("".join(contents))
def writeLocalConf(self): def updateConf(self, orig_lines, changed_values):
# Dictionary containing only new or modified variables new_config_lines = []
changed_values = {}
for var in self.config:
val = self.config[var]
if self.orig_config.get(var, None) != val:
changed_values[var] = val
if not len(changed_values):
return
# read the original conf into a list
with open(self.local, 'r') as config:
config_lines = config.readlines()
new_config_lines = ["\n"]
for var in changed_values: for var in changed_values:
# Convenience function for re.subn(). If the pattern matches # Convenience function for re.subn(). If the pattern matches
# return a string which contains an assignment using the same # return a string which contains an assignment using the same
@@ -254,10 +249,10 @@ class Configurator(gobject.GObject):
# Iterate over the local.conf lines and if they are a match # Iterate over the local.conf lines and if they are a match
# for the pattern comment out the line and append a new line # for the pattern comment out the line and append a new line
# with the new VAR op "value" entry # with the new VAR op "value" entry
for line in config_lines: for line in orig_lines:
new_line, replacements = p.subn(replace_val, line) new_line, replacements = p.subn(replace_val, line)
if replacements: if replacements:
config_lines[cnt] = "#%s" % line orig_lines[cnt] = "#%s" % line
new_config_lines.append(new_line) new_config_lines.append(new_line)
replaced = True replaced = True
cnt = cnt + 1 cnt = cnt + 1
@@ -266,16 +261,53 @@ class Configurator(gobject.GObject):
new_config_lines.append("%s = \"%s\"\n" % (var, changed_values[var])) new_config_lines.append("%s = \"%s\"\n" % (var, changed_values[var]))
# Add the modified variables # Add the modified variables
config_lines.extend(new_config_lines) orig_lines.extend(new_config_lines)
return orig_lines
self.writeConfFile(self.local, config_lines) def writeConf(self):
pre_vars = ["MACHINE", "SDKMACHINE", "DISTRO",
"INCOMPATIBLE_LICENSE"]
post_vars = ["BB_NUMBER_THREADS", "PARALLEL_MAKE", "PACKAGE_CLASSES",
"IMAGE_FSTYPES", "HOB_BUILD_TOOLCHAIN",
"HOB_BUILD_TOOLCHAIN_HEADERS"]
pre_values = {}
post_values = {}
changed_values = {}
pre_lines = None
post_lines = None
for var in self.config:
val = self.config[var]
if self.orig_config.get(var, None) != val:
changed_values[var] = val
if not len(changed_values):
return
for var in changed_values:
if var in pre_vars:
pre_values[var] = changed_values[var]
elif var in post_vars:
post_values[var] = changed_values[var]
with open(self.preconf, 'r') as pre:
pre_lines = pre.readlines()
pre_lines = self.updateConf(pre_lines, pre_values)
if len(pre_lines):
self.writeConfFile(self.preconf, pre_lines)
with open(self.postconf, 'r') as post:
post_lines = post.readlines()
post_lines = self.updateConf(post_lines, post_values)
if len(post_lines):
self.writeConfFile(self.postconf, post_lines)
del self.orig_config del self.orig_config
self.orig_config = copy.deepcopy(self.config) self.orig_config = copy.deepcopy(self.config)
def insertTempBBPath(self, bbpath, bbfiles): def insertTempBBPath(self, bbpath, bbfiles):
# read the original conf into a list # read the original conf into a list
with open(self.local, 'r') as config: with open(self.postconf, 'r') as config:
config_lines = config.readlines() config_lines = config.readlines()
if bbpath: if bbpath:
@@ -283,7 +315,7 @@ class Configurator(gobject.GObject):
if bbfiles: if bbfiles:
config_lines.append("BBFILES := \"${BBFILES} %s\"\n" % bbfiles) config_lines.append("BBFILES := \"${BBFILES} %s\"\n" % bbfiles)
self.writeConfFile(self.local, config_lines) self.writeConfFile(self.postconf, config_lines)
def writeLayerConf(self): def writeLayerConf(self):
# If we've not added/removed new layers don't write # If we've not added/removed new layers don't write
+7 -4
View File
@@ -65,7 +65,7 @@ class HobHandler(gobject.GObject):
gobject.TYPE_STRING,)), gobject.TYPE_STRING,)),
} }
(CFG_PATH_LOCAL, CFG_PATH_HOB, CFG_PATH_LAYERS, CFG_FILES_DISTRO, CFG_FILES_MACH, CFG_FILES_SDK, FILES_MATCH_CLASS, GENERATE_TGTS, REPARSE_FILES, BUILD_IMAGE) = range(10) (CFG_PATH_LOCAL, CFG_PATH_PRE, CFG_PATH_POST, CFG_PATH_LAYERS, CFG_FILES_DISTRO, CFG_FILES_MACH, CFG_FILES_SDK, FILES_MATCH_CLASS, GENERATE_TGTS, REPARSE_FILES, BUILD_IMAGE) = range(11)
def __init__(self, taskmodel, server): def __init__(self, taskmodel, server):
gobject.GObject.__init__(self) gobject.GObject.__init__(self)
@@ -90,9 +90,12 @@ class HobHandler(gobject.GObject):
self.generating = True self.generating = True
if self.current_command == self.CFG_PATH_LOCAL: if self.current_command == self.CFG_PATH_LOCAL:
self.current_command = self.CFG_PATH_HOB self.current_command = self.CFG_PATH_PRE
self.server.runCommand(["findConfigFilePath", "hob.local.conf"]) self.server.runCommand(["findConfigFilePath", "hob-pre.conf"])
elif self.current_command == self.CFG_PATH_HOB: elif self.current_command == self.CFG_PATH_PRE:
self.current_command = self.CFG_PATH_POST
self.server.runCommand(["findConfigFilePath", "hob-post.conf"])
elif self.current_command == self.CFG_PATH_POST:
self.current_command = self.CFG_PATH_LAYERS self.current_command = self.CFG_PATH_LAYERS
self.server.runCommand(["findConfigFilePath", "bblayers.conf"]) self.server.runCommand(["findConfigFilePath", "bblayers.conf"])
elif self.current_command == self.CFG_PATH_LAYERS: elif self.current_command == self.CFG_PATH_LAYERS:
+11 -11
View File
@@ -38,13 +38,13 @@ class HobPrefs(gtk.Dialog):
else: else:
self.selected_image_types = handler.remove_image_output_type(ot) self.selected_image_types = handler.remove_image_output_type(ot)
self.configurator.setLocalConfVar('IMAGE_FSTYPES', "%s" % " ".join(self.selected_image_types).lstrip(" ")) self.configurator.setConfVar('IMAGE_FSTYPES', "%s" % " ".join(self.selected_image_types).lstrip(" "))
def sdk_machine_combo_changed_cb(self, combo, handler): def sdk_machine_combo_changed_cb(self, combo, handler):
sdk_mach = combo.get_active_text() sdk_mach = combo.get_active_text()
if sdk_mach != self.curr_sdk_mach: if sdk_mach != self.curr_sdk_mach:
self.curr_sdk_mach = sdk_mach self.curr_sdk_mach = sdk_mach
self.configurator.setLocalConfVar('SDKMACHINE', sdk_mach) self.configurator.setConfVar('SDKMACHINE', sdk_mach)
handler.set_sdk_machine(sdk_mach) handler.set_sdk_machine(sdk_mach)
def update_sdk_machines(self, handler, sdk_machines): def update_sdk_machines(self, handler, sdk_machines):
@@ -67,7 +67,7 @@ class HobPrefs(gtk.Dialog):
distro = combo.get_active_text() distro = combo.get_active_text()
if distro != self.curr_distro: if distro != self.curr_distro:
self.curr_distro = distro self.curr_distro = distro
self.configurator.setLocalConfVar('DISTRO', distro) self.configurator.setConfVar('DISTRO', distro)
handler.set_distro(distro) handler.set_distro(distro)
self.reload_required = True self.reload_required = True
@@ -91,7 +91,7 @@ class HobPrefs(gtk.Dialog):
package_format = combo.get_active_text() package_format = combo.get_active_text()
if package_format != self.curr_package_format: if package_format != self.curr_package_format:
self.curr_package_format = package_format self.curr_package_format = package_format
self.configurator.setLocalConfVar('PACKAGE_CLASSES', 'package_%s' % package_format) self.configurator.setConfVar('PACKAGE_CLASSES', 'package_%s' % package_format)
handler.set_package_format(package_format) handler.set_package_format(package_format)
self.reload_required = True self.reload_required = True
@@ -113,7 +113,7 @@ class HobPrefs(gtk.Dialog):
def include_gplv3_cb(self, toggle): def include_gplv3_cb(self, toggle):
excluded = toggle.get_active() excluded = toggle.get_active()
orig_incompatible = self.configurator.getLocalConfVar('INCOMPATIBLE_LICENSE') orig_incompatible = self.configurator.getConfVar('INCOMPATIBLE_LICENSE')
new_incompatible = "" new_incompatible = ""
if excluded: if excluded:
if not orig_incompatible: if not orig_incompatible:
@@ -125,18 +125,18 @@ class HobPrefs(gtk.Dialog):
if new_incompatible != orig_incompatible: if new_incompatible != orig_incompatible:
self.handler.set_incompatible_license(new_incompatible) self.handler.set_incompatible_license(new_incompatible)
self.configurator.setLocalConfVar('INCOMPATIBLE_LICENSE', new_incompatible) self.configurator.setConfVar('INCOMPATIBLE_LICENSE', new_incompatible)
self.reload_required = True self.reload_required = True
def change_bb_threads_cb(self, spinner): def change_bb_threads_cb(self, spinner):
val = spinner.get_value_as_int() val = spinner.get_value_as_int()
self.handler.set_bbthreads(val) self.handler.set_bbthreads(val)
self.configurator.setLocalConfVar('BB_NUMBER_THREADS', val) self.configurator.setConfVar('BB_NUMBER_THREADS', val)
def change_make_threads_cb(self, spinner): def change_make_threads_cb(self, spinner):
val = spinner.get_value_as_int() val = spinner.get_value_as_int()
self.handler.set_pmake(val) self.handler.set_pmake(val)
self.configurator.setLocalConfVar('PARALLEL_MAKE', "-j %s" % val) self.configurator.setConfVar('PARALLEL_MAKE', "-j %s" % val)
def toggle_toolchain_cb(self, check): def toggle_toolchain_cb(self, check):
enabled = check.get_active() enabled = check.get_active()
@@ -144,7 +144,7 @@ class HobPrefs(gtk.Dialog):
if enabled: if enabled:
toolchain = '1' toolchain = '1'
self.handler.toggle_toolchain(enabled) self.handler.toggle_toolchain(enabled)
self.configurator.setLocalConfVar('HOB_BUILD_TOOLCHAIN', toolchain) self.configurator.setConfVar('HOB_BUILD_TOOLCHAIN', toolchain)
def toggle_headers_cb(self, check): def toggle_headers_cb(self, check):
enabled = check.get_active() enabled = check.get_active()
@@ -152,13 +152,13 @@ class HobPrefs(gtk.Dialog):
if enabled: if enabled:
headers = '1' headers = '1'
self.handler.toggle_toolchain_headers(enabled) self.handler.toggle_toolchain_headers(enabled)
self.configurator.setLocalConfVar('HOB_BUILD_TOOLCHAIN_HEADERS', headers) self.configurator.setConfVar('HOB_BUILD_TOOLCHAIN_HEADERS', headers)
def set_parent_window(self, parent): def set_parent_window(self, parent):
self.set_transient_for(parent) self.set_transient_for(parent)
def write_changes(self): def write_changes(self):
self.configurator.writeLocalConf() self.configurator.writeConf()
def prefs_response_cb(self, dialog, response): def prefs_response_cb(self, dialog, response):
if self.reload_required: if self.reload_required:
+2 -2
View File
@@ -192,8 +192,8 @@ class MainWindow (gtk.Window):
self.curr_mach = mach self.curr_mach = mach
# Flush this straight to the file as MACHINE is changed # Flush this straight to the file as MACHINE is changed
# independently of other 'Preferences' # independently of other 'Preferences'
self.configurator.setLocalConfVar('MACHINE', mach) self.configurator.setConfVar('MACHINE', mach)
self.configurator.writeLocalConf() self.configurator.writeConf()
handler.set_machine(mach) handler.set_machine(mach)
handler.reload_data() handler.reload_data()