From 65c57d6a013410890319adfae3c5d3f9dfb914fa Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Mon, 16 Jan 2023 11:25:59 -0800 Subject: [PATCH 1/2] Replace "facebook.proguard.annotations" with "facebook.yoga.annotations" (#35841) Summary: X-link: https://github.com/facebook/react-native/pull/35841 X-link: https://github.com/facebook/litho/pull/928 Pull Request resolved: https://github.com/facebook/yoga/pull/1216 The Yoga JNI bindings use Reflection, so we need to let ProGuard know not to strip certain annotated fields. This is done internally using a single copy of `com.facebook.proguard.annotations` from fbandroid (sometimes), which is then repackaged externally, and published as its own whole Yoga specific package. We never actually inform the stock Gradle project of the rules for the annotations though, so apps must add these manually. This simplifies the setup, where Yoga has its own self-contained annotations/rules. The rules are exposed for Gradle/Buck dependencies, but RN and Litho both consume Yoga via dirsync + custom Gradle logic, so we need to duplicate the proguard rules to them instead of them being propagated automatically. Changelog: [Internal] Reviewed By: rshest Differential Revision: D42406641 fbshipit-source-id: c2b12fd498f93f144e5651917ca878d2a5050e08 --- enums.py | 2 +- java/build.gradle | 3 ++- java/com/facebook/yoga/YogaLogLevel.java | 2 +- java/com/facebook/yoga/YogaLogger.java | 2 +- java/com/facebook/yoga/YogaNative.java | 2 +- java/com/facebook/yoga/YogaNodeJNIBase.java | 2 +- .../yoga}/annotations/DoNotStrip.java | 2 +- java/proguard-annotations/build.gradle | 13 ---------- java/proguard-annotations/gradle.properties | 12 ---------- .../proguard/annotations/DoNotStripAny.java | 24 ------------------- java/proguard-rules.pro | 10 ++++++++ settings.gradle | 3 +-- 12 files changed, 19 insertions(+), 58 deletions(-) rename java/{proguard-annotations/src/main/java/com/facebook/proguard => com/facebook/yoga}/annotations/DoNotStrip.java (92%) delete mode 100644 java/proguard-annotations/build.gradle delete mode 100644 java/proguard-annotations/gradle.properties delete mode 100644 java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStripAny.java create mode 100644 java/proguard-rules.pro diff --git a/enums.py b/enums.py index 69dfd7ad..e87f6f79 100644 --- a/enums.py +++ b/enums.py @@ -162,7 +162,7 @@ for name, values in sorted(ENUMS.items()): f.write(get_license("java")) f.write("package com.facebook.yoga;\n\n") if name in DO_NOT_STRIP: - f.write("import com.facebook.proguard.annotations.DoNotStrip;\n\n") + f.write("import com.facebook.yoga.annotations.DoNotStrip;\n\n") f.write("@DoNotStrip\n") f.write("public enum Yoga%s {\n" % name) if len(values) > 0: diff --git a/java/build.gradle b/java/build.gradle index 20584cf4..a0f633c8 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -19,6 +19,8 @@ android { minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.targetSdkVersion + consumerProguardFiles 'proguard-rules.pro' + ndk { abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' } @@ -47,7 +49,6 @@ android { dependencies { implementation 'com.google.code.findbugs:jsr305:3.0.2' - implementation project(':yoga:proguard-annotations') implementation 'com.facebook.soloader:soloader:0.10.4' testImplementation 'junit:junit:4.12' } diff --git a/java/com/facebook/yoga/YogaLogLevel.java b/java/com/facebook/yoga/YogaLogLevel.java index 85076706..761f302e 100644 --- a/java/com/facebook/yoga/YogaLogLevel.java +++ b/java/com/facebook/yoga/YogaLogLevel.java @@ -9,7 +9,7 @@ package com.facebook.yoga; -import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.yoga.annotations.DoNotStrip; @DoNotStrip public enum YogaLogLevel { diff --git a/java/com/facebook/yoga/YogaLogger.java b/java/com/facebook/yoga/YogaLogger.java index 9d439ad3..f40292dd 100644 --- a/java/com/facebook/yoga/YogaLogger.java +++ b/java/com/facebook/yoga/YogaLogger.java @@ -7,7 +7,7 @@ package com.facebook.yoga; -import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.yoga.annotations.DoNotStrip; /** * Interface for receiving logs from native layer. Use by setting YogaNode.setLogger(myLogger); diff --git a/java/com/facebook/yoga/YogaNative.java b/java/com/facebook/yoga/YogaNative.java index f6c53c3b..c0246f60 100644 --- a/java/com/facebook/yoga/YogaNative.java +++ b/java/com/facebook/yoga/YogaNative.java @@ -7,7 +7,7 @@ package com.facebook.yoga; -import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.yoga.annotations.DoNotStrip; import com.facebook.soloader.SoLoader; @DoNotStrip diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index 85aebb3f..fd44cc0f 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -7,7 +7,7 @@ package com.facebook.yoga; -import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.yoga.annotations.DoNotStrip; import java.util.ArrayList; import java.util.List; import javax.annotation.Nullable; diff --git a/java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStrip.java b/java/com/facebook/yoga/annotations/DoNotStrip.java similarity index 92% rename from java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStrip.java rename to java/com/facebook/yoga/annotations/DoNotStrip.java index d8d4c7ba..574d3562 100644 --- a/java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStrip.java +++ b/java/com/facebook/yoga/annotations/DoNotStrip.java @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.proguard.annotations; +package com.facebook.yoga.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/java/proguard-annotations/build.gradle b/java/proguard-annotations/build.gradle deleted file mode 100644 index 2b287fa2..00000000 --- a/java/proguard-annotations/build.gradle +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -apply plugin: 'java' - -sourceCompatibility = '1.7' -targetCompatibility = '1.7' - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/java/proguard-annotations/gradle.properties b/java/proguard-annotations/gradle.properties deleted file mode 100644 index 4c53dbee..00000000 --- a/java/proguard-annotations/gradle.properties +++ /dev/null @@ -1,12 +0,0 @@ -# -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the LICENSE -# file in the root directory of this source tree. -# - -GROUP=com.facebook.yoga -POM_NAME=Proguard Annotations -POM_DESCRIPTION=Shared annotations for use with Proguard -POM_ARTIFACT_ID=proguard-annotations -POM_PACKAGING=jar diff --git a/java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStripAny.java b/java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStripAny.java deleted file mode 100644 index 7c04b61f..00000000 --- a/java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStripAny.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.proguard.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.RetentionPolicy.CLASS; - -/** - * Add this annotation to a class to instruct Proguard to not strip it or any of its fields or - * methods out. - * - *

This is useful for methods called via reflection that could appear as unused to Proguard. - */ -@Target({ElementType.TYPE}) -@Retention(CLASS) -public @interface DoNotStripAny {} diff --git a/java/proguard-rules.pro b/java/proguard-rules.pro new file mode 100644 index 00000000..afb1f615 --- /dev/null +++ b/java/proguard-rules.pro @@ -0,0 +1,10 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +-keep,allowobfuscation @interface com.facebook.yoga.annotations.DoNotStrip +-keep @com.facebook.yoga.annotations.DoNotStrip class * +-keepclassmembers class * { + @com.facebook.yoga.annotations.DoNotStrip *; +} diff --git a/settings.gradle b/settings.gradle index cc035683..7fedecea 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -include ':yoga', ':yoga-layout', ':yoga:proguard-annotations' +include ':yoga', ':yoga-layout' project(':yoga').projectDir = file('java') -project(':yoga:proguard-annotations').projectDir = file('java/proguard-annotations') project(':yoga-layout').projectDir = file('android') From cac197f5a6332990dedf1401b45fdc7d62f88ce4 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Mon, 16 Jan 2023 13:06:45 -0800 Subject: [PATCH 2/2] Colorize GTest Output in GitHub Actions (#1218) Summary: GitHub actions supports terminal colors, but most programs won't output color to a non-interactive terminal. We can control this via env variable, so that GTest output in GitHub actions is colorized. Before: {F847577544} After: {F847577610} Pull Request resolved: https://github.com/facebook/yoga/pull/1218 Reviewed By: christophpurrer Differential Revision: D42537630 Pulled By: NickGerleman fbshipit-source-id: 28b22c061200026bf167c1a31d6a58445ba70214 --- .github/workflows/validate-cpp.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/validate-cpp.yml b/.github/workflows/validate-cpp.yml index 2db9991a..6d83c390 100644 --- a/.github/workflows/validate-cpp.yml +++ b/.github/workflows/validate-cpp.yml @@ -7,6 +7,9 @@ on: - main workflow_dispatch: +env: + GTEST_COLOR: 1 + jobs: test: name: Build and Test [${{ matrix.os }}][${{ matrix.mode }}]