Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: support Gradle configuration cache #2201

Conversation

ahruss
Copy link
Contributor

@ahruss ahruss commented Dec 11, 2023

Summary:

Directly calling Runtime.exec breaks Gradle configuration caching. An easy workaround is to use providers.exec instead, which supports configuration caching.

Test Plan:

This change should be functionally equivalent to existing behavior. I've tested locally that my project's gradle build still works with this change, both with and without the --configuration-cache argument

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md

Directly using Runtime.exec breaks Gradle configuration caching. This change is to use `providers.exec` which supports configuration caching. This is a minimal fix; it's likely possible that more invasive changes could be useful to avoid having to exec these processes at all until their values are needed, but I have not looked into larger structural changes.
Co-authored-by: Nicola Corti <corti.nico@gmail.com>
@szymonrybczak
Copy link
Collaborator

Hey @ahruss, mind looking why e2e tests are failing?

def readBuffer = new StringBuffer()
while ((buff = bufferedReader.readLine()) != null) {
readBuffer.append(buff)
def execOutput = providers.exec {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI fails with this error on this line:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah - created the PR from the wrong branch, should be fixed with 33fa4a1

@thymikee thymikee merged commit d436bfe into react-native-community:main Jan 15, 2024
10 checks passed
lukmccall added a commit to expo/expo that referenced this pull request Feb 8, 2024
# Why

Uses a cache-friendly method of executing external processes. The Gradle now has a new cache configuration setting which allows skipping the configuration step. However, the old `exec` API doesn't support running during the cacheable configuration phase. To fix this, new functions can be used. You can find more information on this topic here: https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:requirements:external_processes

Just to let you know, this pull request is quite similar to the one that was submitted by the community CLI. You can find the link for it here: react-native-community/cli#2201

PR only affects `bare-expo` projects; I didn't modify our template or Expo Go since I'm still testing different approaches. 

> ⚠️ At the moment, this PR doesn't support enabling the cache configuration. We still have a lot of work to do before we can achieve that goal. However, I was able to turn on the configuration cache by making a few changes and using some hacks. This resulted in a significant improvement in build time, reducing it by around 40%.   

# How

Used new cache-friendly API to run external processes. 

# Test Plan

- bare-expo ✅
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants