-
Notifications
You must be signed in to change notification settings - Fork 275
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
Add support for protoc --xxx_opt flag #290
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import com.google.common.base.Preconditions | |
import org.apache.commons.lang.StringUtils | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Dependency | ||
import org.gradle.api.tasks.SourceSet | ||
import org.gradle.api.tasks.TaskInputs | ||
import org.gradle.plugins.ide.idea.GenerateIdeaModule | ||
|
@@ -104,7 +105,32 @@ class Utils { | |
* given target version. Only major and minor versions are checked. Patch version is ignored. | ||
*/ | ||
static int compareGradleVersion(Project project, String target) { | ||
Matcher gv = parseVersionString(project.gradle.gradleVersion) | ||
return compareVersions(project.gradle.gradleVersion, target) | ||
} | ||
|
||
/** | ||
* Returns positive/0/negative if current Protoc version is higher than/equal to/lower than the | ||
* given target version. Only major and minor versions are checked. Patch version is ignored. | ||
*/ | ||
static int compareProtocVersion(Project project, String target) { | ||
String protocVersion = null | ||
Dependency protocDep = project.configurations | ||
.findByName("protobufToolsLocator_protoc").getAllDependencies()[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im not happy about it but it seems that this was the only dependable way to get the current protoc compiler version configured. The artifact property of the protoc executable locator is overridden once the path is resolved. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The protoc may be from local path and you won't get the version from configurations at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that idea a lot better |
||
if(protocDep != null){ | ||
protocVersion = protocDep.version | ||
} | ||
if(protocVersion == null || protocVersion == ""){ | ||
return -1 | ||
} | ||
return compareVersions(protocVersion, target) | ||
} | ||
|
||
/** | ||
* Returns positive/0/negative if current version is higher than/equal to/lower than the | ||
* given target version. Only major and minor versions are checked. Patch version is ignored. | ||
*/ | ||
private static int compareVersions(String current, String target) { | ||
Matcher gv = parseVersionString(current) | ||
Matcher tv = parseVersionString(target) | ||
int majorVersionDiff = gv.group(1).toInteger() - tv.group(1).toInteger() | ||
if (majorVersionDiff != 0) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability, I would change
makeOptionsPrefix()
toassembleOptions()
, which would leave out the trailing colon, then add the colon in theelse
branch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to do that. That was my initial approach but I back tracked a bit. I was reluctant to introduce too many changes with out initial feedback.