From 3bfee78764ed80c26f5d73edbfb237b48b4a576f Mon Sep 17 00:00:00 2001 From: GrazianoCapelli Date: Sun, 29 Oct 2023 23:28:36 +0100 Subject: [PATCH] #8 - Try the suggested patch for EventBus RB --- app/build.gradle | 33 +++++++++++++++++++++++++++++++++ build.gradle | 17 ++++++++++++++--- scripts/fixEventBus.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 scripts/fixEventBus.py diff --git a/app/build.gradle b/app/build.gradle index 0450bf10..aa1417e0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -67,6 +67,34 @@ android { lint { abortOnError false } + + + // https://codeberg.org/Bazsalanszky/Eternity/commit/05123c70682e5988ad5f0ff111f97b66a87d8806 + // Patch that solves the problem with EventBus and Reproducible Builds + + task rearrangeClass(type: Exec) { + commandLine 'python', '../scripts/fixEventBus.py' + } + + applicationVariants.all { variant -> + if (variant.name == 'release') { + task("compileSingleFile${variant.name.capitalize()}", type: JavaCompile, dependsOn: rearrangeClass) { + def filePath = project.rootDir.absolutePath + '/app/build/generated/ap_generated_sources/release/out/eu/basicairdata/graziano/gpslogger/' + source = files(filePath) + includes = ["**/EventBusIndex.java"] + classpath = variant.getCompileClasspath() + files(project.rootDir.absolutePath + '/app/build/intermediates/javac/release/classes') + destinationDir = file("$buildDir/intermediates/javac/release/classes") + } + + tasks.withType(JavaCompile).all { task -> + if (task.name == 'compileReleaseJavaWithJavac') { + task.finalizedBy "compileSingleFile${variant.name.capitalize()}" + } + } + } + } + + // end patch } dependencies { @@ -85,4 +113,9 @@ dependencies { implementation "org.greenrobot:eventbus:3.3.1" annotationProcessor "org.greenrobot:eventbus-annotation-processor:3.3.1" +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8b01ce07..f8a813f5 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,17 @@ allprojects { } } -task clean(type: Delete) { - delete rootProject.buildDir -} \ No newline at end of file +//task clean(type: Delete) { +// delete rootProject.buildDir +//} + +// https://codeberg.org/Bazsalanszky/Eternity/commit/05123c70682e5988ad5f0ff111f97b66a87d8806 +// Patch that solves the problem with EventBus and Reproducible Builds + +tasks.whenTaskAdded { + if (name.contains("ArtProfile")) { + enabled = false + } +} + +// end patch \ No newline at end of file diff --git a/scripts/fixEventBus.py b/scripts/fixEventBus.py new file mode 100644 index 00000000..d68d6ee8 --- /dev/null +++ b/scripts/fixEventBus.py @@ -0,0 +1,32 @@ +import re +import sys + + +def rearrange(filename): + with open(filename, 'r') as file: + content = file.read() + + # Regex to find the blocks of code to rearrange + pattern = re.compile(r'(putIndex\(new SimpleSubscriberInfo\(.*?\)\);)', re.DOTALL) + blocks = pattern.findall(content) + + # Sort blocks based on the class names mentioned in SimpleSubscriberInfo instances + sorted_blocks = sorted(blocks, key=lambda x: re.search(r'SimpleSubscriberInfo\((.*?),', x).group(1)) + + # Replace the original blocks with the sorted blocks + sorted_content = pattern.sub(lambda match: sorted_blocks.pop(0), content) + + with open(filename, 'w') as file: + file.write(sorted_content) + + +# Project root relative to the script +project_root = __file__[:-len('/scripts/fixEventBus.py')] + +path = './build/generated/ap_generated_sources/release/out/eu/basicairdata/graziano/gpslogger/EventBusIndex.java' + +# Print the path to the file to stderr +print(path, file=sys.stderr) + +# Call the function with the path to EventBusIndex.java +rearrange(path)