summaryrefslogtreecommitdiff
path: root/docs/ide-support.md
blob: fd8422eee7298351e7bed713ebaa8e13633a53c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# IDE Support

This document explains how to configure IDEs to better support the EC codebase.

[TOC]

## Odd File Types

EC uses a few odd file types/names. Some are included from other header files
and used to generate data structures, thus it is important for your IDE to index
them.

Patterns                                              | Vague Type
----------------------------------------------------- | ----------
`README.*`                                            | Text
`Makefile.rules`, `Makefile.toolchain`                | Makefile
`gpio.wrap`                                           | C Header
`gpio.inc`                                            | C Header
`*.tasklist`, `*.irqlist`, `*.mocklist`, `*.testlist` | C Header

## IDE Configuration Primitives

EC firmware presents some unique challenges because it is designed to support a
number of different MCUs and board configurations, each of which is split across
separate RO (Read-Only) and RW (Read-Write) applications. For this reason, you
must specify the specific board/image pair when requesting defines and includes.

Command                                      | Description
-------------------------------------------- | ------------------------------
`make print-defines BOARD=$BOARD BLD=RW/RO`  | List compiler injected defines
`make print-includes BOARD=$BOARD BLD=RW/RO` | List compiler include paths

## VSCode

You can use the `ide-config.sh` tool to generate a VSCode configuration that
includes selectable sub-configurations for every board/image pair.

1.  From the root `ec` directory, do the following:

    ```bash
    (outside) $ mkdir -p .vscode
    ```

    ```bash
    (chroot) $ ./util/ide-config.sh vscode all:RW all:RO | tee .vscode/c_cpp_properties.json
    ```

2.  Open VSCode and navigate to some C source file.

3.  Run `C/C++ Reset IntelliSense Database` from the `Ctrl-Shift-P` menu

4.  Select the config in the bottom right, next to the `Select Language Mode`.
    You will only see this option when a C/C++ file is open. Additionally, you
    can select a configuration by pressing `Ctrl-Shift-P` and selecting the
    `C/C++ Select a Configuration...` option.

5.  Add the EC specific file associations and style settings. Do the following
    to copy the default settings to `.vscode/settings.json`:

    ```bash
    (outside) $ cp .vscode/settings.json.default .vscode/settings.json
    ```

## VSCode CrOS IDE

CrOS IDE is a VSCode extension to enable code completion and navigation for
ChromeOS source files.

Support for `platform/ec` is not available out of the box (yet), but can be
manually enabled following these steps.

### Prerequisites

1.  Install CrOS IDE following the [quickstart guide]
1.  Install `bear`, a utility to generate the compilation database

    ```
    (chroot) $ sudo emerge bear
    ```

[quickstart guide]: https://chromium.googlesource.com/chromiumos/chromite/+/main/ide_tooling/docs/quickstart.md

### Configure EC Board

1.  Build the image and create new compile_commands.json using `bear`

    ```
    (chroot) $ cd ~/chromiumos/src/platform/ec
    export BOARD=bloonchipper
    make clean BOARD=${BOARD}
    bear make -j BOARD=${BOARD}
    mv compile_commands.json compile_commands_inside_chroot.json
    ```

1.  Generate the new compile_commands.json (use the absolute path outside chroot
    as first argument)

    ```bash
    (chroot) $ cd ~/chromiumos/chromite/ide_tooling/scripts
    python compdb_no_chroot.py ${EXTERNAL_TRUNK_PATH} \
      < ~/chromiumos/src/platform/ec/compile_commands_inside_chroot.json \
      > ~/chromiumos/src/platform/ec/compile_commands.json
    ```
    The command will overwrite the file `compile_commands.json`, if it already
    exists.