From e25682b802ef40f5ba6cd271561660c3ed23df6a Mon Sep 17 00:00:00 2001 From: William Brown Date: Fri, 4 Mar 2022 14:10:44 +1000 Subject: [PATCH] Allow formatting of the sccache uri This allows a format to be specified in the sccache uri, specifically the file uri so that a per-package cache can be created. This way an osc build locally doesn't ruin your cache moving between different packages. --- osc/build.py | 25 +++++++++++++++---------- osc/conf.py | 7 ++++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/osc/build.py b/osc/build.py index 8796c36bc..ff3d31559 100644 --- a/osc/build.py +++ b/osc/build.py @@ -682,16 +682,6 @@ def main(apiurl, opts, argv): if opts.pkg_ccache: buildargs.append('--pkg-ccache=%s' % opts.pkg_ccache) xp.append('ccache') - if opts.sccache_uri or config['sccache_uri'] or opts.sccache or config['sccache']: - if opts.pkg_ccache or opts.ccache or config['ccache']: - raise oscerr.WrongArgs('Error: sccache and ccache can not be enabled at the same time') - if opts.sccache_uri: - buildargs.append('--sccache-uri=%s' % opts.sccache_uri) - elif config['sccache_uri']: - buildargs.append('--sccache-uri=%s' % config['sccache_uri']) - else: - buildargs.append('--sccache') - xp.append('sccache') if opts.linksources: buildargs.append('--linksources') if opts.baselibs: @@ -779,6 +769,21 @@ def main(apiurl, opts, argv): except: pass + # We configure sccache after pacname, so that in default cases we can have an sccache for each + # package to prevent cross-cache polutions. It helps to make the local-use case a bit nicer. + if opts.sccache_uri or config['sccache_uri'] or opts.sccache or config['sccache']: + if opts.pkg_ccache or opts.ccache or config['ccache']: + raise oscerr.WrongArgs('Error: sccache and ccache can not be enabled at the same time') + sccache_arg = "--sccache-uri=/var/tmp/osbuild-sccache-{pkgname}.tar" + if opts.sccache_uri: + sccache_arg = '--sccache-uri=%s' % opts.sccache_uri + elif config['sccache_uri']: + sccache_arg = '--sccache-uri=%s' % config['sccache_uri'] + # Format the package name. + sccache_arg = sccache_arg.format(pkgname=pacname) + buildargs.append(sccache_arg) + xp.append('sccache') + # define buildinfo & config local cache bi_file = None bc_file = None diff --git a/osc/conf.py b/osc/conf.py index 8d741625c..e5a08bbde 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -304,9 +304,14 @@ def _identify_osccookiejar(): # ccache = 1 # Enable sccache in build roots. Conflicts with ccache. +# Equivalent to sccache_uri = file:///var/tmp/osbuild-sccache-{pkgname}.tar # sccache = 1 -# Optional remote URI for sccache storage. +# Optional URI for sccache storage. Maybe a file://, redis:// or other URI supported +# by the configured sccache install. This uri MAY take {pkgname} as a special parameter +# which will be replaced with the name of the package to be built. +# sccache_uri = file:///var/tmp/osbuild-sccache-{pkgname}.tar.lzop +# sccache_uri = file:///var/tmp/osbuild-sccache-{pkgname}.tar # sccache_uri = redis://127.0.0.1:6379 # extra packages to install when building packages locally (osc build)