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

Support ABI exclusions #158

Merged
merged 2 commits into from
May 15, 2020
Merged

Support ABI exclusions #158

merged 2 commits into from
May 15, 2020

Conversation

ZacSweers
Copy link
Sponsor Contributor

This is intended to resolve #48 by adding a new API to extensions for abi handling and exclusions configuration.

The API in practice looks like this:

abi {
  exclusions {
    // Convenience helpers
    ignoreSubPackage("internal")
    ignoreInternalPackages()
    ignoreGeneratedCode()

    // Raw, regexp-based APIs
    excludeAnnotations(".*\\.Generated")
    excludeClasses(".*\\.internal\\..*")
  }
}

I've left toe-holds in for directory based parsing (i.e. build/), but that will take more work as the current code looks only at class files and not where they originated from.

No tests yet as I want to put this up for review of the design before moving further.

@autonomousapps autonomousapps self-requested a review May 11, 2020 06:14
Copy link
Owner

@autonomousapps autonomousapps left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! I have no fundamental problems with this, although I did leave a few small comments.

The biggest thing this PR needs is a functional test verifying the new behavior. I can provide pointers to get you started more quickly if you want to tackle that.

src/main/kotlin/com/autonomousapps/internal/models.kt Outdated Show resolved Hide resolved
@@ -25,6 +25,10 @@ internal inline fun <T, R> Iterable<T>.mapToSet(transform: (T) -> R): HashSet<R>
return mapTo(HashSet(collectionSizeOrDefault(10)), transform)
}

internal inline fun <T, R> Iterable<T>.mapToLinkedHashSet(transform: (T) -> R): HashSet<R> {
Copy link
Owner

Choose a reason for hiding this comment

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

Do you think we should change the pre-existing maptToSet() function to use a LinkedHashSet instead of adding a new method? Or, why do you prefer a linked hash set specifically here?

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

I'd be down for that, as that would match kotlin's conventional behavior as well (toSet() guarantees preserved order)

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

a3c0509

@ZacSweers
Copy link
Sponsor Contributor Author

Addressed the inline comments, going to work on adding a test(s) now

@ZacSweers
Copy link
Sponsor Contributor Author

I wrote a pretty good unit test for the ABI checking. I can still write a functional test, but at this point it would be just to verify gradle plumbing rather than functionally correct exclusion behavior. Can take a crack if you think it's worth it, let me know

@ZacSweers ZacSweers changed the title Begin ABI exclusions implementation Support ABI exclusions May 13, 2020
@autonomousapps autonomousapps added the enhancement New feature or request label May 13, 2020
@autonomousapps autonomousapps added this to the 1.0 milestone May 13, 2020
Copy link
Owner

@autonomousapps autonomousapps left a comment

Choose a reason for hiding this comment

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

very nice! Love that new unit test. TIL. I'll give this a try locally and hopefully we can merge soon.

@autonomousapps
Copy link
Owner

I want to talk a bit about the impact this has on generated advice.

Without setting any exclusions and running buildHealth on a personal project, I will see this in the abi-dump.txt file:

public abstract interface class com/seattleshelter/core/api/PetsService {
	public abstract fun getCatById (J)Lio/reactivex/Single;
	public abstract fun getCatsList ()Lio/reactivex/Single;
        ...etc...
}

and furthermore, the advice for this project suggests adding RxJava as an api dependency (as we would expect).

If I add the following:

abi {
  exclusions {
    excludeClasses("com\\.seattleshelter\\.core\\.api\\.PetsService")
  }
}

then abi dump does not contain that interface any longer, and the advice no longer suggests adding RxJava2 as an api dependency, since it's no longer part of the published api, as it was only used by the now-excluded class.

Is this what you expected? If not, could you be precise with what your goal is?

One interesting thing about this is that this plugin deals primarily in resolved dependencies. This new DSL operates at a different level (that of classes), which has an indirect impact on the dependency advice.

@ZacSweers
Copy link
Sponsor Contributor Author

Right, in this case that's expected. The idea is that you can limit exposed APIs for things that are either optional or public-only-becuse-tey-have-to-be

Copy link
Owner

@autonomousapps autonomousapps left a comment

Choose a reason for hiding this comment

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

LGTM. Will merge when CI passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't recommend adding direct dependencies if they're only used by generated code?
2 participants