Use RepackagingTransform and remove custom ConscryptTransform
Tested by running srcgen/generate_android_src.sh and checking that it
produced the same output as it did before the change.
Bug: 117818301
Test: see above
Change-Id: I8e438dc097a11f908d284924ade4b033451b6ab6
diff --git a/srcgen/Android.bp b/srcgen/Android.bp
deleted file mode 100644
index 79f0c40..0000000
--- a/srcgen/Android.bp
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (C) 2018 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// Build the bouncycastle srcgen jar
-// ============================================================
-
-java_library_host {
- name: "android_conscrypt_srcgen",
- libs: ["currysrc"],
- srcs: ["src/**/*.java"],
-}
diff --git a/srcgen/generate_android_src.sh b/srcgen/generate_android_src.sh
index f854149..a9c1358 100755
--- a/srcgen/generate_android_src.sh
+++ b/srcgen/generate_android_src.sh
@@ -5,11 +5,11 @@
exit 1
fi
-CLASSPATH=${ANDROID_HOST_OUT}/framework/currysrc.jar:${ANDROID_HOST_OUT}/framework/android_conscrypt_srcgen.jar
+CLASSPATH=${ANDROID_HOST_OUT}/framework/currysrc.jar
CONSCRYPT_DIR=${ANDROID_BUILD_TOP}/external/conscrypt
cd ${ANDROID_BUILD_TOP}
-make -j15 currysrc android_conscrypt_srcgen
+make -j15 currysrc
CORE_PLATFORM_API_FILE=${CONSCRYPT_DIR}/srcgen/core-platform-api.txt
INTRA_CORE_API_FILE=${CONSCRYPT_DIR}/srcgen/intra-core-api.txt
@@ -26,12 +26,13 @@
rm -rf ${SRC_OUT_DIR}
mkdir -p ${SRC_OUT_DIR}
- java -cp ${CLASSPATH} com.android.conscrypt.srcgen.ConscryptTransform \
- ${SRC_IN_DIR} \
- ${SRC_OUT_DIR} \
- ${CORE_PLATFORM_API_FILE} \
- ${INTRA_CORE_API_FILE} \
- ${UNSUPPORTED_APP_USAGE_FILE}
+ java -cp ${CLASSPATH} com.google.currysrc.aosp.RepackagingTransform \
+ --source-dir ${SRC_IN_DIR} \
+ --target-dir ${SRC_OUT_DIR} \
+ --package-transformation "org.conscrypt:com.android.org.conscrypt" \
+ --core-platform-api-file ${CORE_PLATFORM_API_FILE} \
+ --intra-core-api-file ${INTRA_CORE_API_FILE} \
+ --unsupported-app-usage-file ${UNSUPPORTED_APP_USAGE_FILE}
}
REPACKAGED_DIR=${CONSCRYPT_DIR}/repackaged
diff --git a/srcgen/src/main/java/com/android/conscrypt/srcgen/ConscryptTransform.java b/srcgen/src/main/java/com/android/conscrypt/srcgen/ConscryptTransform.java
deleted file mode 100644
index 3f2b26d..0000000
--- a/srcgen/src/main/java/com/android/conscrypt/srcgen/ConscryptTransform.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.conscrypt.srcgen;
-
-import static com.google.currysrc.api.process.Rules.createMandatoryRule;
-import static com.google.currysrc.api.process.Rules.createOptionalRule;
-
-import com.google.currysrc.Main;
-import com.google.currysrc.aosp.Annotations;
-import com.google.currysrc.api.RuleSet;
-import com.google.currysrc.api.input.DirectoryInputFileGenerator;
-import com.google.currysrc.api.input.InputFileGenerator;
-import com.google.currysrc.api.output.BasicOutputSourceFileGenerator;
-import com.google.currysrc.api.output.OutputSourceFileGenerator;
-import com.google.currysrc.api.process.Rule;
-import com.google.currysrc.api.process.ast.BodyDeclarationLocators;
-import com.google.currysrc.api.process.ast.TypeLocator;
-import com.google.currysrc.processors.AddMarkerAnnotation;
-import com.google.currysrc.processors.HidePublicClasses;
-import com.google.currysrc.processors.InsertHeader;
-import com.google.currysrc.processors.ModifyQualifiedNames;
-import com.google.currysrc.processors.ModifyStringLiterals;
-import com.google.currysrc.processors.RenamePackage;
-
-import java.io.File;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
-
-/**
- * Generates conscrypt sources in the com.android.org.conscrypt package.
- */
-public class ConscryptTransform {
- static final String ORIGINAL_PACKAGE = "org.conscrypt";
- static final String ANDROID_PACKAGE = "com.android.org.conscrypt";
-
- /**
- * Usage:
- * java ConscryptTransform {source dir} {target dir}
- */
- public static void main(String[] args) throws Exception {
- if (args.length != 5) {
- throw new IllegalArgumentException(
- "Usage: " + ConscryptTransform.class.getCanonicalName() + " <source-dir>"
- + " <target-dir>"
- + " <core-platform-api-file>"
- + " <intra-core-api-file>"
- + " <unsupported-app-usage-file>");
- }
- String sourceDir = args[0];
- String targetDir = args[1];
- Path corePlatformApiFile = Paths.get(args[2]);
- Path intraCoreApiFile = Paths.get(args[3]);
- Path unsupportedAppUsageFile = Paths.get(args[4]);
-
- Map<String, String> options = JavaCore.getOptions();
- options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
- options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
- options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
- options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
- options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
-
- new Main(false /* debug */)
- .setJdtOptions(options)
- .execute(new TransformRules(sourceDir, targetDir, corePlatformApiFile,
- intraCoreApiFile, unsupportedAppUsageFile));
- }
-
- static class TransformRules implements RuleSet {
- private final String sourceDir;
- private final String targetDir;
- private final Path corePlatformApiFile;
- private final Path intraCoreApiFile;
- private final Path unsupportedAppUsageFile;
-
- TransformRules(String sourceDir, String targetDir, Path corePlatformApiFile,
- Path intraCoreApiFile, Path unsupportedAppUsageFile) {
- this.sourceDir = sourceDir;
- this.targetDir = targetDir;
- this.corePlatformApiFile = corePlatformApiFile;
- this.intraCoreApiFile = intraCoreApiFile;
- this.unsupportedAppUsageFile = unsupportedAppUsageFile;
- }
-
- @Override
- public InputFileGenerator getInputFileGenerator() {
- return new DirectoryInputFileGenerator(new File(sourceDir));
- }
-
- @Override
- public List<Rule> getRuleList(File ignored) {
- return Arrays.asList(
- // Doc change: Insert a warning about the source code being generated.
- createMandatoryRule(
- new InsertHeader("/* GENERATED SOURCE. DO NOT MODIFY. */\n")),
- // AST change: Change the package of each CompilationUnit
- createMandatoryRule(new RenamePackage(ORIGINAL_PACKAGE, ANDROID_PACKAGE)),
- // AST change: Change all qualified names in code and javadoc.
- createOptionalRule(new ModifyQualifiedNames(ORIGINAL_PACKAGE, ANDROID_PACKAGE)),
- // AST change: Change all string literals containing package names in code.
- createOptionalRule(new ModifyStringLiterals(ORIGINAL_PACKAGE, ANDROID_PACKAGE)),
- // Doc change: Insert @hide on all public classes.
- createHidePublicClassesRule(),
- // AST change: Add CorePlatformApi to specified classes and members
- createOptionalRule(new AddMarkerAnnotation("libcore.api.CorePlatformApi",
- BodyDeclarationLocators.readBodyDeclarationLocators(
- corePlatformApiFile))),
- // AST change: Add IntraCoreApi to specified classes and members
- createOptionalRule(new AddMarkerAnnotation("libcore.api.IntraCoreApi",
- BodyDeclarationLocators.readBodyDeclarationLocators(intraCoreApiFile))),
- // AST Change: Add UnsupportedAppUsage to specified class members.
- createOptionalRule(
- Annotations.addUnsupportedAppUsage(unsupportedAppUsageFile)));
- }
-
- private static Rule createHidePublicClassesRule() {
- List<TypeLocator> publicApiClassesWhitelist = Collections.emptyList();
- return createOptionalRule(new HidePublicClasses(publicApiClassesWhitelist,
- "This class is not part of the Android public SDK API"));
- }
-
- @Override
- public OutputSourceFileGenerator getOutputSourceFileGenerator() {
- File outputDir = new File(targetDir);
- return new BasicOutputSourceFileGenerator(outputDir);
- }
- }
-
- private ConscryptTransform() {
- }
-}