New patcher using sed

This commit is contained in:
DarkCat09 2023-08-03 11:21:36 +04:00
parent 2d6a217083
commit 3b8ca8158e
4 changed files with 42 additions and 73 deletions

View file

@ -1,26 +0,0 @@
diff --git a/build.gradle b/build.gradle
index edfdf66..c7cfa4d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -40,7 +40,7 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp'
implementation 'com.squareup.okhttp3:okhttp-brotli'
implementation 'io.sentry:sentry:6.27.0'
- implementation 'rocks.kavin:reqwest4j:1.0.6'
+ implementation files('libs/reqwest4j.jar')
implementation 'io.minio:minio:8.5.4'
}
diff --git a/src/main/java/me/kavin/piped/Main.java b/src/main/java/me/kavin/piped/Main.java
index a5a8b57..4f9e6ed 100644
--- a/src/main/java/me/kavin/piped/Main.java
+++ b/src/main/java/me/kavin/piped/Main.java
@@ -41,7 +41,7 @@ public class Main {
ReqwestUtils.init(Constants.REQWEST_PROXY);
Sentry.init(options -> {
- options.setDsn(Constants.SENTRY_DSN);
+ options.setDsn("");
options.setRelease(Constants.VERSION);
options.addIgnoredExceptionForType(ErrorResponse.class);
options.setTracesSampleRate(0.1);

View file

@ -1,5 +1,5 @@
#!/usr/bin/env ash
# shellcheck shell=dash
#!/usr/bin/env bash
# shellcheck source=patcher.sh
WORKDIR=$(pwd)
@ -31,6 +31,7 @@ try_exec () {
}
set_piped_version () {
# From GitHub Actions
commit_date=$(git log -1 --date=short --pretty=format:%cd)
commit_sha=$(git rev-parse --short HEAD)
echo "$commit_date-$commit_sha" >VERSION
@ -54,19 +55,9 @@ title 'Cloning repositories...'
[ -e reqwest4j ] || clone https://github.com/TeamPiped/reqwest4j reqwest4j
title 'Applying patches...'
if [ "$1" != "patched" ]
then
title 'Hint:'
echo "if you've already applied patches,"
echo "call this script specifying \"patched\" arg, i.e."
echo "./build.sh patched"
echo
cd_and_exec backend git apply ../backend.patch
cd_and_exec reqwest4j git apply ../reqwest4j.patch
else
echo 'Already applied, skipping'
fi
source patcher.sh
cd_and_exec backend patch_backend
cd_and_exec reqwest4j patch_reqwest4j
# ---
@ -125,7 +116,6 @@ title 'Adding reqwest4j JAR into Piped sources...'
cd_and_exec backend mkdir -p libs
cd_and_exec backend/libs mv "$REQ4J" ./
# From GitHub Actions
title 'Creating VERSION file...'
cd_and_exec backend set_piped_version

36
patcher.sh Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env bash
patch_backend () {
patcher \
build.gradle \
-e "s/implementation 'rocks.kavin:reqwest4j:.*'/implementation files('libs/reqwest4j.jar')/"
patcher \
src/main/java/me/kavin/piped/Main.java \
-e 's/options\.setDsn\(Constants\.SENTRY_DSN\)/options.setDsn("")/'
}
patch_reqwest4j () {
patcher \
build.gradle \
-e '/rust\(project\(":reqwest-jni"\)\)/d'
patcher \
reqwest-jni/build.gradle.kts \
-e 's/command\.set\("cross"\)/command.set("cargo")/' \
-e ' /command\.set\("cargo"\)/a cargoInstallTargets.set(true)' \
-e ' /targets \+= target\(".*-unknown-linux-gnu", "libreqwest\.so"\)/d' \
-e ' /cargoInstallTargets\.set\(true\)/a targets += target("x86_64-unknown-linux-musl", "libreqwest.so")'
}
patcher () {
if grep '//patched' "$1" >/dev/null
then
echo "$1: already patched"
return
fi
file="$1"
shift
sed -i -E "$@" -e '1i //patched' "$file"
}

View file

@ -1,31 +0,0 @@
diff --git a/build.gradle b/build.gradle
index 4a0df70..46e6f0c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -10,10 +10,6 @@ repositories {
mavenCentral()
}
-dependencies {
- rust(project(":reqwest-jni"))
-}
-
// javac -h
tasks.register('generateJniHeaders', JavaCompile) {
classpath = sourceSets.main.compileClasspath
diff --git a/reqwest-jni/build.gradle.kts b/reqwest-jni/build.gradle.kts
index 189a81d..1c22153 100644
--- a/reqwest-jni/build.gradle.kts
+++ b/reqwest-jni/build.gradle.kts
@@ -4,8 +4,8 @@ plugins {
rust {
release.set(true)
- command.set("cross")
+ command.set("cargo")
+ cargoInstallTargets.set(true)
- targets += target("aarch64-unknown-linux-gnu", "libreqwest.so")
- targets += target("x86_64-unknown-linux-gnu", "libreqwest.so")
+ targets += target("x86_64-unknown-linux-musl", "libreqwest.so")
}