Skip to content

Commit

Permalink
android: use gradle tasks inputs and output
Browse files Browse the repository at this point in the history
Defines the native modules tasks inputs and outputs so that native
modules are only rebuilt if the nodejs-project has changed. Also
avoids rebuilding the NDK standalone toolchain if it's already
there.
  • Loading branch information
jaimecbernardo committed Feb 26, 2018
1 parent 534114b commit ff19463
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ if (shouldRebuildNativeModules==null) {

if ("1".equals(shouldRebuildNativeModules)) {

task CleanNPMTempBuildDir (type: Delete) {
delete "${rootProject.buildDir}/nodejs-native-assets-temp-build/"
}

android.defaultConfig.ndk.abiFilters.each { abi_name ->
String temp_arch = {
switch (abi_name) {
Expand Down Expand Up @@ -137,22 +133,39 @@ if ("1".equals(shouldRebuildNativeModules)) {
throw new GradleException("Unsupported opperating system for nodejs-mobile native builds: ${OperatingSystem.current().getName()}")
}

task "CopyNodeProjectAssets${abi_name}" (type:Copy) {
dependsOn "CleanNPMTempBuildDir"
task "CopyNodeProjectAssets${abi_name}" {
description = "Copying node assets to build native modules for ${abi_name}."
from "${project.projectDir}/assets/www/nodejs-project/"
into "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/nodejs-project/"
inputs.files fileTree (
dir: "${project.projectDir}/assets/www/nodejs-project/"
).exclude({
details -> // We shouldn't need to rebuild native code if there are only changes in the Node.js project javascript files.
!details.isDirectory() &&
details.getPath().endsWith('.js') &&
!details.getPath().startsWith('node_modules/')
})
outputs.file "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/copy.timestamp"
doLast {
delete "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/"
copy {
from "${project.projectDir}/assets/www/nodejs-project/"
into "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/nodejs-project/"
}
new File("${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/copy.timestamp").text = "${new Date().format('yyyy-MM-dd HH:mm:ss')}"
}
}

task "MakeToolchain${abi_name}" (type:Exec) {
dependsOn "CopyNodeProjectAssets${abi_name}"
description = "Building a native toolchain to compile nodejs-mobile native modules for ${abi_name}."
executable = "${ndk_bundle_path}/build/tools/make-standalone-toolchain.sh"
args "--toolchain=${temp_toolchain_name}-${temp_cc_ver}", "--arch=${temp_arch}", "--install-dir=${standalone_toolchain}", "--stl=libc++", "--force", "--platform=android-22"
outputs.file "${standalone_toolchain}"
}

task "BuildNpmModules${abi_name}" (type:Exec) {
dependsOn "MakeToolchain${abi_name}"
dependsOn "CopyNodeProjectAssets${abi_name}"
inputs.file "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/copy.timestamp"
outputs.file "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/nodejs-project/"
description = "Building native modules for ${abi_name}."
workingDir "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/nodejs-project/"
commandLine 'npm', '--verbose', 'rebuild', '--build-from-source'
Expand All @@ -170,12 +183,9 @@ if ("1".equals(shouldRebuildNativeModules)) {
environment ('LINK',"${npm_toolchain_link}")
environment ('GYP_DEFINES',"${npm_gyp_defines}")
}
task "CleanFinalNpmAssets${abi_name}" (type: Delete) {
delete "${rootProject.buildDir}/nodejs-native-assets/nodejs-native-assets-${abi_name}/"
}
task "CopyBuiltNpmAssets${abi_name}" (type:Copy) {

task "CopyBuiltNpmAssets${abi_name}" (type:Sync) {
dependsOn "BuildNpmModules${abi_name}"
dependsOn "CleanFinalNpmAssets${abi_name}"
description = "Copying node assets with build native modules for ${abi_name}."
from "${rootProject.buildDir}/nodejs-native-assets-temp-build/nodejs-native-assets-${abi_name}/nodejs-project/"
into "${rootProject.buildDir}/nodejs-native-assets/nodejs-native-assets-${abi_name}/"
Expand All @@ -186,7 +196,12 @@ if ("1".equals(shouldRebuildNativeModules)) {
task "GenerateNodeNativeAssetsLists${abi_name}" {
dependsOn "CopyBuiltNpmAssets${abi_name}"
description "Generates a list for runtime copying"
inputs.file "${rootProject.buildDir}/nodejs-native-assets/nodejs-native-assets-${abi_name}/"
outputs.file "${rootProject.buildDir}/nodejs-native-assets/nodejs-native-assets-${abi_name}/file.list"
outputs.file "${rootProject.buildDir}/nodejs-native-assets/nodejs-native-assets-${abi_name}/dir.list"
doLast{
delete "${rootProject.buildDir}/nodejs-native-assets/nodejs-native-assets-${abi_name}/file.list"
delete "${rootProject.buildDir}/nodejs-native-assets/nodejs-native-assets-${abi_name}/dir.list"
String file_list = "";
String dir_list = "";

Expand Down

0 comments on commit ff19463

Please sign in to comment.