Application Runtimes and Containers¶
A core abstraction in the design of builder is
This provides a way to setup and execute processes within a given environment.
That environment could be your host operating system, a container, a build environment, or even a remote system.
For example, if we want to run the
make command for your project and that project is targeting the GNOME Sdk we need to first enter the SDK environment.
The Flatpak plugin provides an
Ide.Runtime implementation to do this so that before your subprocess is lanched, the runtime is setup and initialized for execution with an alternate mount namespace, network namespace, and more.
How to get a runtime¶
If you need to run a process within the build environment you will want to access the runtime for the current build configuration.
The current build configuration can be accessed from the
config_manager = context.get_configuration_manager() config = config_manager.get_current() runtime = config.get_runtime()
It is possible that the configured runtime does not yet exist, so remember to check for
Creating a Subprocess¶
To create a subprocess in the runtime, use the
Ide.Subprocess.create_launcher() method and then spawn a process using that launcher.
try: launcher = runtime.create_launcher() launcher.push_argv('which') launcher.push_argv('make') subprocess = launcher.spawn(None) _, stdout, stderr = subprocess.communicate_utf8(None, None) except Exception as ex: print("Failed to create launcher: " + repr(ex)) return