Skip to content

Commit 736900c

Browse files
android: build reproducible dir and file lists
Sorts dir.list and file.list. This makes sure the app is reproducible between builds. PR-URL: JaneaSystems/nodejs-mobile-react-native#16 Reviewed-By: Jaime Bernardo <[email protected]>
1 parent b2d3fe9 commit 736900c

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

android/build.gradle

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ android {
6868
abiFilters = project(":app").android.defaultConfig.ndk.abiFilters
6969
}
7070
}
71-
71+
7272
externalNativeBuild {
7373
cmake {
7474
path "CMakeLists.txt"
7575
}
7676
}
77-
77+
7878
sourceSets {
7979
main {
8080
jniLibs.srcDirs 'libnode/bin/'
8181
}
8282
main.assets.srcDirs += '../install/resources/nodejs-modules'
8383
}
84-
84+
8585
lintOptions {
8686
abortOnError false
8787
}
@@ -114,6 +114,8 @@ task GenerateNodeProjectAssetsLists {
114114
delete "${rootProject.buildDir}/nodejs-assets/file.list"
115115
delete "${rootProject.buildDir}/nodejs-assets/dir.list"
116116

117+
ArrayList<String> file_list_arr = new ArrayList<String>();
118+
ArrayList<String> dir_list_arr = new ArrayList<String>();
117119
String file_list = "";
118120
String dir_list = "";
119121

@@ -123,14 +125,26 @@ task GenerateNodeProjectAssetsLists {
123125
assets_tree.exclude('**/*~') // Exclude temporary files.
124126
assets_tree.visit { assetFile ->
125127
if (assetFile.isDirectory()) {
126-
dir_list += "${assetFile.relativePath}\n"
128+
dir_list_arr.add("${assetFile.relativePath}\n");
127129
} else {
128-
file_list += "${assetFile.relativePath}\n"
130+
file_list_arr.add("${assetFile.relativePath}\n");
129131
}
130132
}
133+
134+
//Ensure both files are ordered similarly across builds.
135+
Collections.sort(file_list_arr);
136+
Collections.sort(dir_list_arr);
137+
131138
def file_list_path = new File( "${rootProject.buildDir}/nodejs-assets/file.list")
139+
for (String file : file_list_arr){
140+
file_list += file;
141+
}
132142
file_list_path.write file_list
143+
133144
def dir_list_path = new File( "${rootProject.buildDir}/nodejs-assets/dir.list")
145+
for (String dir : dir_list_arr){
146+
dir_list += dir;
147+
}
134148
dir_list_path.write dir_list
135149
}
136150
}
@@ -433,4 +447,4 @@ if ("1".equals(shouldRebuildNativeModules)) {
433447
tasks.getByPath(":${project.name}:preBuild").dependsOn "GenerateNodeNativeAssetsLists${abi_name}"
434448
}
435449
project.android.sourceSets.main.assets.srcDirs+="${rootProject.buildDir}/nodejs-native-assets/"
436-
}
450+
}

0 commit comments

Comments
 (0)