Skip to content

Commit

Permalink
android: build reproducible dir and file lists
Browse files Browse the repository at this point in the history
Sorts dir.list and file.list.
This makes sure the app is reproducible between builds.

PR-URL: #16
Reviewed-By: Jaime Bernardo <jaime@janeasystems.com>
  • Loading branch information
coreyphillips committed May 25, 2020
1 parent b2d3fe9 commit 736900c
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -114,6 +114,8 @@ task GenerateNodeProjectAssetsLists {
delete "${rootProject.buildDir}/nodejs-assets/file.list"
delete "${rootProject.buildDir}/nodejs-assets/dir.list"

ArrayList<String> file_list_arr = new ArrayList<String>();
ArrayList<String> dir_list_arr = new ArrayList<String>();
String file_list = "";
String dir_list = "";

Expand All @@ -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
}
}
Expand Down Expand Up @@ -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/"
}
}

0 comments on commit 736900c

Please sign in to comment.