opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

Vendor tool: Allow import of more than one part of a repository

Open imphil opened this issue 6 years ago • 6 comments

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:

  1. Clone repository.
  2. For each entry in import:
  3. Copy source_dir in repositorytotarget_dir. Exclude all files listed in exclude(relative to thesource_dir`).
  4. Get the
  5. Apply patches listed in patch_dir. The base directory for patches is target_dir. All patches are applied with 1 level of directory stripping (-p1).

Patch update process:

  1. Clone repository.
  2. Clone patch repository.
  3. For each entry in import: Create a patch for each commit between patch_repo and upstream in source_dir. All paths in patches should be relative to the source_dir. (Doing this with git format-patch, as we do today, will require post-processing, as all paths are relative to the repository root.)

imphil avatar Feb 12 '20 15:02 imphil

@vogelpi please have a look if that works for your USB use case.

imphil avatar Feb 12 '20 15:02 imphil

This looks perfectly suited for the USB use case @imphil!

vogelpi avatar Feb 12 '20 16:02 vogelpi

@udinator would like to use that to vendor code into Ibex. We should prioritize this.

imphil avatar Mar 17 '20 19:03 imphil

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:?

udinator avatar Mar 17 '20 19:03 udinator

No, exclude and patch_dir don't depend on each other.

imphil avatar Mar 17 '20 19:03 imphil

This was handled by #2077. There are a couple of follow-ups from that, but they have their own separate tracking issues.

rswarbrick avatar Mar 11 '22 11:03 rswarbrick