Skip to content

Commit 4a0e7c3

Browse files
committed
feat(ios): store prebuilt tarballs in shared cache folder
1 parent 08f954f commit 4a0e7c3

3 files changed

Lines changed: 52 additions & 12 deletions

File tree

packages/react-native/scripts/cocoapods/rncore.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,10 @@ def self.podspec_source_download_prebuild_stable_tarball()
157157
end
158158

159159
rncore_log("Resolved stable ReactNativeCore-prebuilt version:")
160-
rncore_log(" #{Pathname.new(destinationDebug).relative_path_from(Pathname.pwd).to_s}")
161-
rncore_log(" #{Pathname.new(destinationRelease).relative_path_from(Pathname.pwd).to_s}")
160+
rncore_log(" #{destinationDebug}")
161+
rncore_log(" #{destinationRelease}")
162162

163+
ensure_pods_symlink()
163164
return {:http => URI::File.build(path: destinationDebug).to_s }
164165
end
165166

@@ -185,17 +186,18 @@ def self.podspec_source_download_prebuilt_nightly_tarball()
185186
dSymsDebug = download_nightly_rncore(@@react_native_path, @@react_native_version, :debug, true)
186187
dSymsRelease = download_nightly_rncore(@@react_native_path, @@react_native_version, :release, true)
187188
rncore_log("Resolved nightly dSYMs")
188-
rncore_log(" #{Pathname.new(dSymsDebug).relative_path_from(Pathname.pwd).to_s}")
189-
rncore_log(" #{Pathname.new(dSymsRelease).relative_path_from(Pathname.pwd).to_s}")
189+
rncore_log(" #{dSymsDebug}")
190+
rncore_log(" #{dSymsRelease}")
190191

191192
# Make sure that the dSYMs are processed
192193
process_dsyms(destinationDebug, dSymsDebug)
193194
process_dsyms(destinationRelease, dSymsRelease)
194195
end
195196

196197
rncore_log("Resolved nightly ReactNativeCore-prebuilt version:")
197-
rncore_log(" #{Pathname.new(destinationDebug).relative_path_from(Pathname.pwd).to_s}")
198-
rncore_log(" #{Pathname.new(destinationRelease).relative_path_from(Pathname.pwd).to_s}")
198+
rncore_log(" #{destinationDebug}")
199+
rncore_log(" #{destinationRelease}")
200+
ensure_pods_symlink()
199201
return {:http => URI::File.build(path: destinationDebug).to_s }
200202
end
201203

@@ -410,11 +412,11 @@ def self.download_rncore_tarball(react_native_path, tarball_url, version, config
410412

411413
unless File.exist?(destination_path)
412414
# Download to a temporary file first so we don't cache incomplete downloads.
413-
rncore_log("Downloading ReactNativeCore-prebuilt #{dsyms ? "dSYMs " : ""}#{configuration ? configuration.to_s : ""} tarball from #{tarball_url} to #{Pathname.new(destination_path).relative_path_from(Pathname.pwd).to_s}")
415+
rncore_log("Downloading ReactNativeCore-prebuilt #{dsyms ? "dSYMs " : ""}#{configuration ? configuration.to_s : ""} tarball from #{tarball_url} to #{destination_path}")
414416
tmp_file = "#{artifacts_dir()}/reactnative-core.download"
415417
`mkdir -p "#{artifacts_dir()}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
416418
else
417-
rncore_log("Using downloaded ReactNativeCore-prebuilt #{dsyms ? "dSYMs " : ""}#{configuration ? configuration.to_s : ""} tarball at #{Pathname.new(destination_path).relative_path_from(Pathname.pwd).to_s}")
419+
rncore_log("Using downloaded ReactNativeCore-prebuilt #{dsyms ? "dSYMs " : ""}#{configuration ? configuration.to_s : ""} tarball at #{destination_path}")
418420
end
419421

420422
return destination_path
@@ -429,7 +431,19 @@ def self.nightly_artifact_exists(version)
429431
end
430432

431433
def self.artifacts_dir()
432-
return File.join(Pod::Config.instance.project_pods_root, "ReactNativeCore-artifacts")
434+
return ENV['RCT_PREBUILT_CACHE_DIR'] || "/tmp/react-native-prebuilt"
435+
end
436+
437+
def self.ensure_pods_symlink()
438+
pods_artifacts = File.join(Pod::Config.instance.project_pods_root, "ReactNativeCore-artifacts")
439+
if File.symlink?(pods_artifacts)
440+
return if File.readlink(pods_artifacts) == artifacts_dir()
441+
FileUtils.rm(pods_artifacts)
442+
elsif File.exist?(pods_artifacts)
443+
FileUtils.rm_rf(pods_artifacts)
444+
end
445+
FileUtils.mkdir_p(File.dirname(pods_artifacts))
446+
FileUtils.ln_sf(artifacts_dir(), pods_artifacts)
433447
end
434448

435449
# This function checks that ReactNativeCore artifact exists on the maven repo

packages/react-native/scripts/cocoapods/rndependencies.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def self.podspec_source_download_prebuild_release_tarball()
161161
destinationDebug = download_stable_rndeps(@@react_native_path, @@react_native_version, :debug)
162162
download_stable_rndeps(@@react_native_path, @@react_native_version, :release)
163163

164+
ensure_pods_symlink()
164165
return {:http => URI::File.build(path: destinationDebug).to_s }
165166
end
166167

@@ -228,8 +229,8 @@ def self.podspec_source_download_prebuilt_nightly_tarball(version)
228229
destinationDebug = download_nightly_rndeps(@@react_native_path, @@react_native_version, :debug)
229230
download_nightly_rndeps(@@react_native_path, @@react_native_version, :release)
230231

232+
ensure_pods_symlink()
231233
return {:http => URI::File.build(path: destinationDebug).to_s }
232-
return {:http => url}
233234
end
234235

235236
def self.download_rndeps_tarball(react_native_path, tarball_url, version, configuration)
@@ -255,7 +256,19 @@ def self.nightly_artifact_exists(version)
255256
end
256257

257258
def self.artifacts_dir()
258-
return File.join(Pod::Config.instance.project_pods_root, "ReactNativeDependencies-artifacts")
259+
return ENV['RCT_PREBUILT_CACHE_DIR'] || "/tmp/react-native-prebuilt"
260+
end
261+
262+
def self.ensure_pods_symlink()
263+
pods_artifacts = File.join(Pod::Config.instance.project_pods_root, "ReactNativeDependencies-artifacts")
264+
if File.symlink?(pods_artifacts)
265+
return if File.readlink(pods_artifacts) == artifacts_dir()
266+
FileUtils.rm(pods_artifacts)
267+
elsif File.exist?(pods_artifacts)
268+
FileUtils.rm_rf(pods_artifacts)
269+
end
270+
FileUtils.mkdir_p(File.dirname(pods_artifacts))
271+
FileUtils.ln_sf(artifacts_dir(), pods_artifacts)
259272
end
260273

261274
# This function checks that ReactNativeDependencies artifact exists on the maven repo

packages/react-native/sdks/hermes-engine/hermes-utils.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def podspec_source_download_prebuild_release_tarball(react_native_path, version)
194194
hermes_log("Using release tarball from URL: #{url}")
195195
download_stable_hermes(react_native_path, version, :debug)
196196
download_stable_hermes(react_native_path, version, :release)
197+
ensure_hermes_pods_symlink()
197198
return {:http => url}
198199
end
199200

@@ -206,7 +207,19 @@ def podspec_source_download_prebuilt_nightly_tarball(version)
206207
# HELPERS
207208

208209
def artifacts_dir()
209-
return File.join(Pod::Config.instance.project_pods_root, "hermes-engine-artifacts")
210+
return ENV['RCT_PREBUILT_CACHE_DIR'] || "/tmp/react-native-prebuilt"
211+
end
212+
213+
def ensure_hermes_pods_symlink()
214+
pods_artifacts = File.join(Pod::Config.instance.project_pods_root, "hermes-engine-artifacts")
215+
if File.symlink?(pods_artifacts)
216+
return if File.readlink(pods_artifacts) == artifacts_dir()
217+
FileUtils.rm(pods_artifacts)
218+
elsif File.exist?(pods_artifacts)
219+
FileUtils.rm_rf(pods_artifacts)
220+
end
221+
FileUtils.mkdir_p(File.dirname(pods_artifacts))
222+
FileUtils.ln_sf(artifacts_dir(), pods_artifacts)
210223
end
211224

212225
def hermestag_file(react_native_path)

0 commit comments

Comments
 (0)