Skip to content

Commit

Permalink
Make CircleCI caches for hermesc be version dependent (facebook#37452)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#37452

Fixes facebook#37428

We do have cache poisoning for hermesc on Windows and Linux due to reusing the same cache key among different
React Native version. This fixes it by specifying a cache key which is version dependent + it invalidates the
caches by defining a new key.

Changelog:
[Internal] [Fixed] - Make CircleCI caches for hermesc be version dependent

Differential Revision: D45909178

fbshipit-source-id: b9491a759fdb0da5bbbb710b2fd93ecff5fd14f3
  • Loading branch information
cipolleschi authored and facebook-github-bot committed May 22, 2023
1 parent 92c7219 commit d54202a
Showing 1 changed file with 86 additions and 69 deletions.
155 changes: 86 additions & 69 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ references:
hermes_workspace_cache_key: &hermes_workspace_cache_key v4-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
hermes_workspace_debug_cache_key: &hermes_workspace_debug_cache_key v2-hermes-{{ .Environment.CIRCLE_JOB }}-debug-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
hermes_workspace_release_cache_key: &hermes_workspace_release_cache_key v2-hermes-{{ .Environment.CIRCLE_JOB }}-release-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
hermes_windows_cache_key: &hermes_windows_cache_key v3-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "tmp/hermes/hermesversion" }}
hermes_linux_cache_key: &hermes_linux_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-linux-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
hermes_windows_cache_key: &hermes_windows_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-windows-{{ checksum "tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
hermes_tarball_debug_cache_key: &hermes_tarball_debug_cache_key v4-hermes-tarball-debug-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
hermes_tarball_release_cache_key: &hermes_tarball_release_cache_key v3-hermes-tarball-release-{{ checksum "/tmp/hermes/hermesversion" }}-{{ checksum "/tmp/react-native-version" }}
pods_cache_key: &pods_cache_key v8-pods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile.lock.bak" }}-{{ checksum "packages/rn-tester/Podfile" }}
Expand Down Expand Up @@ -314,11 +315,24 @@ commands:
- run:
name: Get React Native version
command: |
VERSION=$( grep '"version"' packages/react-native/package.json | cut -d '"' -f 4 | head -1)
VERSION=$(cat packages/react-native/package.json | jq -r '.version')
# Save the react native version we are building in a file so we can use that file as part of the cache key.
echo "$VERSION" > /tmp/react-native-version
echo "React Native Version is $(cat /tmp/react-native-version)"
echo "Hermes commit is $(cat /tmp/hermes/hermesversion)"
HERMES_VERSION="$(cat /tmp/hermes/hermesversion)"
echo "Hermes commit is $HERMES_VERSION"
get_react_native_version_windows:
steps:
- run:
name: Get React Native version on Windows
command: |
$VERSION=cat packages/react-native/package.json | jq -r '.version'
# Save the react native version we are building in a file so we can use that file as part of the cache key.
echo "$VERSION" > /tmp/react-native-version
echo "React Native Version is $(cat /tmp/react-native-version)"
$HERMES_VERSION=cat /tmp/hermes/hermesversion
echo "Hermes commit is $HERMES_VERSION"
with_hermes_tarball_cache_span:
parameters:
Expand Down Expand Up @@ -729,7 +743,7 @@ jobs:

- store_test_results:
path: ~/react-native/packages/react-native-gradle-plugin/build/test-results

- store_test_results:
path: ~/react-native/packages/react-native/ReactAndroid/build/test-results

Expand Down Expand Up @@ -1146,17 +1160,18 @@ jobs:
docker:
- image: debian:bullseye
resource_class: "xlarge"
working_directory: /root
steps:
- checkout_code_with_cache
- run:
name: Install dependencies
command: |
apt update
apt install -y git openssh-client cmake build-essential \
libreadline-dev libicu-dev zip python3
libreadline-dev libicu-dev jq zip python3
- *attach_hermes_workspace
- get_react_native_version
- restore_cache:
key: *hermes_workspace_cache_key
key: *hermes_linux_cache_key
- run:
name: Set up workspace
command: |
Expand All @@ -1175,7 +1190,7 @@ jobs:
cp /tmp/hermes/build/bin/hermesc /tmp/hermes/linux64-bin/.
fi
- save_cache:
key: *hermes_workspace_cache_key
key: *hermes_linux_cache_key
paths:
- /tmp/hermes/linux64-bin/
- /tmp/hermes/hermes/destroot/
Expand Down Expand Up @@ -1296,68 +1311,70 @@ jobs:
- MSBUILD_DIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin'
- CMAKE_DIR: 'C:\Program Files\CMake\bin'
steps:
- checkout_code_with_cache
- *attach_hermes_workspace
- restore_cache:
key: *hermes_windows_cache_key
- run:
name: Set up workspace
command: |
New-Item -ItemType Directory $Env:HERMES_WS_DIR
New-Item -ItemType Directory $Env:HERMES_WS_DIR\icu
New-Item -ItemType Directory $Env:HERMES_WS_DIR\deps
New-Item -ItemType Directory $Env:HERMES_WS_DIR\win64-bin
New-Item -ItemType SymbolicLink -Target tmp\hermes\hermes -Path $Env:HERMES_WS_DIR -Name hermes
- run:
name: Build HermesC for Windows
command: |
if (-not(Test-Path -Path $Env:HERMES_WS_DIR\win64-bin\hermesc.exe)) {
choco install --no-progress cmake --version 3.14.7
if (-not $?) { throw "Failed to install CMake" }
cd $Env:HERMES_WS_DIR\icu
# If Invoke-WebRequest shows a progress bar, it will fail with
# Win32 internal error "Access is denied" 0x5 occurred [...]
$progressPreference = 'silentlyContinue'
Invoke-WebRequest -Uri "$Env:ICU_URL" -OutFile "icu.zip"
Expand-Archive -Path "icu.zip" -DestinationPath "."
cd $Env:HERMES_WS_DIR
Copy-Item -Path "icu\bin64\icu*.dll" -Destination "deps"
# Include MSVC++ 2015 redistributables
Copy-Item -Path "c:\windows\system32\msvcp140.dll" -Destination "deps"
Copy-Item -Path "c:\windows\system32\vcruntime140.dll" -Destination "deps"
Copy-Item -Path "c:\windows\system32\vcruntime140_1.dll" -Destination "deps"
$Env:PATH += ";$Env:CMAKE_DIR;$Env:MSBUILD_DIR"
$Env:ICU_ROOT = "$Env:HERMES_WS_DIR\icu"
cmake -S hermes -B build_release -G 'Visual Studio 16 2019' -Ax64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=True -DHERMES_ENABLE_WIN10_ICU_FALLBACK=OFF
if (-not $?) { throw "Failed to configure Hermes" }
cd build_release
cmake --build . --target hermesc --config Release
if (-not $?) { throw "Failed to build Hermes" }
cd $Env:HERMES_WS_DIR
Copy-Item -Path "build_release\bin\Release\hermesc.exe" -Destination "win64-bin"
# Include Windows runtime dependencies
Copy-Item -Path "deps\*" -Destination "win64-bin"
}
else {
Write-Host "Skipping; Clean c:\tmp\hermes\win64-bin to rebuild."
}
- save_cache:
key: *hermes_windows_cache_key
paths:
- C:\tmp\hermes\win64-bin\
- C:\tmp\hermes\hermes\icu\
- C:\tmp\hermes\hermes\deps\
- C:\tmp\hermes\hermes\build_release\
- store_artifacts:
path: C:\tmp\hermes\win64-bin\
- persist_to_workspace:
root: C:\tmp\hermes\
paths:
- win64-bin
- get_react_native_version_windows
# - restore_cache:
# key: *hermes_windows_cache_key
# - run:
# name: Set up workspace
# command: |
# New-Item -ItemType Directory $Env:HERMES_WS_DIR
# New-Item -ItemType Directory $Env:HERMES_WS_DIR\icu
# New-Item -ItemType Directory $Env:HERMES_WS_DIR\deps
# New-Item -ItemType Directory $Env:HERMES_WS_DIR\win64-bin
# New-Item -ItemType SymbolicLink -Target tmp\hermes\hermes -Path $Env:HERMES_WS_DIR -Name hermes
# - run:
# name: Build HermesC for Windows
# command: |
# if (-not(Test-Path -Path $Env:HERMES_WS_DIR\win64-bin\hermesc.exe)) {
# choco install --no-progress cmake --version 3.14.7
# if (-not $?) { throw "Failed to install CMake" }

# cd $Env:HERMES_WS_DIR\icu
# # If Invoke-WebRequest shows a progress bar, it will fail with
# # Win32 internal error "Access is denied" 0x5 occurred [...]
# $progressPreference = 'silentlyContinue'
# Invoke-WebRequest -Uri "$Env:ICU_URL" -OutFile "icu.zip"
# Expand-Archive -Path "icu.zip" -DestinationPath "."

# cd $Env:HERMES_WS_DIR
# Copy-Item -Path "icu\bin64\icu*.dll" -Destination "deps"
# # Include MSVC++ 2015 redistributables
# Copy-Item -Path "c:\windows\system32\msvcp140.dll" -Destination "deps"
# Copy-Item -Path "c:\windows\system32\vcruntime140.dll" -Destination "deps"
# Copy-Item -Path "c:\windows\system32\vcruntime140_1.dll" -Destination "deps"

# $Env:PATH += ";$Env:CMAKE_DIR;$Env:MSBUILD_DIR"
# $Env:ICU_ROOT = "$Env:HERMES_WS_DIR\icu"

# cmake -S hermes -B build_release -G 'Visual Studio 16 2019' -Ax64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=True -DHERMES_ENABLE_WIN10_ICU_FALLBACK=OFF
# if (-not $?) { throw "Failed to configure Hermes" }
# cd build_release
# cmake --build . --target hermesc --config Release
# if (-not $?) { throw "Failed to build Hermes" }

# cd $Env:HERMES_WS_DIR
# Copy-Item -Path "build_release\bin\Release\hermesc.exe" -Destination "win64-bin"
# # Include Windows runtime dependencies
# Copy-Item -Path "deps\*" -Destination "win64-bin"
# }
# else {
# Write-Host "Skipping; Clean c:\tmp\hermes\win64-bin to rebuild."
# }
# - save_cache:
# key: *hermes_windows_cache_key
# paths:
# - C:\tmp\hermes\win64-bin\
# - C:\tmp\hermes\hermes\icu\
# - C:\tmp\hermes\hermes\deps\
# - C:\tmp\hermes\hermes\build_release\
# - store_artifacts:
# path: C:\tmp\hermes\win64-bin\
# - persist_to_workspace:
# root: C:\tmp\hermes\
# paths:
# - win64-bin

# -------------------------
# JOBS: Releases
Expand Down

0 comments on commit d54202a

Please sign in to comment.