@@ -363,12 +363,63 @@ commands:
363
363
- matrix_notify_failure_unless_pr
364
364
365
365
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.
366
371
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.
369
407
- run :
370
408
name : Install build dependencies
371
409
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
372
423
373
424
defaults :
374
425
0 commit comments