Skip to content

Commit d436bfe

Browse files
ahrussthymikeecortinico
authoredJan 15, 2024
build: support Gradle configuration cache (#2201)
* build: support configuration caching in cli-platform-android 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. * Update packages/cli-platform-android/native_modules.gradle Co-authored-by: Nicola Corti <corti.nico@gmail.com> * fix: pass providers into ReactNativeModules --------- Co-authored-by: Michał Pierzchała <thymikee@gmail.com> Co-authored-by: Nicola Corti <corti.nico@gmail.com>
1 parent dec46c3 commit d436bfe

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed
 

‎packages/cli-platform-android/native_modules.gradle

+11-18
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void rncli_registerProviders(std::shared_ptr<ComponentDescriptorProviderRegistry
138138

139139
class ReactNativeModules {
140140
private Logger logger
141+
private ProviderFactory providers
141142
private String packageName
142143
private File root
143144
private ArrayList<HashMap<String, String>> reactNativeModules
@@ -147,8 +148,9 @@ class ReactNativeModules {
147148

148149
private static String LOG_PREFIX = ":ReactNative:"
149150

150-
ReactNativeModules(Logger logger, File root) {
151+
ReactNativeModules(Logger logger, ProviderFactory providers, File root) {
151152
this.logger = logger
153+
this.providers = providers
152154
this.root = root
153155

154156
def (nativeModules, reactNativeModulesBuildVariants, androidProject, reactNativeVersion) = this.getReactNativeConfig()
@@ -366,29 +368,20 @@ class ReactNativeModules {
366368
}
367369

368370
/**
369-
* Runs a specified command using Runtime exec() in a specified directory.
371+
* Runs a specified command using providers.exec in a specified directory.
370372
* Throws when the command result is empty.
371373
*/
372374
String getCommandOutput(String[] command, File directory) {
373375
try {
374-
def output = ""
375-
def cmdProcess = Runtime.getRuntime().exec(command, null, directory)
376-
def bufferedReader = new BufferedReader(new InputStreamReader(cmdProcess.getInputStream()))
377-
def buff = ""
378-
def readBuffer = new StringBuffer()
379-
while ((buff = bufferedReader.readLine()) != null) {
380-
readBuffer.append(buff)
376+
def execOutput = providers.exec {
377+
commandLine(command)
378+
workingDir(directory)
381379
}
382-
output = readBuffer.toString()
380+
def output = execOutput.standardOutput.asText.get().trim()
383381
if (!output) {
384382
this.logger.error("${LOG_PREFIX}Unexpected empty result of running '${command}' command.")
385-
def bufferedErrorReader = new BufferedReader(new InputStreamReader(cmdProcess.getErrorStream()))
386-
def errBuff = ""
387-
def readErrorBuffer = new StringBuffer()
388-
while ((errBuff = bufferedErrorReader.readLine()) != null) {
389-
readErrorBuffer.append(errBuff)
390-
}
391-
throw new Exception(readErrorBuffer.toString())
383+
def error = execOutput.standardError.asText.get().trim()
384+
throw new Exception(error)
392385
}
393386
return output
394387
} catch (Exception exception) {
@@ -486,7 +479,7 @@ class ReactNativeModules {
486479
*/
487480
def projectRoot = rootProject.projectDir
488481

489-
def autoModules = new ReactNativeModules(logger, projectRoot)
482+
def autoModules = new ReactNativeModules(logger, providers, projectRoot)
490483

491484
def reactNativeVersionRequireNewArchEnabled(autoModules) {
492485
def rnVersion = autoModules.reactNativeVersion

0 commit comments

Comments
 (0)
Please sign in to comment.