yocto-kernel: create open_user_file() wrapper function
With the addition of custom kernels, we can no longer rely on a hard-coded /files directory for BSPs - we need to be able to find the user_config/patches files in a number of different directories. We now hide the search inside a new open_user_file() function that accomplishes the same thing as before but with a more flexible scope. (From meta-yocto rev: 26a7032553e8d8691239368f0f994f948db06eed) Signed-off-by: Tom Zanussi <tom.zanussi@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
125eb6f390
commit
be93447bef
|
@ -133,6 +133,30 @@ def gen_choices_str(choices):
|
||||||
return choices_str
|
return choices_str
|
||||||
|
|
||||||
|
|
||||||
|
def open_user_file(scripts_path, machine, userfile, mode):
|
||||||
|
"""
|
||||||
|
Find one of the user files (user-config.cfg, user-patches.scc)
|
||||||
|
associated with the machine (could be in files/,
|
||||||
|
linux-yocto-custom/, etc). Returns the open file if found, None
|
||||||
|
otherwise.
|
||||||
|
|
||||||
|
The caller is responsible for closing the file returned.
|
||||||
|
"""
|
||||||
|
layer = find_bsp_layer(scripts_path, machine)
|
||||||
|
linuxdir = os.path.join(layer, "recipes-kernel/linux")
|
||||||
|
linuxdir_list = os.listdir(linuxdir)
|
||||||
|
for fileobj in linuxdir_list:
|
||||||
|
fileobj_path = os.path.join(linuxdir, fileobj)
|
||||||
|
if os.path.isdir(fileobj_path):
|
||||||
|
userfile_name = os.path.join(fileobj_path, userfile)
|
||||||
|
try:
|
||||||
|
f = open(userfile_name, mode)
|
||||||
|
return f
|
||||||
|
except IOError:
|
||||||
|
continue
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def read_config_items(scripts_path, machine):
|
def read_config_items(scripts_path, machine):
|
||||||
"""
|
"""
|
||||||
Find and return a list of config items (CONFIG_XXX) in a machine's
|
Find and return a list of config items (CONFIG_XXX) in a machine's
|
||||||
|
@ -140,10 +164,7 @@ def read_config_items(scripts_path, machine):
|
||||||
"""
|
"""
|
||||||
config_items = []
|
config_items = []
|
||||||
|
|
||||||
layer = find_bsp_layer(scripts_path, machine)
|
f = open_user_file(scripts_path, machine, "user-config.cfg", "r")
|
||||||
cfg = os.path.join(layer, "recipes-kernel/linux/files/user-config.cfg")
|
|
||||||
|
|
||||||
f = open(cfg, "r")
|
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
s = line.strip()
|
s = line.strip()
|
||||||
|
@ -159,10 +180,7 @@ def write_config_items(scripts_path, machine, config_items):
|
||||||
Write (replace) the list of config items (CONFIG_XXX) in a
|
Write (replace) the list of config items (CONFIG_XXX) in a
|
||||||
machine's user-defined config fragment [user-config.cfg].
|
machine's user-defined config fragment [user-config.cfg].
|
||||||
"""
|
"""
|
||||||
layer = find_bsp_layer(scripts_path, machine)
|
f = open_user_file(scripts_path, machine, "user-config.cfg", "w")
|
||||||
cfg = os.path.join(layer, "recipes-kernel/linux/files/user-config.cfg")
|
|
||||||
|
|
||||||
f = open(cfg, "w")
|
|
||||||
for item in config_items:
|
for item in config_items:
|
||||||
f.write(item + "\n")
|
f.write(item + "\n")
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -377,10 +395,7 @@ def read_patch_items(scripts_path, machine):
|
||||||
"""
|
"""
|
||||||
patch_items = []
|
patch_items = []
|
||||||
|
|
||||||
layer = find_bsp_layer(scripts_path, machine)
|
f = open_user_file(scripts_path, machine, "user-patches.scc", "r")
|
||||||
patches = os.path.join(layer, "recipes-kernel/linux/files/user-patches.scc")
|
|
||||||
|
|
||||||
f = open(patches, "r")
|
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
s = line.strip()
|
s = line.strip()
|
||||||
|
@ -399,11 +414,7 @@ def write_patch_items(scripts_path, machine, patch_items):
|
||||||
Write (replace) the list of patches in a machine's user-defined
|
Write (replace) the list of patches in a machine's user-defined
|
||||||
patch list [user-patches.scc].
|
patch list [user-patches.scc].
|
||||||
"""
|
"""
|
||||||
layer = find_bsp_layer(scripts_path, machine)
|
f = open_user_file(scripts_path, machine, "user-patches.scc", "w")
|
||||||
|
|
||||||
patches = os.path.join(layer, "recipes-kernel/linux/files/user-patches.scc")
|
|
||||||
|
|
||||||
f = open(patches, "w")
|
|
||||||
for item in patch_items:
|
for item in patch_items:
|
||||||
pass
|
pass
|
||||||
# this currently breaks do_patch, but is really what we want
|
# this currently breaks do_patch, but is really what we want
|
||||||
|
|
Loading…
Reference in New Issue