Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move identifiernamestring to proguard config + enable default #1720

Closed
wants to merge 13 commits into from

Conversation

ZacSweers
Copy link

@ZacSweers ZacSweers commented Jan 13, 2020

This moves the identifiernamestring directly to the shipped proguard configs. R8 is the default now, so this should be safe to enable by default at this point and I've updated the flag to match.

This is important also because the current implementation was not compatible with incremental annotation processing, and would force full rebuilds if stringKeys() was enabled. This was because it did not report originating elements. Since it's also a hardcoded construct and not attached to a particular element, it would have nothing to originate from even if we did want to add them.

Note that this option is not available in standard proguard, so this generates custom proguard rules into resources under the custom layout that AGP supports for configuring different rules for R8 and proguard. The processor solution isn't pretty, but bazel doesn't allow specifying custom jar resources and setting up a throwaway intermediary java package seemed strictly worse than just generating them.

This moves the `identifiernamestring` directly to the shipped proguard config. R8 is the default now, so this should be safe to enable by default at this point and I've updated the flag to match.

This is important also because the current implementation was not compatible with incremental annotation processing, and would force full rebuilds if stringKeys() was enabled. This was because it did not report originating elements. Since it's also a hardcoded construct and not attached to a particular element, it would have nothing to originate from even if we did want to add them.

-identifiernamestring class dagger.android.internal.AndroidInjectionKeys {
java.lang.String of(java.lang.String);
}
Copy link

@ronshapiro ronshapiro Jan 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing newline

@ronshapiro
Copy link

Looks like Bazel is complaining about the Proguard rule, presumably because it doesn't know that it's valid in vanila Proguard

@ZacSweers
Copy link
Author

Yeah we'll need to do the split up files approach for this, which I'm not thrilled about. Bazel's Android rule leaves a lot to be desired for this as well, so I think the actual best solution may honestly be to run an annotation processor over the dagger-android project that generates resource files in the structure AGP expects. Unfortunately doesn't seem like the Android rule exposes a way to declare jar resources like a normal java_library rule does, and dagger's unconventional project structure may prevent that approach regardless because the rule wouldn't be able to infer a path

@ZacSweers
Copy link
Author

The CI failure seems unrelated. Master is also failing

import static java.lang.annotation.RetentionPolicy.SOURCE;

/**
* Our proguard rules generator needs one annotation to hook into for it to run, so we use this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make ProguardProcessor requests all annotations (returning "*" on getSupportedAnnotations()), that way we don't need to make a dummy annotation, since either way we always want to apply this processor.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I always forget that's possible 21b6d6e

@@ -0,0 +1,117 @@
/*
* Copyright (C) 2017 The Dagger Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We on 2020! 🎉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* limitations under the License.
*/

package dagger.android.proguardprocessor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to dagger.android.internal.proguard

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writer.write(proguardRules);
}
} catch (IOException e) {
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new RuntimeException(e) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,45 @@
# Copyright (C) 2017 The Dagger Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We on 2020! 🎉

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 91 to 96
try (Writer writer = filer.createResource(CLASS_OUTPUT,
"",
"META-INF/com.android.tools/proguard/dagger-android.pro")
.openWriter()) {
writer.write(proguardRules);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract to a method that takes the file path and content? So that we don't repeat the same writing maneuver.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZacSweers
Copy link
Author

Confirmation they're being generated

image

cpovirk pushed a commit that referenced this pull request Jan 28, 2020
This moves the `identifiernamestring` directly to the shipped proguard
config. R8 is the default now, so this should be safe to enable by
default at this point but the flag is not yet updated in this change.

This change is important also because the current implementation was not
compatible with incremental annotation processing, and would force full
rebuilds if stringKeys() was enabled. This was because it did not report
originating elements. Since it's also a hardcoded construct and not
attached to a particular element, it would have nothing to originate
from even if we did wanted to add them.

Closes #1720

RELNOTES=Generate 'identifiernamestring' r8 rule by default.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=291056440
@cpovirk cpovirk mentioned this pull request Jan 28, 2020
danysantiago pushed a commit that referenced this pull request Jan 28, 2020
This moves the `identifiernamestring` directly to the shipped proguard
config. R8 is the default now, so this should be safe to enable by
default at this point but the flag is not yet updated in this change.

This change is important also because the current implementation was not
compatible with incremental annotation processing, and would force full
rebuilds if stringKeys() was enabled. This was because it did not report
originating elements. Since it's also a hardcoded construct and not
attached to a particular element, it would have nothing to originate
from even if we did wanted to add them.

Closes #1720

RELNOTES=Generate 'identifiernamestring' r8 rule by default.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=291056440
@ZacSweers ZacSweers deleted the z/androidProguard branch January 29, 2020 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants