kas Setup Tool

repository·master·Indexed 20 days ago

https://github.com/siemens/kas

A setup tool for bitbake-based projects that automates downloading, configuration, and execution of builds using a project configuration file. It provides a CLI with plugins for building, checking out source code, cleaning environments, managing dependency locks, and generating SLSA provenance attestations.

Tokens
20.2K
Snippets
65
Records
112
Agent score
69%

What's inside kas

  1. Overview of kas for bitbake projects

    master

    kas is a setup tool designed to automate the configuration and build process for bitbake-based projects. Unlike manual OpenEmbedded workflows where source downloading and configuration are handled by hand (often following a README), kas uses a project configuration file to automate the download and configuration phases.

    Key capabilities include:

    • Cloning and checking out bitbake layers.
    • Creating default bitbake settings (e.g., machine, architecture).
    • Launching a minimal build environment to reduce the risk of host contamination.
    • Initiating the bitbake build process.
  2. Available kas sub-commands (Plugins)

    master

    The kas CLI is extended via a plugin system where each plugin typically implements one or more sub-commands. The following sub-commands are available through the kas command line interface:

    • build: Executes the build process.
    • checkout: Handles repository checkouts.
    • clean: Performs cleaning operations.
    • cleanall: Performs deep cleaning of all components.
    • cleansstate: Cleans the sstate-cache.
    • diff: Compares differences.
    • diff: Compares differences.
    • dump: Dumps configuration or state information.
    • for-all-repos: Runs a command across all repositories.
    • lock: Manages locks.
    • menu: Displays a command menu.
    • purge: Performs purging operations.
    • shell: Opens a shell within the configured environment.
  3. Include configuration files from the same or other repositories

    master

    Kas supports modular configurations through an includes mechanism within the header section.

    In-tree includes

    To include files from the same repository, provide relative paths:

    header:
      version: x
      includes:
        - base.yml
        - bsp.yml

    Cross-repository includes

    To include files from other repositories, specify the repo and the file path:

    header:
      version: x
      includes:
        - repo: poky
          file: kas-poky.yml

    Merging and Overriding Rules

    • Order: Files are merged top-to-bottom and depth-first. Later files overwrite settings in earlier files.
    • Excluding Layers: You can prevent a layer from being added by an included file by setting its name to excluded in your repos section.
    • Recursive Merging: Dictionaries are merged recursively. local_conf_header entries are added in the order they are defined across includes.
    • Constraint: You cannot create circular references in repos entries. An included file must not change the reference of the repository it is included from.
    header:
      version: x
      includes:
        - repo: poky
          file: kas-poky.yml
        - repo: meta-bsp-collection
          file: hw1/kas-hw-bsp1.yml
    repos:
      poky:
        url: "https://git.yoctoproject.org/git/poky"
        commit: 89e6c98d92887913cadf06b2adb97f26cde4849b
        layers:
          meta-yocto-bsp: excluded
  4. Use lockfiles to pin repository commits

    master

    Lockfiles allow you to override the commit ID of a repository defined in a .yml configuration file.

    To use a lockfile, create a file named <original_filename>.lock.<extension> (e.g., kas-isar.yml -> kas-isar.lock.yml) in the same directory as the configuration file. Kas automatically detects and loads this lockfile before processing the main file.

    The lockfile should contain an overrides section to specify the new commit.

    # kas-isar.lock.yml
    header:
      version: 14
    overrides:
      repos:
        isar:
          commit: 0336610df8bb0adce76ef8c5a921c758efed9f45
  5. Use monkeykas for decoupled testing

    master

    To ensure tests are decoupled from the local environment, use the monkeykas fixture. This fixture cleans up the environment before each test.

    Environment Variables: Do not assume values for KAS_WORK_DIR or KAS_BUILD_DIR. Instead, use these monkeykas helpers to access paths safely:

    • monkeykas.get_kwd(): returns the absolute path to the current KAS_WORK_DIR.
    • monkeykas.get_kbd(): returns the absolute path to the current KAS_BUILD_DIR.
    • monkeykas.move_to_kwd(path): moves the specified path into the KAS_WORK_DIR if necessary.

    Testing directory layouts: Use monkeykas.setenv() to temporarily set KAS_WORK_DIR and KAS_BUILD_DIR to test different directory combinations. Tests relying on these features should be marked with the dirsfromenv marker.

  6. Configure kas directory layout and environment variables

    master

    By default, kas places download and build artifacts in the current directory. You can control the location of these files using the following environment variables:

    • KAS_WORK_DIR: Sets the base location for all work. Repositories managed by kas are stored under their path (or name if path is not set) within this directory.
    • KAS_BUILD_DIR: Sets the build directory name relative to KAS_WORK_DIR. If not set, the build directory is named build.

    Internal data that persists across executions is prefixed with .kas_.

  7. Generate build attestation with kas

    master
    Kas includes support for generating build attestations to provide verifiable information about the build process. For instructions on how to enable and use this feature, refer to the kas-build-attestation(1) manual page.
  8. Handle credentials in kas builds

    master
    To securely inject credentials (such as API keys or authentication tokens) into a build environment, use the mechanisms provided by kas. Detailed usage and configuration options are documented in the kas-credentials(1) manual page.
  9. How credential handling works in KAS

    master

    KAS provides several mechanisms to inject credentials into the build environment, making them available to both KAS and the underlying build tools (like BitBake).

    Key behaviors:

    • Environment Variables: Credentials provided via environment variables are automatically forwarded to the build environment.
    • File-based Credentials: Files like .netrc are only copied into the isolated environment if explicitly requested by setting the corresponding environment variable.
    • Isolation: Because KAS may need to modify configuration files to inject credentials, it often copies these files into the isolated environment first to avoid mutating the host's original files.
  10. Configure project headers in kas configuration files

    master

    Every kas configuration file must contain a header that provides context to the kas tool. Key header elements include:

    • version: An integer representing the configuration format version. kas uses this to ensure compatibility with the file. This version is incremented whenever the format changes.
    • machine: Specifies the target machine, as defined in the BitBake local.conf.
    • distro: Specifies the distribution name, as defined in the BitBake local.conf.
    • bblayers (implied): Configuration files include the repository locations for layers to be added to bblayers.conf.
  11. Configure a kas project

    master
    The primary input for kas is a project configuration file. This file defines the build environment and specifies the layers to be used in the BitBake-based project. For detailed syntax and schema, refer to the kas-project-config(1) manual page.