Use case
This page introduce typical use cases for bbclient. Please do setup like below before each use cases.
import bbclient
project_path: str = "path/to/poky"
init_command: str = "any_init_script_like_oe_init_env"
client: BBClient = BBClient(project_path, init_command)
client.start_server()
# You can do anything you want. See each use cases.
# You have to stop_server when closing
client.stop_server()
Use cases for whole project
Build package
client.build_targets(["busybox"], "compile")
Please note that this command will kick all the tasks target depends, so it maybe taks so much time.
Get all recipes in layers
ret: List[GetRecipesResult] = client.get_recipes()
for i in ret:
print(i.package_name)
print(i.recipe_files)
or
ret: List[GetRecipeVersionsResult] = client.get_recipe_versions()
for i in ret:
print(i.recipe_file_path)
print(i.pe)
print(i.pv)
print(i.pr)
There are many other commands to get all recipes in layers.
Get all recipes that inherits specific recipe
ret: List[GetRecipeInheritsResult] = client.get_recipe_inherits()
imatges = [i for i in ret if "/PATH/TO/poky/meta/classes/core-image.bbclass" in i.inherit_file_paths]
for i in imatges:
print(i.recipe_file_path)
Get all recipes that provides specific package
ret: List[FindProvidersResult] = client.find_providers()
imatges = [i for i in ret if "gcc" in i.package_name]
for i in imatges:
print(i.latest_recipe_file_path)
print(i.latest_pe)
print(i.latest_pv)
print(i.latest_pr)
print(i.latest_recipe_file_path)
print(i.preffered_pe)
print(i.preffered_pv)
print(i.preffered_pr)
print(i.preffered_recipe_file_path)
print(i.required_version)
Get global variable
ret: str = client.get_variable("MACHINE")
print(ret)
Get all layers
ret: List[GetLayerPrioritiesResult] = client.get_layer_priorities()
for i in ret:
print(i.name)
print(i.path)
print(i.priority)
or
ret: str = client.get_variable("BBLAYERS")
print(ret)
Generate dependency dot file
You can get task-depends.dot and pn-depends file like below.
These files will be writtene at the root of the yocto porject.
client.generate_dot_graph(["gcc"], "build")
task-depends provides dependency info between recipes. See here
Use cases for one specific recipe
Get one specific variable in one specific package
ret: List[str] = client.find_best_provider("gcc")
target_recipe_file_path: str = ret[3]
data_store_index: int = client.parse_recipe_file(target_recipe_file_path)
ret: Any = client.data_store_connector_cmd(data_store_index, "getVar", "FILE")
print(ret)
Get all variables in one specific recipe
inx: int = client.parse_recipe_file("/PATH/TO/RECIPE/psplash_git.bb")
keys: KeysView = client.data_store_connector_cmd(inx, "keys")
for key in keys:
var: str = client.data_store_connector_cmd(inx, "getVar", key)
print(f"{key}: {var}")
Get all appends files for one specific recipe
ret: List[str] = client.get_file_appends("/PATH/TO/RECIPE/psplash_git.bb")
print(ret)
Get all inherit files for one specific recipe
ret: List[GetRecipeInheritsResult] = client.get_recipe_inherits()
imatges = [i for i in ret if "/PATH/TO/poky/meta/classes/core-image.bbclass" in i.inherit_file_paths]
for i in imatges:
print(i.recipe_file_path)
Get all inherit files for one specific recipe
ret: List[GetRecipeInheritsResult] = client.get_recipe_inherits()
itr = filter(lambda x: x.recipe_file_path == "/PATH/TO/RECIPE/psplash_git.bb", ret)
result = next(itr, None)
print(result.inherit_file_paths)
Run a task
client.build_targets(["busybox"], "fetch")
client.build_targets(["busybox"], "patch")
Monitor callback events
You can monitor various events from bitbake server.
def monitor_callback(bbclient_:BBClient, event: ProcessProgressEvent):
print(event.pid)
print(event.processname)
print(event.progress)
callback_index:int = client.register_callback(ProcessProgressEvent, monitor_callback)
client.build_targets(["curl"], "compile")
client.unregister_callback(callback_index)