Cache Invalidation when BUILD files are changed

107 views
Skip to first unread message

Garrett Malmquist

unread,
May 30, 2014, 5:43:46 PM5/30/14
to pants...@googlegroups.com
I'm working on integrating Jaxb code generation with Pants, which mostly works, but I've noticed an inconvenience regarding the file hashes. If I change the schema (.xsd) file, pants correctly recognizes that there has been a change, and rebuilds the target. 

However, the target takes in a parameter in the BUILD file to change the output package which the generated java files are placed in. Pants doesn't pick up on this change, because it's only checking the hash of the schema file, so it skips the build step on the jaxb_library target. Pants then carries merrily along until it chokes because the dependees can't find the files, because they were never generated.

Specifically, it throws this error:

pants.base.cache_manager.CacheValidationError: Problem validating target .pants.d.gen.jaxb.gen-java.src.resources.com.pants.example.jaxb.jaxb in .pants.d/gen/jaxb/gen-java: [Errno 2] No such file or directory: u'/Users/gmalmquist/Development/pants/.pants.d/gen/jaxb/gen-java/com/pants/example/jaxb/ObjectFactory.java'

Is there an easy way to check for this sort of thing and invalidate the files manually, or do I have to implement some sort of workaround/redesign?

Thanks, 

Garrett


Patrick Lawson

unread,
May 30, 2014, 5:45:37 PM5/30/14
to Garrett Malmquist, pants-devel
Which target takes what parameter?  In general, invalidation is accomplished by asking the target's payload to hash itself.  So the parameter should be plumbed into the payload companion, which should in turn integrate it into its own hash.

Garrett Malmquist

unread,
May 30, 2014, 6:03:48 PM5/30/14
to pants...@googlegroups.com, gmalm...@squareup.com
It's a custom target I'm writing (jaxb_library), with a 'package' parameter. It extends JvmTarget. I suppose I'll override the payload with a new one which incorporates the package information. Is there a good-practice/standard way to do that, avoiding copypasta-ing most of JvmTargetPayload? payload.py appears to be mostly ad-hoc for each target.

Thanks

Patrick Lawson

unread,
May 30, 2014, 6:12:41 PM5/30/14
to Garrett Malmquist, pants-devel
There is no well-established recipe yet, no.  I recommend keeping the companion payload next to the definition of the Target that uses it.  Probably you will just need to do a bit of copy-pasting except in the places where you can use the helpers in payload.py.  If it's a very lightweight extension of JvmTarget, you can likely subclass JvmTarget's Payload and defer to it within your own, capturing package (which I assume is a simple, hashable thing?) in the __init__ and then shuffling it into the result of super().invalidation_hash().

Probably the inheritance structure of Payload needs to be rethought, but so far it's sufficiently lightweight that if we come up with a better way of doing it, it won't be hard to fixup everything else.
Reply all
Reply to author
Forward
0 new messages