<< Back to previous view

[CLJS-282] When compiling incrementally, goog dependencies can get out of order (breaks builds) Created: 29/May/12  Updated: 27/Jul/13  Resolved: 19/Nov/12

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Evan Mezeske Assignee: David Nolen
Resolution: Completed Votes: 4
Labels: bug,, namespace

Attachments: Text File cljs_282.patch     Text File dependencies-out-of-order.txt    


In lein-cljsbuild version 0.2.0, I changed it to allow incremental compilation again. Previous versions would always clean out the :output-dir before each call to closure/build, because I had seen weird issues before but never tracked them down.

Finally, I have pinpointed the problem with incremental compilation (although not the solution). The problem is that sometimes, when the compiler notices that a ClojureScript file has already been compiled to JavaScript, its JavaScript output will be inserted into the :whitespace (or higher) optimized output in the wrong order. By "wrong order", I mean its goog.provide() comes after a goog.require() for that same namespace.

I've attached a snippet from my :whitespace compiled output for a closed source project. I removed a bunch of code from the attachment, but I did not change the order of anything. As you can see, ss_charts.crossover.url is provided after it is required.

My guess is that the problem originates in compiler/compile-file. It calls requires-compilation?, and returns a hash containing only {:file ...} if it does not require compilation. I assume that the problem has to do with the fact that this hash lacks the :provides and :requires keys, and thus down the road doesn't get considered in the dependency graph correctly.

Comment by David Nolen [ 29/May/12 11:50 AM ]

Seems like a reasonable guess. Patch welcome.

Comment by Arlen Christian Mart Cuss [ 05/Nov/12 11:29 PM ]

There's a minimalish reproducible example of this here: https://github.com/unnali/cljs-sscce.

Comment by David Nolen [ 18/Nov/12 6:41 PM ]

I'm unable to recreate the issue myself when using the example project. I've created a patch that may fix the issue for others. Can someone please confirm? You can test the patch by making a checkouts directory, clone ClojureScript into it, apply the patch there and then add the following to your project.clj:

:extra-classpath-dirs ["checkouts/clojurescript/src/clj"
Comment by Arlen Christian Mart Cuss [ 18/Nov/12 7:14 PM ]

Unfortunately, this didn't fix the issue for me. I've just realised the cljs-sscce as linked had ":incremental false" set in project.clj, which stops the issue from being reproduced. If you didn't notice that (I didn't until I came to try and found it "working" pre-patch!), it might be worth trying again with that.

If you still can't reproduce it, let me know—I can try preparing a VM image or similar?

Comment by David Nolen [ 18/Nov/12 7:36 PM ]

OK, I was able to reproduce the original issue. I can also confirm that the issue is fixed for me per the instructions on the cljs-sscce repo. I note that it's not really possible to confirm w/ my instructions in the comment above with Lein 2.

Comment by Arlen Christian Mart Cuss [ 18/Nov/12 9:10 PM ]

My testing's with Lein 2, so as David noted the fact that it didn't work for me is no indication that the patch doesn't work!

Comment by David Nolen [ 19/Nov/12 9:44 AM ]

I believe you may be able to confirm the patch by skipping the checkouts bit, just clone clojurescript to some directory in your project and set :extra-classpath-dirs.

Comment by David Nolen [ 19/Nov/12 12:00 PM ]

I checked with Phil Hagelberg, in Lein 2 instead of using :extra-classpath-dirs you need to use :resource-paths and no need to create the checkouts directory.

Comment by David Nolen [ 19/Nov/12 1:37 PM ]

fixed, http://github.com/clojure/clojurescript/commit/a27f811f046cd1ace9e4b9461181e5a5fb23b682

Generated at Sat Jan 20 11:32:35 CST 2018 using JIRA 4.4#649-r158309.