diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2023-06-01 16:29:55 +0530 |
---|---|---|
committer | GStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2023-06-07 18:35:43 +0000 |
commit | 4217ba6a202a3ce5151fa5744fff50462b260302 (patch) | |
tree | 6bdd8c0bf40a8961218f78c005b973fccfc1a1a8 | |
parent | 55ccdd9f91cdf96e33abf1cd34f718b40455e94e (diff) |
cerbero: Don't extract if already extracted in fetch
Some recipes need to extract the source tree in order to know what
else needs to be fetched. At present, this is true for Cargo recipes
where we need to run `cargo vendor` to fetch sources for offline
build.
This is especially important for Cargo recipes, because `cargo vendor`
can take a dozen minutes or more on Windows. This should speed up the
MSVC CI by 15-20 minutes.
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1199>
-rw-r--r-- | cerbero/build/source.py | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/cerbero/build/source.py b/cerbero/build/source.py index 6ace7a53..45ee1267 100644 --- a/cerbero/build/source.py +++ b/cerbero/build/source.py @@ -60,6 +60,8 @@ class Source (object): patches = None strip = 1 offline = False + _extract_locks = collections.defaultdict(asyncio.Lock) + _extract_done = set() def __init__(self): if self.patches is None: @@ -101,21 +103,6 @@ class Source (object): f.write(ct) m.log('Created cargo vendor config.toml', logfile=logfile) - async def fetch(self, **kwargs): - self.fetch_impl(**kwargs) - - def fetch_impl(self): - ''' - Fetch the sources - ''' - raise NotImplemented("'fetch' must be implemented by subclasses") - - async def extract(self): - ''' - Extracts the sources - ''' - raise NotImplemented("'extract' must be implemented by subclasses") - def expand_url_template(self, s): ''' Expand a standard URL template (GNOME, SourceForge, GNU, etc) @@ -157,6 +144,32 @@ class Source (object): files.append(self.__file__) return files + async def fetch(self, **kwargs): + self.fetch_impl(**kwargs) + + def fetch_impl(self): + ''' + Fetch the sources + ''' + raise NotImplemented("'fetch' must be implemented by subclasses") + + async def extract(self): + # Could have multiple recipes using the same git repo, or extract + # could've already been done in fetch by cargo recipes. + lock = self._extract_locks[self.config_src_dir] + async with lock: + if self.config_src_dir in self._extract_done: + m.log('Extract already completed', logfile=get_logfile(self)) + return + await self.extract_impl() + self._extract_done.add(self.config_src_dir) + + async def extract_impl(self): + ''' + Extracts the sources + ''' + raise NotImplemented("'extract' must be implemented by subclasses") + class CustomSource (Source): @@ -311,6 +324,7 @@ class Tarball(BaseTarball, Source): if issubclass(self.btype, BuildType.CARGO): m.log(f'Extracting project {self.name} to run cargo vendor', logfile=get_logfile(self)) await self.extract_impl(fetching=True) + self._extract_done.add(self.config_src_dir) async def extract_impl(self, fetching=False): m.action(_('Extracting tarball to %s') % self.config_src_dir, logfile=get_logfile(self)) @@ -338,9 +352,6 @@ class Tarball(BaseTarball, Source): if issubclass(self.btype, BuildType.CARGO): await self.cargo_vendor(not fetching or self.offline) - async def extract(self): - await self.extract_impl() - class GitCache (Source): ''' @@ -415,6 +426,7 @@ class GitCache (Source): if issubclass(self.btype, BuildType.CARGO): m.log(f'Extracting project to run cargo vendor', logfile=get_logfile(self)) await self.extract_impl(fetching=True) + self._extract_done.add(self.config_src_dir) def built_version(self): @@ -426,24 +438,12 @@ class Git (GitCache): Source handler for git repositories ''' - _extract_locks = collections.defaultdict(asyncio.Lock) - _extract_done = set() - def __init__(self): GitCache.__init__(self) if self.commit is None: # Used by recipes in recipes/toolchain/ self.commit = 'origin/sdk-%s' % self.version - async def extract(self): - # Could have multiple recipes using the same repo. - lock = self._extract_locks[self.config_src_dir] - async with lock: - if self.config_src_dir in self._extract_done: - return - await self.extract_impl() - self._extract_done.add(self.config_src_dir) - async def extract_impl(self, fetching=False): if os.path.exists(self.config_src_dir): try: @@ -492,8 +492,8 @@ class GitExtractedTarball(Git): Git.__init__(self) self._files = {} - async def extract(self): - if not await Git.extract(self): + async def extract_impl(self): + if not await super().extract_impl(): return False for match in self.matches: self._files[match] = [] @@ -556,7 +556,7 @@ class Svn(Source): await svn.checkout(self.url, self.repo_dir) await svn.update(self.repo_dir, self.revision) - async def extract(self): + async def extract_impl(self): if os.path.exists(self.config_src_dir): shutil.rmtree(self.config_src_dir) |