Skip to content

Commit 89a70c7

Browse files
authored
Merge pull request ethereum#14795 from ethereum/osx-caching
Fix macOS dependency cache.
2 parents ce98680 + ba95a29 commit 89a70c7

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

.circleci/config.yml

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,63 @@ commands:
363363
- matrix_notify_failure_unless_pr
364364

365365
install_dependencies_osx:
366+
# An extra cache key is used to only save the flag that communicates whether the cache exists.
367+
# if this flag was set (the cache exist) we remove all files located in /usr/local & /opt/homebrew.
368+
# With this simple trick restoring the cache is much faster. Otherwise CircleCI is generating
369+
# warning messages if a file from the cache is overwriting an already existing file on disk.
370+
# Restoring the cache is much faster if we remove all potentially conflicting files beforehand.
366371
steps:
367-
# FIXME: We used to cache dependencies on macOS but now it takes longer than just installing
368-
# them each time. See https://github.com/ethereum/solidity/issues/12925.
372+
- restore_cache:
373+
keys:
374+
- osx-dependencies-cached-{{ arch }}-{{ checksum ".circleci/osx_install_dependencies.sh" }}
375+
- run:
376+
name: Installing dependencies / Restoring dependency cache
377+
command: |
378+
if [[ -f ~/osx-dependencies-cached ]]; then
379+
echo "Dependency flag exists. Removing /usr/local/ and /opt/homebrew/. These directories will be restored from cache."
380+
381+
# CircleCI is providing the circleci cli tools via some kind of symlink magic.
382+
# So we just save the original symlinks and restore them later.
383+
circleci_binary_path=$(command -v circleci)
384+
circleci_agent_binary_path=$(command -v circleci-agent)
385+
cp "${circleci_binary_path}" /tmp/circleci
386+
cp "${circleci_agent_binary_path}" /tmp/circleci-agent
387+
388+
# Homebrew is installed in /usr/local on intel macs, but in /opt/homebrew on apple silicon.
389+
if [[ -d /opt/homebrew ]]; then
390+
sudo rm -rf /opt/homebrew
391+
sudo mkdir -p /opt/homebrew/bin
392+
sudo chmod 777 /opt/{homebrew,homebrew/bin}
393+
fi
394+
# under macos /usr/local itself is read-only, so we just remove its sub-directories.
395+
sudo rm -rf /usr/local/*
396+
sudo mkdir -p /usr/local/bin
397+
sudo chmod 777 /usr/{local,local/bin}
398+
399+
mv /tmp/circleci "${circleci_binary_path}"
400+
mv /tmp/circleci-agent "${circleci_agent_binary_path}"
401+
fi
402+
- restore_cache:
403+
keys:
404+
- osx-dependencies-{{ arch }}-{{ checksum ".circleci/osx_install_dependencies.sh" }}
405+
# DO NOT EDIT between here and save_cache, but rather edit ./circleci/osx_install_dependencies.sh
406+
# WARNING! If you do edit anything here instead, remember to invalidate the cache manually.
369407
- run:
370408
name: Install build dependencies
371409
command: .circleci/osx_install_dependencies.sh
410+
- run:
411+
name: Mark dependencies as cached
412+
command: touch ~/osx-dependencies-cached
413+
- save_cache:
414+
key: osx-dependencies-{{ arch }}-{{ checksum ".circleci/osx_install_dependencies.sh" }}
415+
paths:
416+
# Homebrew is installed in /usr/local on intel macs, but in /opt/homebrew on apple silicon.
417+
- /usr/local
418+
- /opt/homebrew
419+
- save_cache:
420+
key: osx-dependencies-cached-{{ arch }}-{{ checksum ".circleci/osx_install_dependencies.sh" }}
421+
paths:
422+
- ~/osx-dependencies-cached
372423

373424
defaults:
374425

.circleci/osx_install_dependencies.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@
2626
# ------------------------------------------------------------------------------
2727

2828
# note that the following directories may be cached by circleci:
29-
# - /usr/local/bin
30-
# - /usr/local/sbin
31-
# - /usr/local/lib
32-
# - /usr/local/include
33-
# - /usr/local/Cellar
34-
# - /usr/local/Homebrew
29+
# - /usr/local
30+
# - /opt/homebrew
3531

3632
set -eu
3733

0 commit comments

Comments
 (0)