Vendor tool: Allow import of more than one part of a repository
People have the need to pick multiple sub-directories out of a single repository with the vendor tool. Currently, that requires either elaborate and fragile sets of exclude_from_upstream, or two .vendor.hjson files. This proposal shows how a single vendor.hjson file (one for each repository) can be used to vendor in multiple subdirectories of an upstream repository.
What we have today:
// hmac.existing_syntax.vendor.hjson
{
name: "hmac",
target_dir: "hmac",
patch_dir: "patches/hmac",
upstream: {
url: "git@upstream:upstream.git",
rev: "master",
only_subdir: "ip/hmac",
},
patch_repo: {
url: "git@fork:fork.git",
rev_base: "master",
rev_patched: "patched",
},
exclude_from_upstream: [
// Refers to ip/hmac/shared/prim_assert.core in git@upstream:upstream.git
'shared/prim_assert.core',
]
}
Proposed syntax:
Complex example, importing two subdirectories:
// lowrisc_central.new_syntax.vendor.hjson
{
name: "lowrisc-central",
target_dir: "lowrisc-central",
upstream: {
url: "git@upstream:upstream.git",
rev: "master",
},
patch_repo: {
url: "git@fork:fork.git",
rev_base: "master",
rev_patched: "patched",
},
import: [
{
// Same functionality as before, moved into a new place.
// Optimization: both source_dir and target_dir default to `.`
source_dir: 'ip/hmac',
target_dir: 'hmac', // Code will end up in lowrisc-central/hmac
patch_dir: 'patches/lowrisc-central/hmac',
exclude: [
// Refers to ip/hmac/shared/prim_assert.core in git@upstream:upstream.git
'shared/prim_assert.core',
]
},
{
// The second directory to import from the same repository.
// This is the new functionality enabled by this syntax.
source_dir: 'ip/usb',
target_dir: 'usb', // Code will end up in lowrisc-central/usb
patch_dir: 'patches/lowrisc-central/usb',
exclude: [
'rtl/some_bogous_file.sv',
]
},
]
}
Simple example, importing a whole directoy.
// simple.new_syntax.vendor.hjson
{
name: "ibex",
target_dir: "ibex",
upstream: {
url: "git@upstream:upstream.git",
rev: "master",
},
patch_repo: {
url: "git@fork:fork.git",
rev_base: "master",
rev_patched: "patched",
},
import: [{
// Optimization: both source_dir and target_dir default to `.`
// If no patching is needed, the whole section can be removed.
patch_dir: 'patches/ibex',
},
]
}
Import process:
- Clone repository.
- For each entry in
import: - Copy
source_dirin repositorytotarget_dir. Exclude all files listed inexclude(relative to thesource_dir`). - Get the
- Apply patches listed in
patch_dir. The base directory for patches istarget_dir. All patches are applied with 1 level of directory stripping (-p1).
Patch update process:
- Clone repository.
- Clone patch repository.
- For each entry in
import: Create a patch for each commit between patch_repo and upstream insource_dir. All paths in patches should be relative to thesource_dir. (Doing this withgit format-patch, as we do today, will require post-processing, as all paths are relative to the repository root.)
@vogelpi please have a look if that works for your USB use case.
This looks perfectly suited for the USB use case @imphil!
@udinator would like to use that to vendor code into Ibex. We should prioritize this.
I think this syntax looks great for the intended purpose!
One clarification question though, is the exclude: section meant to be dependent and/or rely on patch_dir:?
No, exclude and patch_dir don't depend on each other.
This was handled by #2077. There are a couple of follow-ups from that, but they have their own separate tracking issues.