Skip to content

Add API to configure which specific thrift files get compiled #367

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

Merged
merged 6 commits into from
Jun 19, 2020

Conversation

benjamin-bader
Copy link
Collaborator

Adds an API to allow configuring include and exclude patterns on sourceDir entries in the Gradle plugin extension.

@jparise please take a look and let me know whether this addresses your use-case. You're welcome to comment on anything here but probably the most interesting thing will be the readme changes which document the new API, and its direct implementation in ThriftyExtension.kt should you be so inclined.

Fixes #365

@codecov-commenter
Copy link

codecov-commenter commented Jun 16, 2020

Codecov Report

Merging #367 into master will decrease coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #367      +/-   ##
============================================
- Coverage     76.75%   76.69%   -0.07%     
  Complexity      381      381              
============================================
  Files            29       29              
  Lines          1665     1665              
  Branches        148      148              
============================================
- Hits           1278     1277       -1     
  Misses          292      292              
- Partials         95       96       +1     
Impacted Files Coverage Δ Complexity Δ
...com/microsoft/thrifty/service/AsyncClientBase.java 61.62% <0.00%> (-1.17%) 7.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1ca5cc...57f2b26. Read the comment docs.

include '**/*.thrift'
exclude '**/*.analytics.thrift'
}

// Augment the thrift include path with one or more directories:
includeDir 'path/to/include/dir', 'path/to/other/dir'
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated, but this should be includePath.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can includeDir receive multiple paths, or would it need to be includeDirs in this example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The rename seems reasonable.

includeDir takes one single path; includeDirs is the varargs version.

@jparise
Copy link
Contributor

jparise commented Jun 17, 2020

I'm try to get this running locally so I can run through it fully, but I could use a little help that may be related to how I'm building/using this branch locally.

I'm able to load the plugin with a little buildscript help, but something as simple as this:

buildscript {
    repositories {
        flatDir { dirs /* paths to locally-built jars */ }
    }
    dependencies {
        classpath 'com.microsoft.thrifty:thrifty-gradle-plugin:2.1.1-SNAPSHOT'
    }
}

apply plugin: 'com.microsoft.thrifty'
apply plugin: 'kotlin'

thrifty {
    kotlin {
        omitFileComments true
    }
}

... barks back at me with an error when I run the generateThriftFiles task:

A problem occurred evaluating project ':modules:schemas'.
> No signature of method: schemas_lfo0wux2ge0pedca69lbazbc.thrifty() is applicable for argument types: (schemas_lfo0wux2ge0pedca69lbazbc$_run_closure1) values: [schemas_lfo0wux2ge0pedca69lbazbc$_run_closure1@707e1a69]
  Possible solutions: notify(), print(java.lang.Object), print(java.io.PrintWriter), print(java.lang.Object)

thrifty { kotlin {} } (which I see through the test suite) "works" because it doesn't have any closures, but that's not too helpful in my case.

Update: This also happens for me with the 2.1.0 binary release, too, so it must be some kind of misconfiguration in my environment unrelated to building this branch locally.

@benjamin-bader
Copy link
Collaborator Author

Yikes, that sure is unfriendly. The error is that omitFileContents isn't a valid option. I'll see if there's a way to make that less cryptic.

@jparise
Copy link
Contributor

jparise commented Jun 17, 2020

Yikes, that sure is unfriendly. The error is that omitFileContents isn't a valid option. I'll see if there's a way to make that less cryptic.

I don't think that's quite it in my case. I run into the same problem when I use a valid option (thanks for spotting my goof!) or something like:

thrifty {
    includePath 'commons/thrift'
    kotlin { }
}

@benjamin-bader
Copy link
Collaborator Author

Again, I'm sorry to say that your example isn't well formed. As you noted, while the option should be includePath it is in fact includeDir.

@jparise
Copy link
Contributor

jparise commented Jun 17, 2020

Ah. And correcting that gets me to an error like this:

> Failed to query the value of task ':modules:schemas:generateThriftFiles' property 'includePath'.
   > Cannot convert the provided notation to an object of type Dependency: /<removed>/modules/schemas/thrift.
     The following types/formats are supported:
       - Instances of Dependency.
       - String or CharSequence values, for example 'org.gradle:gradle-core:1.0'.
       - Maps, for example [group: 'org.gradle', name: 'gradle-core', version: '1.0'].
       - FileCollections, for example files('some.jar', 'someOther.jar').
       - Projects, for example project(':some:project:path').
       - ClassPathNotation, for example gradleApi().

... for includePath 'thrift'. If I pass a non-existent directory name instead, it gives me a error, so it appears to be finding the path just fine.

@benjamin-bader
Copy link
Collaborator Author

That one is clearly down to my misunderstanding of the dependency APIs; will fix.

@jparise
Copy link
Contributor

jparise commented Jun 17, 2020

I'm afraid cfa1483 didn't fix that error for me.

@jparise
Copy link
Contributor

jparise commented Jun 17, 2020

Also, if I use something like:

thrifty {
    sourceDir 'thrift'
}

... I get path must be a directory. If I use a non-existent directory name, I don't receive any error.

And if I try:

thrifty {
    sourceDir('thrift') {
        include 'base.thrift'
    }
}

... I get this unfriendly result:

> No signature of method: schemas_lfo0wux2ge0pedca69lbazbc.thrifty() is applicable for argument types: (schemas_lfo0wux2ge0pedca69lbazbc$_run_closure1) values: [schemas_lfo0wux2ge0pedca69lbazbc$_run_closure1@95e3289]

@benjamin-bader
Copy link
Collaborator Author

There must be something very different between the integration tests and your actual usage, because I can't seem to reproduce most of the issues you're encountering :(

@benjamin-bader
Copy link
Collaborator Author

Thanks for spending so much time with this today. I finally got a repro, but have to confess that I don't quite understand why the error happens.

As with most things in Gradle, the problem goes away when I stop doing things in the officially-recommended way.

@jparise
Copy link
Contributor

jparise commented Jun 18, 2020

I finally found my misconfiguration. In order to load the locally-build jar, I needed to be more explicit in the classpath declaration:

classpath 'com.microsoft.thrifty.gradle.ThriftyGradlePlugin:thrifty-gradle-plugin:2.1.1-SNAPSHOT'

... and now it's loading the code from this branch rather than the plugin jar that shipped with 2.1.0.

Now that sanity has been restored, I can go about testing the new behavior introduced by this change. 😉

@jparise
Copy link
Contributor

jparise commented Jun 18, 2020

Now I'm stuck trying to resolve this (apparently common) ANTLR dependency issue that pops up sometimes in Android projects:

ANTLR Tool version 4.8 used for code generation does not match the current runtime version 4.5.3ANTLR Runtime version 4.8 used for parser compilation does not match the current runtime version 4.5.3

@benjamin-bader
Copy link
Collaborator Author

Lol, wtf. Could it be that you are depending on multiple thrifty versions (one for the plugin, another for the rest of it)?

@jparise
Copy link
Contributor

jparise commented Jun 18, 2020

I think aside from the fact that I can't quite test it in-to-end, the code in this branch should do what I want it to. :)

The one additional thing that would be nice to customize is the output directory. There doesn't appear to be an option for that.

@benjamin-bader
Copy link
Collaborator Author

Can you say more about the output directory? I'm thinking that the files generated here are ephemeral, not to be preserved or checked in. What would configuring the output directory enable for you?

@benjamin-bader benjamin-bader merged commit c0dded3 into microsoft:master Jun 19, 2020
@benjamin-bader benjamin-bader deleted the single-thrift-files branch June 19, 2020 05:44
@jparise
Copy link
Contributor

jparise commented Jun 19, 2020

Can you say more about the output directory? I'm thinking that the files generated here are ephemeral, not to be preserved or checked in. What would configuring the output directory enable for you?

It's not a very important requirement. We currently generate the files in $projectDir/src/main/kotlin and check them into source control (for historic reasons so that every build didn't need to have the thrift binary back in our pre-Thrifty days). We can revisit this, but for the sake of parity, I was going to configure the output path to be the same as it is currently.

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

Successfully merging this pull request may close these issues.

Add sourceFiles to thrifty-gradle-plugin
3 participants