Plugins in profiles broken #772

Closed
cemerick opened this Issue Sep 7, 2012 · 3 comments

Comments

2 participants
Collaborator

cemerick commented Sep 7, 2012

Apologies for the useless title, but things are askew enough that I don't really know how to sum it up.

project.clj #1:

(defproject bad-init "0.0.1-SNAPSHOT"
  :min-lein-version "2.0.0"
  :profiles {:pprint {:plugins [[lein-pprint "1.1.1"]]}})

This should yield a pprinted representation of the project map:

la-mer:tmp chas$ lein with-profile pprint pprint
Performing task 'pprint' with profile(s): 'pprint'
'pprint' is not a task. See 'lein help'.

Did you mean this?
         run
         plugin
Error encountered performing task 'pprint' with profile(s): 'pprint'

project.clj #2:

(defproject bad-init "0.0.1-SNAPSHOT"

  :cljsbuild {:builds [{:source-path "cljs"
                        :compiler {:output-to "target/classes/cljs.js"
                                   :optimizations :whitespace
                                   :pretty-print true}}]}

  :plugins [[lein-pprint "1.1.1"]]

  :profiles {:dev {:plugins [[lein-cljsbuild "0.2.7"]]
                   :hooks [leiningen.cljsbuild]}
             :no-cljsbuild {}})

This should not include lein-cljsbuild in any way as far as I understand how profiles are supposed to work.

la-mer:tmp chas$ lein2 clean
Deleting files generated by lein-cljsbuild.
la-mer:tmp chas$ lein2 with-profile no-cljsbuild clean
Performing task 'clean' with profile(s): 'no-cljsbuild'
Deleting files generated by lein-cljsbuild.

The core issue with #2 AFAICT is that activate-middleware is being called twice: once with all of the defaults (including :dev) and once with the specified set of profiles, so the lein-cljsbuild hooks are applied long before with-profile ever enters the picture.

Collaborator

cemerick commented Oct 5, 2012

Not fixed. Note that the first case in the original description works properly with -preview10.

With master, the second case remains broken:

la-mer:tmp chas$ lein2 with-profile no-cljsbuild clean
Performing task 'clean' with profile(s): 'no-cljsbuild'
Deleting files generated by lein-cljsbuild.

cljsbuild shouldn't even be on the classpath, nevermind have its hooks activated.

As I said in the original description, this is because activate-middleware is called twice: from both init-project and set-profiles. Since the default profiles are in scope for the former, :dev gets applied, and there's no way to unapply it (regardless of what unmerge might do to the project map, classpath changes and hook applications are forever).

Removing the activate-middleware call from init-project fixes the second case for me. I haven't committed such a change because I presume things are depending on it…but perhaps I should and see who screams… ;-)

@cemerick cemerick reopened this Oct 5, 2012

Collaborator

cemerick commented Oct 5, 2012

Right: load-plugins in init-project is what's responsible for the classpath changes when the default profiles are active, so that's part of the problem as well.

It seems like a lot of complexity is coming from the fact that there's two different profile lifecycles in play: one involving the default profiles (which is always implicit), and one involving whatever is specified by the user via with-profile. If I have this right, that means that, e.g. there's no way for someone to use with-profile to have middleware applied that replaces or is contrary to middleware specified at the base level of project.clj or in a default profile: the latter will always be applied regardless, and by the time with-profile gets control, the default middleware has already had its way. Same goes for hooks.

A simplification would be for init-project to do nothing, and for all tasks to be invoked within the scope of with-profile, so that e.g. lein repl would be tweaked into lein with-profile dev,provided,user,base repl. Of course, explicit usage of with-profile would supersede the implicit default profiles, which is exactly what's not happening now.

Owner

technomancy commented Oct 5, 2012

It seems like the root problem you're describing is that hooks aren't reversible. I just merged technomancy/robert-hooke#10 from @hugoduncan to address this inside Hooke, but I'm going to go ahead and consider that a separate problem in #802.

@technomancy technomancy closed this Oct 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment