### Example: Generate Layer Variables for Scarthgap Release (Bash) Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/constants.md An example demonstrating how to use the `generate-layer-variables` script for a layer named 'my-project-layer' supporting the 'scarthgap' release, with dependencies on 'core', 'meta-poky', and 'meta-oe'. ```bash generate-layer-variables --layer_filter my-project-layer --local scarthgap /oelint.constants.json core yocto openembedded-layer ``` -------------------------------- ### Install oelint-adv from source Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/README.md This sequence of commands clones the oelint-adv repository from GitHub, navigates into the directory, and installs the package using pip. This method is useful for development or if you need the latest unreleased version. ```shell git clone https://github.com/priv-kweihmann/oel-adv cd oelint-adv pip install . # might require sudo/root permissions ``` -------------------------------- ### CI/CD Integration with Jenkins using oelint-adv (Groovy) Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt This Jenkinsfile demonstrates how to integrate oelint-adv into a Jenkins CI/CD pipeline. It covers installing oelint-adv via pip, running the linter with specific output formats suitable for the warnings-ng plugin, and configuring the plugin to parse the linting results. It also includes an example of using `|| true` for non-blocking checks and a `post` section for handling pipeline failures. ```groovy // Jenkinsfile pipeline { agent any stages { stage('Lint BitBake Recipes') { steps { sh ''' # Install oelint-adv pip3 install oelint-adv # Run linting with custom output format for Jenkins oelint-adv \ --release kirkstone \ --output lint-results.txt \ --messageformat "{path}:{line}:{severity}:{id}:{msg}" \ --suppress oelint.vars.mispell \ meta-layer/**/*.bb meta-layer/**/*.bbappend || true ''' // Parse results with warnings-ng plugin recordIssues( enabledForFailure: true, tools: [groovyScript( parserId: 'oelint-adv', pattern: 'lint-results.txt' )] ) } } } post { failure { echo 'Linting found critical issues' } } } // Exit zero mode for non-blocking checks sh 'oelint-adv --exit-zero --release kirkstone recipe.bb' ``` -------------------------------- ### Install oelint-adv with pip Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/README.md This command installs the oelint-adv package using pip, the standard package installer for Python. It is the recommended method for installing the linter. ```shell pip3 install oelint_adv ``` -------------------------------- ### Include Non-existent File (Example) Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.file.includenotfound.md Demonstrates an include directive pointing to a file that does not exist, triggering a warning. ```plaintext include this/file/does/not/exist.inc ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/tests/README.md Installs development dependencies required for testing oelint-adv using pip. It relies on a requirements-dev.txt file for the list of packages. ```shell pip3 install -r requirements-dev.txt ``` -------------------------------- ### Product Matrix Testing with oelint-adv Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt This section demonstrates advanced usage of oelint-adv for testing recipes against various configuration combinations (product matrix). It covers fast mode for single branch expansion and all mode for full product matrix testing, showing example output with matrix information. ```bash # Fast mode - single branch expansion oelint-adv --mode fast recipe.bb # All mode - full product matrix (distro × machine × branch) oelint-adv --mode all \ meta-layer/recipes-core/recipe.bb \ meta-layer/conf/distro/mydistro.conf \ meta-layer/conf/machine/mymachine.conf # Example output with matrix information: # recipe.bb:10:error:oelint.var.override:Variable overridden [branch:false,mydistro.conf,mymachine.conf] # recipe.bb:15:warning:oelint.vars.specific:Unknown identifier [branch:true,mydistro.conf] # The matrix shows which configuration revealed the issue: # - branch:false = false branch of inline conditionals # - mydistro.conf = when using this distro # - mymachine.conf = when using this machine ``` -------------------------------- ### Shell: Example oelint-adv Output Messages Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/README.md Demonstrates the standard output format of oelint-adv, which includes the file path, line number, severity level (error or warning), rule ID, and a descriptive message. This format helps users quickly identify and understand linting issues. ```shell /disk/meta-some/cppcheck-native/cppcheck.inc:26:error:oelint.task.nomkdir:'mkdir' shall not be used in do_install. Use 'install' [branch:true] /disk/meta-some/cppcheck-native/cppcheck-native_1.87.bb:0:error:oelint.var.mandatoryvar.SECTION:Variable 'SECTION' should be set [branch:true] /disk/meta-some/cppcheck-native/cppcheck.inc:1:warning:oelint.vars.summary80chars:'SUMMARY' should not be longer than 80 characters [branch:true] /disk/meta-some/cppcheck-native/cppcheck.inc:4:warning:oelint.vars.homepageprefix:'HOMEPAGE' should start with 'http://' or 'https://' [branch:true] /disk/meta-some/cppcheck-native/cppcheck.inc:28:warning:oelint.spaces.lineend:Line shall not end with a space [branch:true] /disk/meta-some/cppcheck-native/cppcheck-native_1.87.bb:0:error:oelint.var.mandatoryvar.AUTHOR:Variable 'AUTHOR' should be set [branch:true] /disk/meta-some/cppcheck-native/cppcheck.inc:26:error:oelint.task.nocopy:'cp' shall not be used in do_install. Use 'install' [branch:true] /disk/meta-some/cppcheck-native/cppcheck.inc:12:warning:oelint.var.order.DEPENDS:'DEPENDS' should be placed before 'inherit' [branch:true] ``` -------------------------------- ### Lint BitBake Recipes with GitHub Actions Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt This workflow automates the linting of BitBake recipes using oelint-adv on pull requests. It sets up Python, installs oelint-adv, defines custom rules, lints the recipes, and optionally commits auto-fixes. ```yaml name: Lint BitBake Recipes on: pull_request: paths: - '**.bb' - '**.bbappend' - '**.bbclass' - '**.conf' jobs: oelint: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.11' - name: Install oelint-adv run: | pip install oelint-adv - name: Create rulefile run: | cat > rules.json << 'EOF' { "oelint.var.mandatoryvar": "error", "oelint.task.nomkdir": "error", "oelint.task.nocopy": "error", "oelint.vars.summary80chars": "warning" } EOF - name: Lint recipes run: | oelint-adv \ --release kirkstone \ --rulefile rules.json \ --color \ --messageformat "{path}:{line}:{severity}:{id}:{msg}" \ --hide info \ meta-layer/**/*.bb meta-layer/**/*.bbappend - name: Lint with auto-fix (optional) if: github.event_name == 'pull_request' run: | oelint-adv --fix --nobackup --release kirkstone meta-layer/**/*.bb # Commit fixes if any git config --global user.name 'GitHub Actions' git config --global user.email 'actions@github.com' git add -A git diff --staged --quiet || git commit -m "Auto-fix linting issues" ``` -------------------------------- ### Enable and Manage Caching with oelint-adv (Bash) Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt This bash script showcases how to enable and manage the caching system for oelint-adv. It covers enabling caching with default or custom directories, clearing all caches, and provides an example for using caching within a GitLab CI/CD pipeline to speed up builds by caching linting results. ```bash # Enable caching with default directory (~/.oelint/caches) oelint-adv --cached recipe.bb # Use custom cache directory oelint-adv --cached --cachedir /tmp/build-cache recipe.bb # Clear all caches oelint-adv --clear-caches # Use caching in CI/CD # .gitlab-ci.yml example: lint_recipes: script: - export OELINT_CACHE_DIR=${CI_PROJECT_DIR}/.oelint-cache - oelint-adv --cached --release kirkstone meta-layer/**/*.bb cache: key: oelint-cache paths: - .oelint-cache/ ``` -------------------------------- ### SRC_URI Basic Usage Example Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.srcurichecksum.md Demonstrates the basic addition of a SRC_URI entry. This snippet is for illustrative purposes of how SRC_URI can be updated. ```bitbake SRC_URI += "ftp://foo;name=f3" ``` ```bitbake SRC_URI += "ftp://foo" ``` -------------------------------- ### SRC_URI with MD5 Checksum Example Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.srcurichecksum.md Shows an example of a SRC_URI entry with an MD5 checksum. This is considered a bad practice for certain fetcher types and is often replaced with SHA256. ```bitbake SRC_URI += "ftp://foo" SRC_URI[md5sum] = "d8e8fca2dc0f896fd7cb4cb0031ba249" ``` -------------------------------- ### Multiple SRC_URI Domains Example Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.srcuridomains.md This code snippet demonstrates a common scenario where a recipe fetches source code from multiple git repositories hosted on different domains. This pattern is flagged by the oelint.vars.srcuridomains rule. ```bitbake SRC_URI += "git://abc.group.com/a.git" SRC_URI += "git://def.group.com/b.git" ``` -------------------------------- ### BitBake Function Override Examples Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.func.specific.md Demonstrates two ways to define BitBake function overrides. These are examples of how a function can be appended to or redefined within the BitBake build system. The primary concern is that these overrides might not be universally applied if the conditions (like MACHINE or DISTRO) are not met. ```bitbake do_install:append:fooarch() { abc } ``` ```bitbake do_install:qemuall () { cp -r ${B}/testsuite ${D}${PTEST_PATH}/ cp ${B}/.config ${D}${PTEST_PATH}/ ln -s /bin/busybox ${D}${PTEST_PATH}/busybox } ``` -------------------------------- ### Example of Redundant FILES Entries in Yocto/OE Recipes Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.filessetting.md This example illustrates a common issue in Yocto/OE recipes where the `FILES` variable contains duplicate entries. It shows the incorrect syntax where paths are added multiple times for both the main package and custom packages, which is flagged by the `oelint.vars.filessetting` checker. ```bash FILES:${PN} += "${bindir}" PACKAGE_BEFORE_PN = "${PN}-mydev" FILES:${PN}-mydev += "/some/path" FILES:${PN}-mydev += "/some/path" ``` -------------------------------- ### Example of missing mandatory variable in BitBake recipe Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.var.mandatoryvar.md This snippet shows an example of a BitBake recipe file ('my-recipe_1.0.bb') where a mandatory variable is not defined. The 'oelint-adv' linter will flag this as an error. ```bitbake A = "1" ``` -------------------------------- ### Corrected Multiline Variable Assignment with Common Indent (BitBake) Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.multilineident.md Shows the corrected way to format multiline variable assignments using a common indent that matches the starting quote's indentation, as recommended by the Yocto Project style guide for improved readability. ```bitbake A = "\ a \ b \ " ``` -------------------------------- ### Replace Heredocs with Safer File Creation in Bitbake Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.task.heredocs.md Provides a corrected approach to creating files in Bitbake tasks by avoiding heredocs. This method uses standard output redirection and the `install` command to ensure correct ownership and permissions, improving predictability and security. ```shell do_foo() { echo "kfkdfkd" > ${T}/some.files chown root:root ${T}/some.files install -m 0644 ${T}/some.files ${D}/some.files } ``` -------------------------------- ### Avoid Distro-Specific Variables in Distro Configs Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.distroconf.md This example demonstrates the incorrect practice of setting image and machine-specific variables within a distro configuration file. It is advised to avoid using variables such as IMAGE_INSTALL and MACHINE_FEATURES in such contexts to maintain proper layering and configuration management. ```shell IMAGE_INSTALL += "my-recipe" MACHINE_FEATURES:append = " vfat" ``` -------------------------------- ### Example of Bad layer.conf Variable Setting Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.layerconf.md This snippet demonstrates an incorrect way to modify the IMAGE_INSTALL variable within a layer.conf file. Such modifications should typically be reserved for machine, distro, or image configuration files, not within the layer configuration itself. ```bitbake IMAGE_INSTALL += "my-recipe" ``` -------------------------------- ### Example bbappend with problematic variables Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.append.protvars.md This snippet demonstrates the incorrect usage of protected variables (LICENSE, LIC_FILES_CHKSUM, PR, PV, SRCREV) within a bbappend file. These variables should not be defined in *.bbappend files as they can interfere with build system's detection mechanisms. ```bitbake LICENSE = "MIT" LIC_FILES_CHKSUM = "foo;md5sum=f3e466264f6a083f8febd2b6921ce8c2" PR = "4" PV = "4" SRCREV = "f161ebd29699d93411cec0915c5133c0f3229a28" ``` -------------------------------- ### Variable Override Example - oelint.vars.specific Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.specific.md This snippet demonstrates an example of a variable override that would be flagged by the oelint.vars.specific rule. It shows a common pattern where an append operation is performed on a variable without ensuring it's a known override. ```bitbake A:append:fooarch = " foo" ``` -------------------------------- ### Add Suggested Variables to BitBake Recipe Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.var.suggestedvar.md Demonstrates the addition of recommended variables such as AUTHOR, BUGTRACKER, CVE_PRODUCT, and SECTION to a BitBake recipe file. These variables enhance recipe metadata and aid in functionalities like CVE checking. The example shows a minimal recipe with 'A' and then the improved version with suggested variables. ```bitbake A = "2" ``` ```bitbake AUTHOR = "me " BUGTRACKER = "https://my-homepage/issues" CVE_PRODUCT = "me/lib" SECTION = "graphics" BBCLASSEXTEND = "native" ``` -------------------------------- ### Show Inappropriate Message Examples Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.file.inappropriatemsg.md Demonstrates various ways an 'Upstream-Status: Inappropriate' message can be presented in a patch file. This helps in identifying non-compliant formats. ```text Upstream-Status: Inappropriate [me don't care] ``` ```text Upstream-Status: Inappropriate ``` ```text Upstream-Status: Inappropriate (configuration) ``` -------------------------------- ### Include File from Another Layer (Example) Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.file.includenotfound.md Shows an include directive referencing a file located in a different layer, which can create external dependencies and potential breakage. ```plaintext include a/file/from/another/layer.inc ``` -------------------------------- ### Generate Layer Variables Script (Bash) Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/constants.md This command executes the `generate-layer-variables` script to create a custom constants file for a specific layer. It requires paths to the Poky checkout, build directory, release name, the output constants file, and optionally, layers to exclude. ```bash generate-layer-variables --layer_filter --local /oelint.constants.json ``` -------------------------------- ### Python: Constrain oelint-adv Rule to Specific File Types Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/README.md This Python code demonstrates how to limit an oelint-adv rule to specific file types using the `run_on` parameter during rule initialization. The example shows a rule that applies only to recipe files (.bb) by specifying `Classification.RECIPE`. ```python from oelint_adv.cls_rule import Rule, Classification class FooMagicRule(Rule): def __init__(self): super().__init__(id="foocorp.foo.magic", severity="error", run_on=[Classification.RECIPE] message="Too much foo happening here") ``` -------------------------------- ### Check Variable Definition with Bitbake Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/constants.md This command-line snippet demonstrates how to check if a variable is defined within the OpenEmbedded build system. It's useful for diagnosing why a variable might not be recognized by tools like oelint-adv. It shows two methods: a general check and a check specific to a recipe. ```shell $ bitbake-getvar XYZ # or $ bitbake-getvar -r XYZ ``` -------------------------------- ### Bitbake: Example of Incorrect Package Specific Dependency Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.pkgspecific.md This snippet shows an incorrect way to specify dependencies in a Bitbake file. Omitting the package override means the setting might be ignored by the build system, leading to potential issues. ```bitbake RDEPENDS += "foo" ``` -------------------------------- ### Alternative Corrected Multiline Variable Assignment (BitBake) Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.multilineident.md Presents an alternative valid method for formatting multiline variable assignments, where indentation aligns with the first character after the opening quote, also adhering to Yocto Project style guidelines. ```bitbake A = "a \ b \ " ``` -------------------------------- ### Create Library Arguments for oelint-adv Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Demonstrates how to create arguments for the oelint-adv library using `create_lib_arguments`. Covers basic file specification and advanced configuration with options like suppressions, additional rules, rule files, and output formatting. ```python from oelint_adv.core import create_lib_arguments # Basic usage with minimal configuration args = create_lib_arguments( files=['recipe.bb', 'recipe.bbappend'], ) # Advanced configuration with all options args = create_lib_arguments( files=['meta-layer/recipes-core/**/*.bb'], suppressions=['oelint.vars.mispell', 'oelint.newline.eof'], fix=False, nobackup=False, additional_rules=['jetm'], # Load non-default rulesets rulefile='/path/to/rules.json', jobs=4, color=False, quiet=True, hide=['info'], # Hide info-level messages relpaths=True, messageformat='{severity}:{id}:{msg}', constantmods=['+/path/to/additional_constants.json'], release='kirkstone', mode='fast', # or 'all' for exhaustive testing cached=True, cachedir='/tmp/oelint-cache', extra_layer=['meta-custom', 'meta-vendor'] ) # Returns: argparse.Namespace with all configuration print(f"Jobs: {args.jobs}") print(f"Release: {args.release}") print(f"Files: {args.files}") ``` -------------------------------- ### Run oelint-adv Linter with Python Library Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Shows how to execute the oelint-adv linter using the `run` function from the `oelint_adv.core` module. It includes configuring arguments, running the linting process, processing the returned issues, and handling potential exceptions. The function can optionally persist changes. ```python from oelint_adv.core import create_lib_arguments, run import sys # Configure and run linter args = create_lib_arguments( files=['recipe.bb'], release='kirkstone', color=False, quiet=True ) try: issues, fixed_files = run(args, persistent=True) # Process results # issues is List[Tuple[Tuple[str, int], str]] # Each item: ((file_path, line_number), formatted_message) for (path, line), message in issues: print(f"{path}:{line} - {message}") # fixed_files is Dict[str, str] when persistent=False # Keys are file paths, values are fixed file contents # Exit with error if issues found sys.exit(1 if issues else 0) except Exception as e: print(f"Linting failed: {e}", file=sys.stderr) sys.exit(70) # Example output parsing # issues = [ # (('/path/recipe.bb', 26), 'error:oelint.task.nomkdir:\'mkdir\' shall not be used in do_install'), # (('/path/recipe.bb', 1), 'warning:oelint.vars.summary80chars:SUMMARY should not be longer than 80 characters'), # ] ``` -------------------------------- ### CLI Linting BitBake Recipes with oelint-adv Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Perform command-line linting of BitBake recipe files (.bb, .bbappend, .bbclass) and configuration files (.conf). Supports specifying release versions, enabling color output, suppressing rules, and parallel processing using multiple jobs. ```bash # Lint a single recipe file oelint-adv /path/to/recipe.bb # Lint multiple files with release-specific rules oelint-adv --release kirkstone --color /path/to/*.bb /path/to/*.bbappend # Suppress specific rules oelint-adv --suppress oelint.vars.mispell --suppress oelint.newline.eof recipe.bb # Use all cores for parallel processing oelint-adv --jobs 8 /path/to/meta-layer/**/*.bb # Example output: # /disk/meta-some/cppcheck.inc:26:error:oelint.task.nomkdir:'mkdir' shall not be used in do_install. Use 'install' [branch:true] # /disk/meta-some/cppcheck-native_1.87.bb:0:error:oelint.var.mandatoryvar.SECTION:Variable 'SECTION' should be set [branch:true] # /disk/meta-some/cppcheck.inc:4:warning:oelint.vars.homepageprefix:'HOMEPAGE' should start with 'http://' or 'https://' [branch:true] ``` -------------------------------- ### Incorrect Multiline Variable Assignment (BitBake) Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.multilineident.md Demonstrates an incorrect multiline variable assignment where the continuation lines are not properly indented according to the Yocto Project style guide. This can lead to readability issues. ```bitbake A = "\ a \ b \ " ``` -------------------------------- ### oelint-adv command-line usage Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/README.md This displays the help message for the oelint-adv command-line tool, outlining all available options and arguments. It shows how to specify files, suppress rules, control output, enable auto-fixing, and configure various aspects of the linting process. ```shell usage: oelint-adv [-h] [--suppress SUPPRESS] [--output OUTPUT] [--fix] [--nobackup] [--addrules ADDRULES [ADDRULES ...]] [--customrules CUSTOMRULES [CUSTOMRULES ...]] [--rulefile RULEFILE] [--jobs JOBS] [--color] [--quiet] [--hide {info,warning,error}] [--mode {fast,all}] [--relpaths] [--messageformat MESSAGEFORMAT] [--constantmods CONSTANTMODS [CONSTANTMODS ...]] [--print-rulefile] [--exit-zero] [--release {...}] [--cached] [--cachedir CACHEDIR] [--clear-caches] [--extra-layer [EXTRA_LAYER ...]] [--version] [files ...] Advanced OELint - Check bitbake recipes against OECore styleguide positional arguments: files File to parse options: -h, --help show this help message and exit --suppress SUPPRESS Rules to suppress --output OUTPUT Where to flush the findings (default: stderr) --fix Automatically try to fix the issues --nobackup Don't create backup file when auto fixing --addrules ADDRULES [ADDRULES ...] Additional non-default rulessets to add --customrules CUSTOMRULES [CUSTOMRULES ...] Additional directories to parse for rulessets --rulefile RULEFILE Rulefile --jobs JOBS Number of jobs to run (default all cores) --color Add color to the output based on the severity --quiet Print findings only --hide {info,warning,error} Hide mesesages of specified severity --mode {fast,all} Level of testing (default: fast) --relpaths Show relative paths instead of absolute paths in results --messageformat MESSAGEFORMAT Format of message output --constantmods CONSTANTMODS [CONSTANTMODS ...] Modifications to the constant db. prefix with: + - to add to DB, - - to remove from DB, None - to override DB --print-rulefile Print loaded rules as a rulefile and exit --exit-zero Always return a 0 (non-error) status code, even if lint errors are found --release {...} Run against a specific Yocto release --cached Use caches (default: off) --cachedir CACHEDIR Cache directory (default $HOME/.oelint/caches) --clear-caches Clear cache directory and exit --extra-layer [EXTRA_LAYER ...] Layer names of 3rd party layers to use --version show program's version number and exit ``` -------------------------------- ### Example of Mutually Exclusive SRC_URI and SRCREV Information Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.srcurimutualex.md This example demonstrates the problematic pattern where both a Git revision (SRCREV) and a checksum (SRC_URI[sha256sum]) are specified for a Git source URI. This rule flags such occurrences as they represent mutually exclusive information for validating the downloaded artifact. ```bitbake SRC_URI += "gitsm://github.com/CLIUtils/CLI11;branch=main;protocol=https" SRCREV = "1233454566789" SRC_URI[sha256sum] = "1233454566789" ``` -------------------------------- ### Python Library API - run() Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Executes the linting process with the provided arguments and returns any found issues and information about fixed files. ```APIDOC ## run() ### Description Execute linting with configured arguments and retrieve results. This function processes the files specified in the arguments and returns a list of linting issues found. ### Method Python Function ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from oelint_adv.core import create_lib_arguments, run import sys # Configure and run linter args = create_lib_arguments( files=['recipe.bb'], release='kirkstone', color=False, quiet=True ) try: issues, fixed_files = run(args, persistent=True) # Process results # issues is List[Tuple[Tuple[str, int], str]] # Each item: ((file_path, line_number), formatted_message) for (path, line), message in issues: print(f"{path}:{line} - {message}") # fixed_files is Dict[str, str] when persistent=False # Keys are file paths, values are fixed file contents # Exit with error if issues found sys.exit(1 if issues else 0) except Exception as e: print(f"Linting failed: {e}", file=sys.stderr) sys.exit(70) # Example output parsing # issues = [ # (('/path/recipe.bb', 26), 'error:oelint.task.nomkdir:\'mkdir\' shall not be used in do_install'), # (('/path/recipe.bb', 1), 'warning:oelint.vars.summary80chars:SUMMARY should not be longer than 80 characters'), # ] ``` ### Response #### Success Response (200) - **issues** (List[Tuple[Tuple[str, int], str]]) - A list of tuples, where each tuple contains the file path, line number, and the formatted linting message. - **fixed_files** (Dict[str, str]) - A dictionary mapping file paths to their fixed content when `persistent` is `False`. #### Response Example ```json { "issues": [ [["/path/recipe.bb", 26], "error:oelint.task.nomkdir:\'mkdir\' shall not be used in do_install"], [["/path/recipe.bb", 1], "warning:oelint.vars.summary80chars:SUMMARY should not be longer than 80 characters"] ], "fixed_files": { "/path/recipe.bb": "# Fixed content of recipe.bb" } } ``` ``` -------------------------------- ### VS Code Editor Integration for oelint-adv Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt This JSON configuration sets up the `oelint-vscode` extension for VS Code. It specifies the path to the linter, release version, rule file, extra arguments, and enables linting on save. ```json // .vscode/settings.json { "oelint.linter.path": "oelint-adv", "oelint.linter.release": "kirkstone", "oelint.linter.ruleFile": "${workspaceFolder}/rules.json", "oelint.linter.extraArgs": [ "--suppress", "oelint.vars.mispell", "--color" ], "oelint.linter.runOnSave": true, "oelint.linter.runOnType": false } ``` -------------------------------- ### Example of Inactive-Upstream Status Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.file.inactiveupstreamdetails.md Demonstrates the incorrect and correct ways to format the 'Inactive-Upstream' status in patch files, including optional timestamp information. ```plaintext Upstream-Status: Inactive-Upstream ``` ```plaintext Upstream-Status: Inactive-Upstream [1234] ``` ```plaintext Inactive-Upstream [lastcommit: 11.11.2011] ``` ```plaintext Inactive-Upstream [lastrelease: 11.11.2011] ``` ```plaintext Inactive-Upstream [lastcommit: 11.11.2011, lastrelease: 11.11.2011] ``` -------------------------------- ### CLI Configuration File Support for oelint-adv Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Load default linting settings from a configuration file (e.g., .oelint.cfg). Supports skipping configuration file loading or specifying a custom configuration file path via environment variables. ```bash # Configuration file: .oelint.cfg cat > .oelint.cfg << 'EOF' [oelint] hide = warning suppress = oelint.vars.mispell oelint.newline.eof messageformat = {severity}:{id}:{msg} release = kirkstone color = True cached = True jobs = 4 EOF # Run with auto-loaded config oelint-adv recipe.bb # Skip config file loading export OELINT_SKIP_CONFIG=1 oelint-adv recipe.bb # Use custom config file location export OELINT_CONFIG=/path/to/custom/.oelint.cfg oelint-adv recipe.bb ``` -------------------------------- ### Python Library API - create_lib_arguments() Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Creates a namespace object with arguments for the oelint-adv library. Supports basic and advanced configurations for file paths, suppression rules, fixing behavior, and more. ```APIDOC ## create_lib_arguments() ### Description Creates a namespace object with arguments for the oelint-adv library. Supports basic and advanced configurations for file paths, suppression rules, fixing behavior, and more. ### Method Python Function ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from oelint_adv.core import create_lib_arguments # Basic usage with minimal configuration args = create_lib_arguments( files=['recipe.bb', 'recipe.bbappend'] ) # Advanced configuration with all options args = create_lib_arguments( files=['meta-layer/recipes-core/**/*.bb'], suppressions=['oelint.vars.mispell', 'oelint.newline.eof'], fix=False, nobackup=False, additional_rules=['jetm'], # Load non-default rulesets rulefile='/path/to/rules.json', jobs=4, color=False, quiet=True, hide=['info'], # Hide info-level messages relpaths=True, messageformat='{severity}:{id}:{msg}', constantmods=['+/path/to/additional_constants.json'], release='kirkstone', mode='fast', # or 'all' for exhaustive testing cached=True, cachedir='/tmp/oelint-cache', extra_layer=['meta-custom', 'meta-vendor'] ) print(f"Jobs: {args.jobs}") print(f"Release: {args.release}") print(f"Files: {args.files}") ``` ### Response #### Success Response (200) - **argparse.Namespace** - An object containing all configuration options passed to the function. #### Response Example ```json { "jobs": 4, "release": "kirkstone", "files": [ "meta-layer/recipes-core/**/*.bb" ] } ``` ``` -------------------------------- ### Use oelint-adv as a Python Library Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/README.md Demonstrates how to use the oelint_adv library within a Python application to lint files. It covers creating arguments and running the linter, with results returned as a list of findings. The caller is responsible for exception handling. ```python from oelint_adv.core import create_lib_arguments, run args = create_lib_arguments(['file to check', 'another file to check']) # check the docstring of create_lib_arguments for more options results = run(args) # the results will be a List[Tuple[Tuple[str, int], str]] # each item is # [0] - 'path to the finding', 'line of the finding' # [1] - 'message' ``` -------------------------------- ### Fix Inappropriate Message with Reason Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.file.inappropriatemsg.md Provides an example of how to correctly format the 'Upstream-Status: Inappropriate' message by including a specific reason in square brackets. This is the recommended way to fix the violation. ```text Inappropriate [licensing] ``` -------------------------------- ### Programmatic Cache Control in oelint-adv (Python) Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt This Python code demonstrates how to interact with the oelint-adv caching system programmatically. It shows how to create arguments for the linting library, including enabling caching and specifying a cache directory, and how to programmatically clear caches. The comments explain the factors used for cache fingerprinting. ```python # Programmatic cache control from oelint_adv.caches import Caches from oelint_adv.core import create_lib_arguments args = create_lib_arguments( files=['recipe.bb'], cached=True, cachedir='/var/cache/oelint' ) # Clear caches programmatically args.state._caches.ClearCaches() # Caches automatically fingerprint based on: # - File contents (via oelint-parser fingerprint) # - Loaded rule IDs # - Constant modifications # - Stash parameters ``` -------------------------------- ### Load Rules Dynamically with oelint-adv Python Library Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Illustrates how to dynamically load linting rules using the `load_rules` function. This includes loading default rules, adding non-default rule sets (like 'jetm'), specifying custom rule directories, filtering rules by release, and inspecting loaded rule properties. ```python from oelint_adv.cls_rule import load_rules from oelint_adv.core import arguments_post, parse_arguments # Parse command-line arguments args = arguments_post(parse_arguments()) # Load default rule base rules = load_rules(args) # Load with additional non-default rulesets rules = load_rules( args, add_rules=['jetm'], # Enable jetm ruleset add_dirs=[] ) # Load with custom rule directories rules = load_rules( args, add_rules=[], add_dirs=['/path/to/custom-rules', '/path/to/company-rules'] ) # Inspect loaded rules for rule in rules: print(f"Rule ID: {rule.ID}") print(f"Severity: {rule.Severity}") print(f"Message: {rule.Msg}") print(f"Sub-IDs: {rule.get_ids()}") print(f"Applicable to: {rule._run_on}") print("---") # Filter rules by release matching_rules = [r for r in rules if r.check_release_range(['kirkstone', 'langdale'])] # Example output: # Rule ID: oelint.vars.summary80chars # Severity: warning # Message: 'SUMMARY' should not be longer than 80 characters # Sub-IDs: ['oelint.vars.summary80chars'] # Applicable to: [, , ...] ``` -------------------------------- ### Create CLI Arguments for Testing Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/tests/README.md Utilizes the _create_args method to generate CLI arguments for oelint-adv tests. It accepts a dictionary of filenames and content and optionally custom arguments. ```python self._create_args(input_) ``` ```python self._create_args(input_, ['my', 'extra', 'arguments']) ``` -------------------------------- ### Configure oelint-adv to exclude classes from mandatory variable checks Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.var.mandatoryvar.md This example shows how to use the '--constantmods' option with 'oelint-adv' to specify a JSON configuration file. This allows excluding specific classes from triggering mandatory variable checks, useful when classes define these variables. ```console oelint-adv --constantmods=+.my-custom-src-uri-classes.json ... ``` -------------------------------- ### CLI Rulefile Configuration for oelint-adv Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Define which rules to enforce and their severity levels using a JSON rulefile. Supports enforcing specific rules, setting severity (error, warning, info), and using rulefiles in CI environments with strict output filtering. ```bash # Create a rulefile to enforce specific rules only cat > rules.json << 'EOF' { "oelint.file.includenotfound": "", "oelint.file.requirenotfound": "warning", "oelint.var.mandatoryvar": "error", "oelint.var.mandatoryvar.AUTHOR": "error", "oelint.var.mandatoryvar.SECTION": "warning", "oelint.vars.summary80chars": "info", "oelint.task.nomkdir": "error", "oelint.task.nocopy": "error" } EOF # Use the rulefile oelint-adv --rulefile rules.json /path/to/recipe.bb # Generate rulefile from currently loaded rules oelint-adv --print-rulefile > current-rules.json # Use rulefile in CI with strict mode oelint-adv --rulefile rules.json --hide info --hide warning /path/to/recipe.bb # Exit code 1 if any errors found, 0 otherwise ``` -------------------------------- ### CLI Automatic Fixing of BitBake Recipe Issues with oelint-adv Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Automatically fix issues in BitBake recipes. Supports creating backup files for restored changes, disabling backup creation, and customizing the message format for reported fixes. ```bash # Fix all auto-fixable issues with backup oelint-adv --fix recipe.bb # Fix without creating .bak files oelint-adv --fix --nobackup recipe.bb # Fix with custom message format oelint-adv --fix --messageformat "{path}:{line} [{severity}] {msg}" recipe.bb # Example output: # /path/to/recipe.bb:debug:Applied automatic fixes # # Fixed issues include: # - Trailing whitespace removal # - EOF newline addition # - Indentation corrections # - Variable quote formatting ``` -------------------------------- ### Python Library API for oelint-adv Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Programmatically create runtime arguments for library usage with the `oelint-adv` Python API. This allows integrating linting functionalities into other Python applications. ```python from oelint_adv.core import create_lib_arguments, run ``` -------------------------------- ### Example of Out-of-Context Variable Assignment in Bitbake Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.vars.outofcontext.md This snippet demonstrates a common scenario where a variable intended for a specific context (like MACHINEOVERRIDES, often used in recipes) is assigned a value in a place where it might not be interpreted as intended, potentially affecting multiple recipes globally. ```bitbake MACHINEOVERRIDES .= "foo:" ``` -------------------------------- ### Python Library API - load_rules() Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt Dynamically loads linting rules, allowing for the inclusion of built-in rules, additional non-default rule sets, and custom rule directories. ```APIDOC ## load_rules() ### Description Dynamically load linting rules from built-in and custom directories. This function allows for flexible rule management, including enabling specific rule sets and specifying custom rule locations. ### Method Python Function ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from oelint_adv.cls_rule import load_rules from oelint_adv.core import arguments_post, parse_arguments # Parse command-line arguments args = arguments_post(parse_arguments()) # Load default rule base rules = load_rules(args) # Load with additional non-default rulesets rules = load_rules( args, add_rules=['jetm'], # Enable jetm ruleset add_dirs=[] ) # Load with custom rule directories rules = load_rules( args, add_rules=[], add_dirs=['/path/to/custom-rules', '/path/to/company-rules'] ) # Inspect loaded rules for rule in rules: print(f"Rule ID: {rule.ID}") print(f"Severity: {rule.Severity}") print(f"Message: {rule.Msg}") print(f"Sub-IDs: {rule.get_ids()}") print(f"Applicable to: {rule._run_on}") print("---") # Filter rules by release matching_rules = [r for r in rules if r.check_release_range(['kirkstone', 'langdale'])] # Example output: # Rule ID: oelint.vars.summary80chars # Severity: warning # Message: 'SUMMARY' should not be longer than 80 characters # Sub-IDs: ['oelint.vars.summary80chars'] # Applicable to: [, , ...] ``` ### Response #### Success Response (200) - **rules** (List[oelint_adv.cls_rule.Rule]) - A list of loaded Rule objects. #### Response Example ```json [ { "ID": "oelint.vars.summary80chars", "Severity": "warning", "Msg": "'SUMMARY' should not be longer than 80 characters", "_run_on": [ 0, 2 ] } ] ``` ``` -------------------------------- ### Create Custom OELint Rule (Python) Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/README.md This Python code demonstrates how to create a custom rule for oelint-adv. It shows how to define a rule with an ID, severity, and message, and how to implement the `check` method to find specific patterns in the metadata. An optional `fix` method for automatic fixing is also included. This requires the `oelint_adv.cls_rule` module. ```python from oelint_adv.cls_rule import Rule class FooMagicRule(Rule): def __init__(self): super().__init__(id="foocorp.foo.magic", severity="error", message="Too much foo happening here") def check(self, _file, stash): res = [] items = stash.GetItemsFor(filename=_file) for i in items: if "Foo" in i.Raw: res += self.finding(i.Origin, i.InFileLine) return res # To provide automatic fixing capability # add the following optional function def fix(self, _file, stash): res = [] items = stash.GetItemsFor(filename=_file) for i in items: if 'Foo' in i.Raw: # you have to replace the content of `RealRaw` and `Raw` # with the fixed content # `Raw` is the raw block with expanded inlines blocks # `RealRaw` is the raw block without any modifications # this is what will be actually written to the file i.RealRaw = i.RealRaw.replace('Foo', 'Bar') i.Raw = i.Raw.replace('Foo', 'Bar') # Return the file name to signalize that fixes have been # applied res.append(_file) return res ``` -------------------------------- ### NeoVim Editor Integration for oelint-adv (nvim-lint) Source: https://context7.com/priv-kweihmann/oelint-adv/llms.txt This Lua configuration integrates oelint-adv with NeoVim using the nvim-lint plugin. It registers oelint-adv as a linter for BitBake files and sets up an autocommand to trigger linting on save. ```lua -- NeoVim with nvim-lint require('lint').linters_by_ft = { bitbake = {'oelint-adv'} } -- Auto-lint on save vim.api.nvim_create_autocmd({"BufWritePost"}, { pattern = {"*.bb", "*.bbappend", "*.bbclass"}, callback = function() require('lint').try_lint() end, }) ``` -------------------------------- ### Configure oelint-adv to Exclude Variables by Class Source: https://github.com/priv-kweihmann/oelint-adv/blob/master/docs/wiki/oelint.var.suggestedvar.md Shows how to configure the oelint-adv linter using constants to exclude suggested variables when a specific class is inherited. This is useful when a custom class already defines these variables. The example demonstrates excluding BUGTRACKER and CVE_PRODUCT due to the 'foo' class. ```json { "oelint-suggestedvar": { "BUGTRACKER-exclude-classes": [ "foo" ], "CVE_PRODUCT-exclude-classes": [ "foo" ] } } ```