From 736900c18c0cf69023180fc3964dde09ad35b4e0 Mon Sep 17 00:00:00 2001 From: Corey Date: Mon, 25 May 2020 04:34:51 -0700 Subject: [PATCH] android: build reproducible dir and file lists Sorts dir.list and file.list. This makes sure the app is reproducible between builds. PR-URL: https://github.com/JaneaSystems/nodejs-mobile-react-native/pull/16 Reviewed-By: Jaime Bernardo --- android/build.gradle | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 843e5e1..b6dccc4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -68,20 +68,20 @@ android { abiFilters = project(":app").android.defaultConfig.ndk.abiFilters } } - + externalNativeBuild { cmake { path "CMakeLists.txt" } } - + sourceSets { main { jniLibs.srcDirs 'libnode/bin/' } main.assets.srcDirs += '../install/resources/nodejs-modules' } - + lintOptions { abortOnError false } @@ -114,6 +114,8 @@ task GenerateNodeProjectAssetsLists { delete "${rootProject.buildDir}/nodejs-assets/file.list" delete "${rootProject.buildDir}/nodejs-assets/dir.list" + ArrayList file_list_arr = new ArrayList(); + ArrayList dir_list_arr = new ArrayList(); String file_list = ""; String dir_list = ""; @@ -123,14 +125,26 @@ task GenerateNodeProjectAssetsLists { assets_tree.exclude('**/*~') // Exclude temporary files. assets_tree.visit { assetFile -> if (assetFile.isDirectory()) { - dir_list += "${assetFile.relativePath}\n" + dir_list_arr.add("${assetFile.relativePath}\n"); } else { - file_list += "${assetFile.relativePath}\n" + file_list_arr.add("${assetFile.relativePath}\n"); } } + + //Ensure both files are ordered similarly across builds. + Collections.sort(file_list_arr); + Collections.sort(dir_list_arr); + def file_list_path = new File( "${rootProject.buildDir}/nodejs-assets/file.list") + for (String file : file_list_arr){ + file_list += file; + } file_list_path.write file_list + def dir_list_path = new File( "${rootProject.buildDir}/nodejs-assets/dir.list") + for (String dir : dir_list_arr){ + dir_list += dir; + } dir_list_path.write dir_list } } @@ -433,4 +447,4 @@ if ("1".equals(shouldRebuildNativeModules)) { tasks.getByPath(":${project.name}:preBuild").dependsOn "GenerateNodeNativeAssetsLists${abi_name}" } project.android.sourceSets.main.assets.srcDirs+="${rootProject.buildDir}/nodejs-native-assets/" -} \ No newline at end of file +}