tree: ff07789a42469dec43d7ca998d3c65b6ff87271a [path history] [tgz]
  1. lib/
  2. scripts/
  3. .gitignore
  4. main.py
  5. OWNERS
  6. README.md
contrib/package_index_cros/README.md

Package index pregenerator

A script to generate build artifacts for Chrome OS packages.

WARNING: this script is only manually tested for very limited purposes and by very limited engineer. The engineer tried to list possible pitfalls here but certainly missed something. Use at your own risk.

Overview

The ultimate goal for the script is to generate input for package_index which makes references available for Chrome on Codesearch page. The script should help to reuse package_index for ChromeOS purposes.

Currently, it is able to generate, fix and merge:

  • compile_commands.json
  • build dir (generated source files, ninja artifacts etc)

Usage

The main entrypoint for this tool is at chromite/contrib/package_index_cros/main. Run that file with --help for details.

Local usage

NOTE: same chroot notation used as in ChromiumOS.

Side effect of the compile_commands.json generator is that it can be used locally with clangd.

  1. Install package_index_cros with steps above.

  2. Install clangd.

  3. Build packages and preserve build targets:

    (inside)
    $ cros-workon-${BOARD} start package1 package2 package3
    $ FEATURES="noclean test" emerge-${BOARD} package1 package2 package3
    
  4. Generate compile_commands.json:

    (outside)
    $ /path/to/package_index_cros/main \
      --with-tests \
      --compile-commands \
      /path/to/clangd/compile/commands/dir/compile_commands.json \
      package1 package2 package3
    

    Where:

    • --with-tests indicates that packages were built with tests.
    • --compile-commands /some/path/compile_commands.json will store tells the script to generate compile commands and store it in given file.
    • packages: which packages you want to include. Compile commands will include these packages plus their dependencies of unlimited depth. You can skip packages, then compile commands will be generated for all available and supported packages (may take a while because of build).
    • Optional --build-dir ${some_dir} will create a dir and merge all packages' build dirs and generated files there. Can be useful when working with proto files but fully optional.

    NOTE: The existing ${some_dir} is removed each script run. Be careful with that axe.

  5. Bosh. Done. Now you can use clangd and click references in your favorite IDE.

NOTE: The script does not clean up after itself. You might want to use cros_sdk clean.

Cover all packages

To have as many packages as possible in compile commands, build all the packages and run the script on top level packages:

(inside)
$ FEATURES="noclean" build_packages \
  --board ${BOARD} \
  --no-usepkg --no-usepkgonly \
  --skip-toolchain-update --skip-chroot-upgrade \
  --withtest --withdev --withfactory

$ FEATURES="noclean" cros_run_unit_tests --board ${BOARD}

(outside)
$ /path/to/package_index_cros/main \
  --with-tests \
  --compile-commands \
  /path/to/clangd/compile/commands/dir/compile_commands.json \
  virtual/target-chromium-os virtual/target-chromium-os-test \
  virtual/target-chromium-os-dev virtual/target-chromium-os-factory \
  virtual/target-chromium-os-factory-shim