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

Proto generation spreading #174

Merged
merged 7 commits into from
Nov 22, 2017
Merged

Proto generation spreading #174

merged 7 commits into from
Nov 22, 2017

Conversation

Gegy
Copy link
Contributor

@Gegy Gegy commented Oct 20, 2017

This PR spreads proto generation over multiple protoc calls when on Windows. Once the command length exceeds the OS limit, it calls with the current arguments and resets the builder.

This is related to #167, allowing this issue to be avoided when many proto files are present, until protocolbuffers/protobuf#274 is completed.

@zhangkun83
Copy link
Collaborator

I understand you are currently experiencing trouble in Windows. I would rather have this issue dealt with in the implementation without adding a new option, given that protocolbuffers/protobuf/issues/274 should be the appropriate fix and this knob will only be temporary. It's easy to add a new option but very difficult to remove one. Can you figure out the actual limit on Windows, and just adapt the command line to it? Something like this:

int cmdLimit = Integer.MAX_INT;
if (isWindows()) {
  cmdLimit = WINDOWS_CMD_LIMIT;
}
// In a loop, construct the command line by adding
// proto file one by one until it reaches cmdLimit, then
// start a new command line, and so on.

@Gegy
Copy link
Contributor Author

Gegy commented Oct 21, 2017

@zhangkun83 Thanks for the feedback. I had considered this, but wasn't sure if it was the right way to go about it.

currentCmd.append(proto.toString()).append(" ")
currentFileCount++
// Offset to account for trailing space
if (currentCmd.length() - 1 > lengthLimit) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This won't prevent currentCmd from exceeding the limit at the beginning of the next iteration, and -1 should be +1.
The condition should be currentCmd.length() + 1 + nextProtoFile.toString().length() > lengthLimit

currentCmd.setLength(baseCmd.length())
}
}
if (currentFileCount > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This only executes the last command. It won't work.


String baseCmd = cmd.join(" ") + " "

StringBuilder currentCmd = new StringBuilder(baseCmd)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a unit test for this logic is necessary. To make this testable, consider defining a static method like this:

List<String> generateCmds(String baseCmd, List<File> protoFiles, int cmdLineLimit)

Copy link
Collaborator

@zhangkun83 zhangkun83 left a comment

Choose a reason for hiding this comment

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

Sorry for the late review. This looks mostly right, except that more tests are needed.


then: "it splits appropriately"
cmds.size() == 2
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also add a case where it doesn't split.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

return cmds
}

private static int getCmdLengthLimit() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also split out the actual handling logic, something like getCmdLengthLimit(os, version), and add a test for it.

List<String> cmds = GenerateProtoTask.generateCmds(baseCmd, protoFiles, cmdLengthLimit)

then: "it splits appropriately"
cmds.size() == 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

One last comment: should be better to assert the actual list content rather than the size.

@zhangkun83 zhangkun83 merged commit 2e50fea into google:master Nov 22, 2017
zhangkun83 pushed a commit to zhangkun83/protobuf-gradle-plugin-1 that referenced this pull request Nov 7, 2018
Spread proto generation over multiple protoc calls on systems that limit command line length, e.g., Windows. Once the command length exceeds the OS limit, it calls with the current arguments and resets the builder.

This is related to google#167, allowing this issue to be avoided when many proto files are present, until protocolbuffers/protobuf#274 is completed.
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.

2 participants