On Wednesday, February 13, 2019 at 7:46:43 PM UTC-6, Didier wrote:
>
> Hey all,
>
> I've been working on internal build tools where I work, and when looking 
> into how other build tools like lein do their aot :all compilation, it 
> seems that they all rely on some brittle namespace finder library, which 
> searches either the classpath, or a folder of files and tries to identity 
> all the ns declarations.
>

Or you use a hard-coded list (like the Clojure build itself).
 

> From that, they call compile in a loop for every namespace they found. 
> But, compile just goes ahead and converts the namespace into a resource 
> path in a very brittle way, just replaces dots for forward slashes, and 
> dashes by underscores.
>

This is exactly the algorithm used by the runtime to load every Clojure 
namespace, so I don't think this particular part is brittle at all.
 

> That's because, `load-one` is actually used to compile, which internally 
> relies on `load`. Load takes a resource path which needs to be found on the 
> classpath, not a namespace.
>
> Now, there are some packages which have source files that have either a 
> different ns name then their file name
>

This is pretty rare as it's impossible for the runtime to load it in the 
normal way when required (it must be explicitly loaded via one of the load 
methods).
 

> , or they use in-ns and are actually evaluating into an existing namespace 
> defined in another file.
>

Slightly more common, but still comparatively rare to the very common case 
of 1 ns per file. (clojure itself does this a number of times)
 

> Lein actually fails to compile these, because the namespace it finds are 
> looked up as resources on the classpath by compile and it can't find the 
> resource, because the resource path does not match the namespace.
>
> So, for my build tool aot :all compilation, I decided to instead use 
> `load` with *compile-files* bound to true. And I just convert each source 
> file in the source dir to a classpath resource path.
>
> From my perspective, this seems a better way to do it, that is more 
> reliable, and frankly a lot simpler. But since no one
>
else did it this way, I'm curious if there is any known issue with this 
> approach?
>
 
Seems like a reasonable alternative to me.


> Regards!
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to