From 0571b573ce55a91e786396f57fd7faecd2e077fb Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Wed, 5 Mar 2025 12:07:24 +0530 Subject: [PATCH] fix: use perl script to localize maven --- scripts/localize_maven.pl | 38 ++++++++++++++++++++++++++++++++++++++ scripts/prebuild.sh | 8 ++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 scripts/localize_maven.pl diff --git a/scripts/localize_maven.pl b/scripts/localize_maven.pl new file mode 100755 index 00000000..3b038ff1 --- /dev/null +++ b/scripts/localize_maven.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl +use strict; +use warnings; +use File::Slurp; + +sub localize_maven { + my ($file) = @_; + + die "File does not exist: $file\n" unless -f $file; + die "Not a Gradle file (must end in .gradle or .gradle.kts): $file\n" + unless $file =~ /\.(gradle|gradle\.kts)$/; + + my $content = read_file($file); + my $modified_content = $content; + + $modified_content =~ s{ + (maven\s*\{) # Start of maven block + ((?:[^{}]*|\{[^{}]*\})*?) # Content of the block (non-greedy) + (\}) # Closing brace + }{ + # Check if the block contains plugins.gradle.org + my $block = $1 . $2 . $3; + $block =~ /plugins\.gradle\.org/ ? $block : "mavenLocal()" + }gexs; + + if ($modified_content ne $content) { + # Write the modified content back to the file + open(my $out, '>', $file) or die "Can't open $file: $!"; + print $out $modified_content; + close $out; + + print "Processed file: $file\n"; + } +} + +localize_maven($ARGV[0]) if @ARGV; + +1; diff --git a/scripts/prebuild.sh b/scripts/prebuild.sh index d43eba2c..313c9c4f 100755 --- a/scripts/prebuild.sh +++ b/scripts/prebuild.sh @@ -22,8 +22,8 @@ set -e function localize_maven { # Replace custom Maven repositories with mavenLocal() find ./* -name '*.gradle' -type f -print0 | xargs -0 \ - sed -n -i \ - -e '/maven {/{:loop;N;/}$/!b loop;/plugins.gradle.org/!s/maven .*/mavenLocal()/};p' + perl "$rootdir/scripts/localize_maven.pl" + # Make gradlew scripts call our Gradle wrapper find ./* -name gradlew -type f | while read -r gradlew; do echo -e '#!/bin/sh\ngradle "$@"' >"$gradlew" @@ -116,6 +116,10 @@ rustup target add aarch64-linux-android rustup target add x86_64-linux-android cargo install --vers 0.26.0 cbindgen +## Install perl modules +echo 'Installing File::Slurp perl module...' +sudo perl -MCPAN -e 'install File::Slurp' + # Fenix # shellcheck disable=SC2154 pushd "$fenix"