mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Delete the buildSrc directory.
Moved all of the stuff we were using it for into build-logic.
This commit is contained in:
committed by
Nicholas Tinsley
parent
873552436a
commit
21deb6803c
@@ -5,4 +5,5 @@ plugins {
|
||||
dependencies {
|
||||
implementation libs.android.library
|
||||
implementation libs.android.application
|
||||
implementation project(':tools')
|
||||
}
|
||||
144
build-logic/plugins/src/main/java/translations.gradle
Normal file
144
build-logic/plugins/src/main/java/translations.gradle
Normal file
@@ -0,0 +1,144 @@
|
||||
import groovy.io.FileType
|
||||
import groovy.transform.stc.ClosureParams
|
||||
import groovy.transform.stc.SimpleType
|
||||
import org.signal.buildtools.StaticIpResolver
|
||||
|
||||
ext {
|
||||
autoResConfig = this.&autoResConfig
|
||||
}
|
||||
|
||||
def allStringsResourceFiles(@ClosureParams(value = SimpleType.class, options = ['java.io.File']) Closure c) {
|
||||
file('src/main/res').eachFileRecurse(FileType.FILES) { f ->
|
||||
if (f.name == 'strings.xml') {
|
||||
c(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discovers supported languages listed as under the res/values- directory.
|
||||
*/
|
||||
def autoResConfig() {
|
||||
def files = []
|
||||
allStringsResourceFiles { f ->
|
||||
files.add(f.parentFile.name)
|
||||
}
|
||||
['en'] + files.collect { f -> f =~ /^values-([a-z]{2,3}(-r[A-Z]{2})?)$/ }
|
||||
.findAll { matcher -> matcher.find() }
|
||||
.collect { matcher -> matcher.group(1) }
|
||||
.sort()
|
||||
}
|
||||
|
||||
task replaceEllipsis {
|
||||
group 'Translate'
|
||||
description 'Process strings for ellipsis characters.'
|
||||
doLast {
|
||||
allStringsResourceFiles { f ->
|
||||
def before = f.text
|
||||
def after = f.text.replace('...', '…')
|
||||
if (before != after) {
|
||||
f.text = after
|
||||
logger.info("$f.parentFile.name/$f.name...updated")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task cleanApostropheErrors {
|
||||
group 'Translate'
|
||||
description 'Fix transifex apostrophe string errors.'
|
||||
doLast {
|
||||
allStringsResourceFiles { f ->
|
||||
def before = f.text
|
||||
def after = before.replaceAll(/([^\\=08])(')/, '$1\\\\\'')
|
||||
if (before != after) {
|
||||
f.text = after
|
||||
logger.info("$f.parentFile.name/$f.name...updated")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task excludeNonTranslatables {
|
||||
group 'Translate'
|
||||
description 'Remove strings that are marked "translatable"="false" or are ExtraTranslations.'
|
||||
doLast {
|
||||
def englishFile = file('src/main/res/values/strings.xml')
|
||||
|
||||
def english = new XmlParser().parse(englishFile)
|
||||
def nonTranslatable = english
|
||||
.findAll { it['@translatable'] == 'false' }
|
||||
.collect { it['@name'] }
|
||||
.toSet()
|
||||
def all = english.collect { it['@name'] }.toSet()
|
||||
def translatable = all - nonTranslatable
|
||||
def inMultiline = false
|
||||
def endBlockName = ""
|
||||
|
||||
allStringsResourceFiles { f ->
|
||||
if (f != englishFile) {
|
||||
def newLines = f.readLines()
|
||||
.collect { line ->
|
||||
if (!inMultiline) {
|
||||
def singleLineMatcher = line =~ /name="([^"]*)".*(<\/|\/>)/
|
||||
if (singleLineMatcher.find()) {
|
||||
def name = singleLineMatcher.group(1)
|
||||
if (!line.contains('excludeNonTranslatables') && !translatable.contains(name)) {
|
||||
return " <!-- Removed by excludeNonTranslatables ${line.trim()} -->"
|
||||
}
|
||||
} else {
|
||||
def multilineStartMatcher = line =~ /<(.*) .?name="([^"]*)".*/
|
||||
if (multilineStartMatcher.find()) {
|
||||
endBlockName = multilineStartMatcher.group(1)
|
||||
def name = multilineStartMatcher.group(2)
|
||||
if (!line.contains('excludeNonTranslatables') && !translatable.contains(name)) {
|
||||
inMultiline = true;
|
||||
return " <!-- Removed by excludeNonTranslatables ${line.trim()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
def multilineEndMatcher = line =~ /<\/${endBlockName}/
|
||||
if (multilineEndMatcher.find()) {
|
||||
inMultiline = false
|
||||
return "${line} -->"
|
||||
}
|
||||
}
|
||||
|
||||
return line
|
||||
}
|
||||
|
||||
f.write(newLines.join("\n") + "\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task postTranslateQa {
|
||||
group 'Translate'
|
||||
description 'Runs QA to check validity of updated strings, and ensure presence of any new languages in internal lists.'
|
||||
dependsOn ':qa'
|
||||
}
|
||||
|
||||
task postTranslateIpFetch {
|
||||
group 'Translate'
|
||||
description 'Fetches static IPs for core hosts and writes them to static-ips.gradle'
|
||||
doLast {
|
||||
new File(projectDir, "static-ips.gradle").text = """
|
||||
ext.service_ips='${StaticIpResolver.resolveToBuildConfig("chat.signal.org")}'
|
||||
ext.storage_ips='${StaticIpResolver.resolveToBuildConfig("storage.signal.org")}'
|
||||
ext.cdn_ips='${StaticIpResolver.resolveToBuildConfig("cdn.signal.org")}'
|
||||
ext.cdn2_ips='${StaticIpResolver.resolveToBuildConfig("cdn2.signal.org")}'
|
||||
ext.cds_ips='${StaticIpResolver.resolveToBuildConfig("api.directory.signal.org")}'
|
||||
ext.kbs_ips='${StaticIpResolver.resolveToBuildConfig("api.backup.signal.org")}'
|
||||
ext.sfu_ips='${StaticIpResolver.resolveToBuildConfig("sfu.voip.signal.org")}'
|
||||
ext.content_proxy_ips='${StaticIpResolver.resolveToBuildConfig("contentproxy.signal.org")}'
|
||||
""".stripIndent().trim()
|
||||
}
|
||||
}
|
||||
|
||||
task translateQa {
|
||||
group 'Translate'
|
||||
description 'Post-process for ellipsis, apostrophes and non-translatables.'
|
||||
dependsOn replaceEllipsis, cleanApostropheErrors, excludeNonTranslatables, postTranslateIpFetch, postTranslateQa
|
||||
}
|
||||
@@ -18,5 +18,6 @@ dependencyResolutionManagement {
|
||||
rootProject.name = "build-logic"
|
||||
|
||||
include ':plugins'
|
||||
include ':tools'
|
||||
|
||||
apply from: '../dependencies.gradle'
|
||||
|
||||
12
build-logic/tools/build.gradle
Normal file
12
build-logic/tools/build.gradle
Normal file
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
id "java-library"
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation libs.dnsjava
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.signal.buildtools;
|
||||
|
||||
import org.xbill.DNS.ARecord;
|
||||
import org.xbill.DNS.Lookup;
|
||||
import org.xbill.DNS.Record;
|
||||
import org.xbill.DNS.Resolver;
|
||||
import org.xbill.DNS.SimpleResolver;
|
||||
import org.xbill.DNS.Type;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class StaticIpResolver {
|
||||
|
||||
private StaticIpResolver() {}
|
||||
|
||||
public static String resolveToBuildConfig(String hostName) {
|
||||
String[] ips = resolve(hostName);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("new String[]{");
|
||||
for (int i = 0; i < ips.length; i++) {
|
||||
builder.append("\"").append(ips[i]).append("\"");
|
||||
if (i < ips.length - 1) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
return builder.append("}").toString();
|
||||
}
|
||||
|
||||
private static String[] resolve(String hostname) {
|
||||
Set<String> ips = new HashSet<>();
|
||||
|
||||
// Run several resolves to mitigate DNS round robin
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ips.addAll(resolveOnce(hostname));
|
||||
}
|
||||
|
||||
return ips.stream().sorted().toArray(String[]::new);
|
||||
}
|
||||
|
||||
private static List<String> resolveOnce(String hostName) {
|
||||
try {
|
||||
Resolver resolver = new SimpleResolver("1.1.1.1");
|
||||
Lookup lookup = doLookup(hostName);
|
||||
|
||||
lookup.setResolver(resolver);
|
||||
|
||||
Record[] records = lookup.run();
|
||||
|
||||
if (records != null) {
|
||||
return Arrays.stream(records)
|
||||
.filter(r -> r.getType() == Type.A)
|
||||
.map(r -> (ARecord) r)
|
||||
.map(ARecord::getAddress)
|
||||
.map(InetAddress::getHostAddress)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
throw new IllegalStateException("Failed to resolve host! " + hostName);
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
throw new IllegalStateException("Failed to resolve host! " + hostName);
|
||||
}
|
||||
}
|
||||
|
||||
private static Lookup doLookup(String hostname) throws UnknownHostException {
|
||||
try {
|
||||
return new Lookup(hostname);
|
||||
} catch (Throwable e) {
|
||||
throw new UnknownHostException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user