blob: a17d2b57ba7a59ec610140af9bdd61b1900e6a81 [file] [log] [blame] [view]
Garret Kelly9eebde02019-10-22 15:36:49 -04001---
Miguel Osorioba17f112019-11-15 12:30:14 -08002title: "util/vendor.py: Vendor-in Components"
Garret Kelly9eebde02019-10-22 15:36:49 -04003---
lowRISC Contributors802543a2019-08-31 12:12:56 +01004
Miguel Osorioba17f112019-11-15 12:30:14 -08005Not all code contained in this repository is actually developed within this repository.
6Code which we include from external sources is placed in `vendor` sub-directories (e.g. `hw/vendor`) and copied over from upstream sources.
7The process of copying the upstream sources is called vendoring, and it is automated by the `util/vendor` tool.
lowRISC Contributors802543a2019-08-31 12:12:56 +01008
Miguel Osorioba17f112019-11-15 12:30:14 -08009The `util/vendor` tool can go beyond simply copying in source files: it can patch them, it can export patches from commits in a Git repository, and it can commit the resulting changes with a meaningful commit message.
lowRISC Contributors802543a2019-08-31 12:12:56 +010010
11## Tool usage overview
12
13```text
Miguel Osorioba17f112019-11-15 12:30:14 -080014usage: vendor [-h] [--refresh-patches] [--commit] [--verbose] file
lowRISC Contributors802543a2019-08-31 12:12:56 +010015
Miguel Osorioba17f112019-11-15 12:30:14 -080016vendor, copy source code from upstream into this repository
lowRISC Contributors802543a2019-08-31 12:12:56 +010017
18positional arguments:
19 file vendoring description file (*.vendor.hjson)
20
21optional arguments:
22 -h, --help show this help message and exit
Sam Elliotta24497b2020-04-23 15:06:46 +010023 --update, -U Update locked version of repository with upstream changes
lowRISC Contributors802543a2019-08-31 12:12:56 +010024 --refresh-patches Refresh the patches from the patch repository
25 --commit, -c Commit the changes
26 --verbose, -v Verbose
27```
28
29## The vendor description file
30
Miguel Osorioba17f112019-11-15 12:30:14 -080031For each vendored-in component a description file must be created, which serves as input to the `util/vendor` tool.
32The vendor description file is stored in `vendor/<vendor>_<name>.vendor.hjson`.
lowRISC Contributors802543a2019-08-31 12:12:56 +010033By convention all imported code is named `<vendor>_<name>`, with `<vendor>` typically being the GitHub user or organization name, and `<name>` the project name.
34It is recommended to use only lower-case characters.
35
36A full commented example of a vendor description file is given below.
37All relative paths are relative to the description file.
38Optional parts can be removed if they are not used.
39
40```
41// Copyright lowRISC contributors.
42// Licensed under the Apache License, Version 2.0, see LICENSE for details.
43// SPDX-License-Identifier: Apache-2.0
44{
45 // Name of the vendored-in project
46 name: "pulp_riscv_dbg",
47
48 // Target directory: typically equal to the name
49 // All imported code is copied into this directory
50 target_dir: "pulp_riscv_dbg",
51
52 // Git upstream source code repository
53 upstream: {
54 // Upstream Git repository URL. HTTPS URLs are preferred.
55 url: "https://github.com/pulp-platform/riscv-dbg",
56 // Upstream revision or branch. Can be a commit hash or a branch name.
57 rev: "pulpissimo_integration",
58 },
59
Rupert Swarbrick249b4c32020-05-19 17:11:31 +010060 // Optional: Pick specific files or subdirectories from upstream and
61 // specify where to put them.
62 mapping: [
63 {from: 'src', to: 'the-source'},
64 {from: 'doc', to: 'some/documentation', patch_dir: 'doc_patches'}
65 ]
66
lowRISC Contributors802543a2019-08-31 12:12:56 +010067 // Optional: Apply patches from the following directory to the upstream
68 // sources
69 patch_dir: "patches/pulp_riscv_dbg",
70
71 // Optional: Update patches in |patch_dir| from a Git repository
Miguel Osorioba17f112019-11-15 12:30:14 -080072 // If util/vendor is run with --refresh-patches, all commits in the repository
lowRISC Contributors802543a2019-08-31 12:12:56 +010073 // at |url| between |rev_base| and |rev_patched| are exported into the
74 // |patch_dir|, replacing all existing patches.
75 patch_repo: {
76 url: "git@github.com:lowRISC/riscv-dbg.git",
77 rev_base: "pulpissimo_integration",
78 rev_patched: "ot",
79 },
80
81 // Optional: Exclude files or directories from the upstream sources
Rupert Swarbrick249b4c32020-05-19 17:11:31 +010082 // The standard glob wildcards (*, ?, etc.) are supported.
lowRISC Contributors802543a2019-08-31 12:12:56 +010083 exclude_from_upstream: [
84 "src/dm_top.sv",
85 "src_files.yml",
86 ]
87}
88```
89
Rupert Swarbrick249b4c32020-05-19 17:11:31 +010090If only the contents of a single subdirectory (including its children) of an upstream repository are to be copied in, the optional `only_subdir` key of can be used in the `upstream` section to specify the subdirectory to be copied.
Tim Shepard24b72032019-10-23 16:40:04 -040091The contents of that subdirectory will populate the `target_dir` directly (without any intervening directory levels).
92
Rupert Swarbrick249b4c32020-05-19 17:11:31 +010093For a more complicated set of copying rules ("get directories `A/B` and `A/C` but not anything else in `A`"), use a `mapping` list.
94Each element of the list should be a dictionary with keys `from` and `to`.
95The value of `from` should be a path relative to the source directory (either the top of the cloned directory, or the `only_subdir` subdirectory, if set).
96The value of `to` should be a path relative to `target_dir`.
97
98If `patch_dir` is supplied, it names a directory containing patches to be applied to the vendored code.
99If there is no `mapping` list, this directory's patches are applied in lexicographical order relative to `target_dir`.
100If there is a mapping list, each element of the list may contain a `patch_dir` key.
101The value at that key is a directory, relative to the global `patch_dir` and patches in that directory are applied in lexicographical order relative to the target directory of the mapping, `to`.
102
Tim Shepard24b72032019-10-23 16:40:04 -0400103In the example vendor description file below, the mpsse directory is populated from the chromiumos platform2 repository, extracting just the few files in the trunks/ftdi subdirectory.
104
105```
106// Copyright lowRISC contributors.
107// Licensed under the Apache License, Version 2.0, see LICENSE for details.
108// SPDX-License-Identifier: Apache-2.0
109{
110 name: "mpsse",
111 target_dir: "mpsse",
112
113 upstream: {
114 url: "https://chromium.googlesource.com/chromiumos/platform2/",
115 rev: "master",
116 only_subdir: "trunks/ftdi",
117 },
118}
119```
120
Sam Elliotta24497b2020-04-23 15:06:46 +0100121## Updating and The Vendor Lock File
122
123In order to document which version of a repositoy has been cloned and committed to the repository with the vendor tool, a vendor lock file is stored in `vendor/<vendor>_<name>.lock.hjson`.
124This contains only the upstream information, including the URL and the exact git revision that was cloned.
125
126Beyond just documentation, this enables users to re-clone the previously-cloned upstream repository -- including re-applying patches, choosing subdirectories, and excluding additional files -- without having to integrate any upstream changes.
127Indeed the default behaviour of the vendor tool is to use the upstream information from `<vendor>_<name>.lock.hjson` if this file exists.
128
129Once the lock file exists, the vendor tool will only use the upstream information in `<vendor>_<name>.vendor.json` if the `--update` command-line option is used.
130
lowRISC Contributors802543a2019-08-31 12:12:56 +0100131## Examples
132
Sam Elliotta24497b2020-04-23 15:06:46 +0100133### Re-clone code and apply new file exclusions or patches
134
lowRISC Contributors802543a2019-08-31 12:12:56 +0100135```command
136$ cd $REPO_TOP
Sam Elliotta24497b2020-04-23 15:06:46 +0100137$ ./util/vendor.py hw/vendor/google_riscv-dv.vendor.hjson -v
138```
139
140### Update code and commit the new code
141
142This will generate a commit message based off the git shortlog between the
143previously cloned revision and the newly cloned revision of the repository.
144
145```command
146$ cd $REPO_TOP
147$ ./util/vendor.py hw/vendor/google_riscv-dv.vendor.hjson -v --update --commit
lowRISC Contributors802543a2019-08-31 12:12:56 +0100148```