technomancy / leiningen

Moved to Codeberg; this is a convenience mirror
https://codeberg.org/leiningen/leiningen
Other
7.29k stars 1.61k forks source link

Warn when attempting to change hard-coded eval-in-leiningen fields #769

Open charleslparker opened 12 years ago

charleslparker commented 12 years ago

I don't have much experience with Leiningen, but this looks awfully strange (note that I have lein2 as both 2.x and 1.7.x are running on my system).

Charless-MacBook-Air:featurize charleslparker$ lein2 clean
Charless-MacBook-Air:featurize charleslparker$ lein2 compile
Compiling 1 source files to /Users/charleslparker/gitrepos/featurize/target/classes
Compiling featurize.main
Compilation failed: java.io.IOException: No such file or directory, compiling:(featurize/main.clj:7)
Charless-MacBook-Air:featurize charleslparker$ lein2 clean
Charless-MacBook-Air:featurize charleslparker$ lein2 trampoline compile
Warning: trampoline has no effect with :eval-in-leiningen.
Compiling 1 source files to /Users/charleslparker/gitrepos/featurize/target/classes
Compiling featurize.main
Charless-MacBook-Air:featurize charleslparker$ 

Clearly trampoline does have some effect. The same thing happens with lein2 test; I can run tests when using trampoline, but the build fails when I don't.

My project.clj:

(defproject featurize "0.1.0-SNAPSHOT"
  :source-paths ["src/clj"]
  :resource-paths ["res"]
  :java-source-paths ["src/java"]
  :main featurize.main
  :eval-in-leiningen true
  :profiles {:dev
             {:dependencies [[swank-clojure "1.4.2"]]}}
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [org.apache.lucene/lucene-analyzers "3.6.1"]
                 [org.clojure/tools.cli "0.2.2"]
                 [com.taoensso/timbre "0.8.0"]])
technomancy commented 12 years ago

Yeah, in this case the problem is that you can't change :source-paths while using :eval-in-leiningen. The message should be clearer though.

charleslparker commented 12 years ago

But using trampoline to "bounce around" that restriction is a legal move, or is it some sort of hole that's going to be closed?

technomancy commented 12 years ago

I'd say it's a loophole. The point of trampoline is to avoid the creation of a subprocess, which is something you already get by definition with :eval-in-leiningen. There are certain restrictions with :eval-in-leiningen that we can't work around due to bootstrapping difficulties; having things behave differently in trampoline on purpose is not something I want to support; it's undefined behaviour. Why are you setting :eval-in-leiningen to begin with?

charleslparker commented 12 years ago

I'd say it's a loophole.

I figured it was.

Why are you setting :eval-in-leiningen to begin with?

I've got project-specific tasks defined in src/leiningen.

On a related note, I've got a more minimal example of the problem:

1.) Start a new project with lein new tproj.

2.) Modify project.clj so it looks like this:

(defproject tproj "1.0.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.3.0"]]
  :eval-in-leiningen true
  :aot [tproj.core]
  :main tproj.core)

3.) and src/tproj/core.clj:

(ns tproj.core
  (:gen-class :main true))

(defn -main [& args]
  (println "Hello, Main!"))

And you get the following behavior:

Charless-MacBook-Air:tproj charleslparker$ lein2 clean
Charless-MacBook-Air:tproj charleslparker$ lein2 run
Compiling tproj.core
Compilation failed: java.io.IOException: No such file or directory, compiling:(tproj/core.clj:1)
Charless-MacBook-Air:tproj charleslparker$ lein2 clean
Charless-MacBook-Air:tproj charleslparker$ lein2 trampoline run
Warning: trampoline has no effect with :eval-in-leiningen.
Compiling tproj.core
Compiling tproj.core
Hello, Main!
Charless-MacBook-Air:tproj charleslparker$ 

Taking out :eval-in-leiningen makes things behave again. Also, taking out :aot and :main allows compilation and testing. If one isn't supposed to use eval-in-leiningen to create project-specific tasks, I'll volunteer to add a comment on some Stack Overflow responses :)

Thanks for all your hard work on this, by the way. It's a really nice thing.

technomancy commented 12 years ago

Charles Parker notifications@github.com writes:

Why are you setting :eval-in-leiningen to begin with?

I've got project-specific tasks defined in src/leiningen.

OK, that's handled much better by this:

$ mkdir tasks
$ mv src/leiningen tasks/
$ echo tasks > .lein-classpath

On a related note, I've got a more minimal example of the problem:

[...]

Charless-MacBook-Air:tproj charleslparker$ lein2 clean Charless-MacBook-Air:tproj charleslparker$ lein2 run Compiling tproj.core Compilation failed: java.io.IOException: No such file or directory, compiling:(tproj/core.clj:1)

This might be pointing to a different problem where the project's default :compile-path needs to be changed if it's using :eval-in-leiningen.

charleslparker commented 12 years ago

OK, that's handled much better by this:

Indeed it is - I've made a few posts so it doesn't get forgotten. I'd also be happy to do a little PR to update PLUGINS.md with this information if you think it would be useful. I think it's a pretty common case and there's not much on the innertubes about it (as it is in 2.x).

trptcolin commented 12 years ago

@charleslparker +1 on a PR or wiki edit to update lein project documentation to point this out. This is great stuff - somehow I didn't know about it either.

technomancy commented 12 years ago

Yeah, there's a brief mention in PLUGINS.md, but I agree it's not easy to find. Happy to have that improved.

technomancy commented 12 years ago

Leaving this open with a different name so we could get warnings about what can't be changed with :eval-in-project.