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

Arbitrary arg length #574

Merged
merged 1 commit into from
Jan 6, 2016

Conversation

himamis
Copy link
Contributor

@himamis himamis commented Jan 4, 2016

This pull request fixes issue #572 .
A long term fix has been implemented, using a temporary file.
The test have also been modified to accommodate for the changes in the command line of the TranslateTask.

@@ -61,7 +61,7 @@ class TranslateTaskTest {
'-d', '/PROJECT_DIR/build/j2objcSrcGenMain',
'-sourcepath', '/PROJECT_DIR/src/main/java:/PROJECT_DIR/build/classes/main',
'-classpath', '/J2OBJC_HOME/lib/j2objc_annotations.jar:/J2OBJC_HOME/lib/j2objc_guava.jar:/J2OBJC_HOME/lib/j2objc_junit.jar:/J2OBJC_HOME/lib/jre_emul.jar:/J2OBJC_HOME/lib/javax.inject-1.jar:/J2OBJC_HOME/lib/jsr305-3.0.0.jar:/J2OBJC_HOME/lib/mockito-core-1.9.5.jar:/J2OBJC_HOME/lib/hamcrest-core-1.3.jar:/J2OBJC_HOME/lib/protobuf_runtime.jar:/PROJECT_DIR/build/classes',
'/PROJECT_DIR/src/main/java/com/example/Main.java'
'@/PROJECT_DIR/build/tmp/j2objcTranslate/inputFiles'
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you see how this loses something in the validation? Previously, it would check for Main.java but now that no-longer happens. Be very careful that you're not regressing the test. Please make two changes:

  1. For short command lines, no temporary file should be used - so revert this test to what it was before. That preserves the existing behaviour and avoid the complexity and risk of the temporary file.

  2. Add a specific test for the long command line. That'll need a normal test as usual with the @/PROJECT_DIR/build/tmp/j2objcTranslate/inputFiles, then an additional test that reads inputFiles and verifies the contents.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make the changes. I also have a question:

  1. What do you think, what should consist of a long command line? I thought having a an argument list with a length greater than 250000 is what should be called long (as noted before, for Mac OS X this is 262144). We could also tighten this number and make it around 100000.

@brunobowden
Copy link
Contributor

@himamis - this should be enough feedback for you to fix this up. Thanks for working on this. Ping me when you've worked through this. There's a couple of other things for you to do:

  1. Collapse the commits to a single commit - the contributor guide has notes on this
  2. Make sure it passes on all the CI builds on each different platform
  3. Add a note in the comment indicating how long the test takes to run (you can see it in the test output). If it's over a second then we should understand that and see if we can make it faster. I believe it should be pretty quick though.

@himamis
Copy link
Contributor Author

himamis commented Jan 5, 2016

@brunobowden please let me know if the changes are passable, then I'll prepare the pull request for submission.

final File file ->
// Create the files
file.write("// Fake")
Copy link
Contributor

Choose a reason for hiding this comment

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

Take this line out.

The file never needs to be written to disk in order for the test to work. In fact, writing a large number of files will slow down the test dramatically without adding anything to the quality of the testing. An important part of unit tests is that they should avoid anything like writing or reading to a file. In this case, just passing a list of "changed files" is enough for this test to verify the translate task.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I see the code that you moved here that was writing the file in another place. Can you check if it needs to write the file at all? I will test this myself also.

@himamis
Copy link
Contributor Author

himamis commented Jan 6, 2016

On Windows the test fails, if the files are not there:

junit.framework.AssertionFailedError: No call to 'delete' expected at this point. Still 1 call(s) to 'exec' expected.

Good news is that with Windows 240 files are enough, and with that the test is under 1 second on my machine.

@@ -189,18 +187,87 @@ class TranslateTaskTest {
mockProjectExec.verify()
}

@Test
// This test takes 8 seconds on average on a local dev computer
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this comment

@brunobowden
Copy link
Contributor

@himamis - looks like the PR is close to complete. I see the same issue as you that it fails without any files. I put in a comment about trying it with just a main and test file. See if that works.

proj.file('src/test/java/com/example').mkdirs()
proj.file('src/test/java/com/example/Verify.java').write("// Fake")
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment:

// File in this folder are created by 'genNonIncrementalInputs' method

@himamis
Copy link
Contributor Author

himamis commented Jan 6, 2016

Sorry, my comment was not clear enough. Without any files, all of the translate tests fail, with just Main1 and Verify1 only the translate_MaxArgsExceeded test fails.

@brunobowden
Copy link
Contributor

Fair enough. In which case, leave it as setFakeOSWindows and creating all
the files. Then add a comment, in the genNonIncrementalInputs method that:

// TODO: prefer not to create all these temporary files just to run the

test

On Tue, Jan 5, 2016 at 11:12 PM Bencze Balázs [email protected]
wrote:

Sorry, my comment was not clear enough. Without any files, all of the
translate tests fail, with just Main1 and Verify1 only the
translate_MaxArgsExceeded test fails.


Reply to this email directly or view it on GitHub
#574 (comment)
.

@himamis
Copy link
Contributor Author

himamis commented Jan 6, 2016

@brunobowden The commits have been squashed into a single commit. Please let me know, if there is anything else I need to do.

@@ -252,7 +252,7 @@ class TranslateTask extends DefaultTask {
project.files(getTranslateSourcepaths()),
project.files(getGeneratedSourceDirs())
])
doTranslate(sourcepathDirs, srcGenMainDir, translateArgs, mainSrcFilesChanged)
doTranslate(sourcepathDirs, srcGenMainDir, translateArgs, mainSrcFilesChanged, "mainSrcFilesArgsFile")
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace "argsFile" with "argFile" to match the naming in the Java documentation. There's 13 instances of this.

Apologies I didn't catch this earlier:
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#commandlineargfile

@brunobowden
Copy link
Contributor

Two minor nits and then we're done. Ping me once you've fixed them. I'll merge this in once all the CI builds pass. Thanks for your patience @himamis.

current OS
Update TranslateTask, so that when the command line is too large, the file
arguments are written into a temporary file, and they are fed to the
j2objc command
Add a new test case to test if the new files are created and they contain
the correct arguments
Add a new test case to test the Util method maxArgs()
@himamis
Copy link
Contributor Author

himamis commented Jan 6, 2016

@brunobowden The argsFile have been replaced with argFile. If there is anything else, let me know. Thank you in helping fixing this!

@brunobowden
Copy link
Contributor

You're welcome, thank you too. I'll merge this in once the CI builds pass.

One last thing... Have you tested this to see if it makes your own build work now? The docs describe how you can test a locally built plugin for that build which was failing before:

https://github.com/j2objc-contrib/j2objc-gradle/blob/master/CONTRIBUTING.md#testing-on-your-own-gradle-project

Confirming that it works would make sure that this is going to solve your problem. I wanted to avoid the situation of releasing a new plugin version and then you find it doesn't solve your problem.

@himamis
Copy link
Contributor Author

himamis commented Jan 6, 2016

I've tested it, and I can confirm that with my project it works.

@brunobowden
Copy link
Contributor

That's great @himamis. I'll merge this in the morning and then push a new public version for your delectation.

@himamis
Copy link
Contributor Author

himamis commented Jan 6, 2016

Thank you @brunobowden. It was fun working on this project! 😄

brunobowden added a commit that referenced this pull request Jan 6, 2016
@brunobowden brunobowden merged commit 4646490 into j2objc-contrib:master Jan 6, 2016
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