Search code examples
yocto

Make yocto download more sources after unpacking


I have a recipe which references source A via the SRC_URI variable. However inside source A there is somewhere a link to another source B. I'd like to let Yocto download and unpack source A. Then I would parse the URL for source B from source A and tell Yocto to go back to downloading and unpacking source B. Is this possible?

The build process for source A would download source B itself, but I'd like Yocto to add source B to its DL_DIR to avoid downloading it again for the next build.


Solution

  • You can use Bitbake's fetcher to fetch more sources.

    It's important to note that the fetcher will still use the SRCREV variable, even if you append something like ;rev=xxx to your URL. So you should set SRCREV to either None or "AUTOINC".

    python do_loadSources() {
      # Backup SRCREV
      mySrcRev = d.getVar('SRCREV')
      d.setVar('SRCREV', None)
      
      # Somehow determine source URL
      sourceUrl = ...
    
      # Create fetcher
      fetcher = bb.fetch2.Fetch([ sourceUrl ], d)
    
      # Download
      fetcher.download()
    
      # Get path of downloaded sources
      fetcher.localpath(sourceUrl)
    
      # Use the downloaded sources
      ...
    
      # Restore SRCREV
      d.setVar('SRCREV', mySrcRev)
    }
    
    addtask do_loadSources after do_configure before do_compile