Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions packages/react-native/scripts/cocoapods/rncore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,36 @@ def self.download_nightly_rncore(react_native_path, version, configuration, dsym
download_rncore_tarball(react_native_path, tarball_url, version, configuration, dsyms)
end

def self.shared_cache_dir()
return File.join(Dir.home, "Library", "Caches", "ReactNative")
end

def self.download_rncore_tarball(react_native_path, tarball_url, version, configuration, dsyms = false)
destination_path = configuration == nil ?
"#{artifacts_dir()}/reactnative-core-#{version}#{dsyms ? "-dSYM" : ""}.tar.gz" :
"#{artifacts_dir()}/reactnative-core-#{version}#{dsyms ? "-dSYM" : ""}-#{configuration}.tar.gz"
filename = configuration == nil ?
"reactnative-core-#{version}#{dsyms ? "-dSYM" : ""}.tar.gz" :
"reactnative-core-#{version}#{dsyms ? "-dSYM" : ""}-#{configuration}.tar.gz"
destination_path = "#{artifacts_dir()}/#{filename}"

if File.exist?(destination_path)
rncore_log("Tarball #{filename} already exists in Pods. Skipping download.")
return destination_path
end

unless File.exist?(destination_path)
`mkdir -p "#{artifacts_dir()}"`

cached_path = File.join(shared_cache_dir(), filename)
if File.exist?(cached_path)
rncore_log("Cache hit: copying #{filename} from shared cache (#{shared_cache_dir()})")
FileUtils.cp(cached_path, destination_path)
else
rncore_log("Cache miss: downloading #{filename} from #{tarball_url}")
# Download to a temporary file first so we don't cache incomplete downloads.
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}")
tmp_file = "#{artifacts_dir()}/reactnative-core.download"
`mkdir -p "#{artifacts_dir()}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
else
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}")
`curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
# Save to shared cache for future use
`mkdir -p "#{shared_cache_dir()}"`
FileUtils.cp(destination_path, cached_path)
rncore_log("Saved #{filename} to shared cache (#{shared_cache_dir()})")
end

return destination_path
Expand Down
31 changes: 26 additions & 5 deletions packages/react-native/scripts/cocoapods/rndependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,36 @@ def self.podspec_source_download_prebuilt_nightly_tarball(version)
return {:http => url}
end

def self.shared_cache_dir()
return File.join(Dir.home, "Library", "Caches", "ReactNative")
end

def self.download_rndeps_tarball(react_native_path, tarball_url, version, configuration)
destination_path = configuration == nil ?
"#{artifacts_dir()}/reactnative-dependencies-#{version}.tar.gz" :
"#{artifacts_dir()}/reactnative-dependencies-#{version}-#{configuration}.tar.gz"
filename = configuration == nil ?
"reactnative-dependencies-#{version}.tar.gz" :
"reactnative-dependencies-#{version}-#{configuration}.tar.gz"
destination_path = "#{artifacts_dir()}/#{filename}"

if File.exist?(destination_path)
rndeps_log("Tarball #{filename} already exists in Pods. Skipping download.")
return destination_path
end

unless File.exist?(destination_path)
`mkdir -p "#{artifacts_dir()}"`

cached_path = File.join(shared_cache_dir(), filename)
if File.exist?(cached_path)
rndeps_log("Cache hit: copying #{filename} from shared cache (#{shared_cache_dir()})")
FileUtils.cp(cached_path, destination_path)
else
rndeps_log("Cache miss: downloading #{filename} from #{tarball_url}")
# Download to a temporary file first so we don't cache incomplete downloads.
tmp_file = "#{artifacts_dir()}/reactnative-dependencies.download"
`mkdir -p "#{artifacts_dir()}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
`curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
# Save to shared cache for future use
`mkdir -p "#{shared_cache_dir()}"`
FileUtils.cp(destination_path, cached_path)
rndeps_log("Saved #{filename} to shared cache (#{shared_cache_dir()})")
end

return destination_path
Expand Down
32 changes: 27 additions & 5 deletions packages/react-native/sdks/hermes-engine/hermes-utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,38 @@ def download_stable_hermes(react_native_path, version, configuration)
download_hermes_tarball(react_native_path, tarball_url, version, configuration)
end

def shared_cache_dir()
return File.join(Dir.home, "Library", "Caches", "ReactNative")
end

def download_hermes_tarball(react_native_path, tarball_url, version, configuration)
destination_path = configuration == nil ?
"#{artifacts_dir()}/hermes-ios-#{version}.tar.gz" :
"#{artifacts_dir()}/hermes-ios-#{version}-#{configuration}.tar.gz"
filename = configuration == nil ?
"hermes-ios-#{version}.tar.gz" :
"hermes-ios-#{version}-#{configuration}.tar.gz"
destination_path = "#{artifacts_dir()}/#{filename}"

if File.exist?(destination_path)
hermes_log("Tarball #{filename} already exists in Pods. Skipping download.", :info)
return destination_path
end

unless File.exist?(destination_path)
`mkdir -p "#{artifacts_dir()}"`

cached_path = File.join(shared_cache_dir(), filename)
if File.exist?(cached_path)
hermes_log("Cache hit: copying #{filename} from shared cache (#{shared_cache_dir()})", :info)
FileUtils.cp(cached_path, destination_path)
else
hermes_log("Cache miss: downloading #{filename} from #{tarball_url}", :info)
# Download to a temporary file first so we don't cache incomplete downloads.
tmp_file = "#{artifacts_dir()}/hermes-ios.download"
`mkdir -p "#{artifacts_dir()}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
`curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
# Save to shared cache for future use
`mkdir -p "#{shared_cache_dir()}"`
FileUtils.cp(destination_path, cached_path)
hermes_log("Saved #{filename} to shared cache (#{shared_cache_dir()})", :info)
end

return destination_path
end

Expand Down
Loading