Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Summary ] Fix a process fork issue on Windows #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhanghuabin
Copy link

@zhanghuabin zhanghuabin commented May 9, 2019

[ Root Cause ]

  1. There has no clojure script on Windows, the Clojure CLI is a PowerShell Module in windows, which cannot be called as a script directly.
  2. Therefore, I make a .bat or .cmd to execute a PowerShell command.
  3. After adding this .bat file to PATH, lein-tools-deps still cannot work, because the process created by (shell/sh "clojure" "-Sdescribe") cannot find either clojure.bat or clojure.cmd in PATH.

[Solution/Workaround ]
(shell/sh "cmd" "/c" "clojure" "-Sdescribe") work well for both the 'clojure' script file in PATH and custom path from clojure-executables.

[ Result ]
I test these two snippets in REPL:

(if (.startsWith (System/getProperty "os.name") "Windows")
  (shell/sh "cmd" "/c" "clojure" "-Sdescribe")
  (shell/sh "clojure" "-Sdescribe"))
(if (.startsWith (System/getProperty "os.name") "Windows")
  (shell/sh "cmd" "/c" "path/to/clojure.cmd" "-Sdescribe")
  (shell/sh "/path/to/clojure.cmd" "-Sdescribe"))

[ Root Cause ]
1. There has no `clojure` script on Windows, the Clojure CLI is a PowerShell Module in windows, which cannot be called as a script directly.
2. Therefore, I make a `.bat` or `.cmd` to execute a PowerShell command.
3. After adding this `.bat` file to PATH, `lein-tools-deps` still cannot work, because the process created by `(shell/sh "clojure" "-Sdescribe")` cannot find either `clojure.bat` or `clojure.cmd` in PATH.

[Solution/Workaround ]
`(shell/sh "cmd" "/c" "clojure" "-Sdescribe")` work well for both the 'clojure' script file in PATH and custom path from `clojure-executables`.

[ Result ]
I test these two snippets in REPL:
(if (.startsWith (System/getProperty "os.name") "Windows")
  (shell/sh "cmd" "/c" "clojure" "-Sdescribe")
  (shell/sh "clojure" "-Sdescribe"))

(if (.startsWith (System/getProperty "os.name") "Windows")
  (shell/sh "cmd" "/c" "path/to/clojure.cmd" "-Sdescribe")
  (shell/sh "/path/to/clojure.cmd" "-Sdescribe"))
@hlolli
Copy link

hlolli commented Jun 28, 2019

Tested this PR, and this is what I get

 lein deps
clojure.lang.ExceptionInfo: Unable to locate Clojure's edn files
{:exit 1, :out "", :err "'clojure' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"}
 at lein_tools_deps.env$scrape_clojure_env.invokeStatic (env.clj:38)
    lein_tools_deps.env$scrape_clojure_env.invoke (env.clj:27)
    clojure.lang.AFn.applyToHelper (AFn.java:154)
    clojure.lang.AFn.applyTo (AFn.java:144)
    clojure.core$apply.invokeStatic (core.clj:665)
    clojure.core$memoize$fn__6862.doInvoke (core.clj:6353)
    clojure.lang.RestFn.invoke (RestFn.java:408)
    lein_tools_deps.plugin$apply_middleware.invokeStatic (plugin.clj:25)
    lein_tools_deps.plugin$apply_middleware.invoke (plugin.clj:17)
    lein_tools_deps.plugin$resolve_dependencies_with_deps_edn.invokeStatic (plugin.clj:47)
    lein_tools_deps.plugin$resolve_dependencies_with_deps_edn.invoke (plugin.clj:34)
    clojure.lang.Var.invoke (Var.java:384)
    leiningen.core.project$apply_middleware.invokeStatic (project.clj:817)
    leiningen.core.project$apply_middleware.invoke (project.clj:810)
    clojure.lang.ArrayChunk.reduce (ArrayChunk.java:58)
    clojure.core.protocols$fn__8139.invokeStatic (protocols.clj:136)
    clojure.core.protocols/fn (protocols.clj:124)
    clojure.core.protocols$fn__8099$G__8094__8108.invoke (protocols.clj:19)
    clojure.core.protocols$seq_reduce.invokeStatic (protocols.clj:31)
    clojure.core.protocols$fn__8131.invokeStatic (protocols.clj:75)
    clojure.core.protocols/fn (protocols.clj:75)
    clojure.core.protocols$fn__8073$G__8068__8086.invoke (protocols.clj:13)
    clojure.core$reduce.invokeStatic (core.clj:6828)
    clojure.core$reduce.invoke (core.clj:6810)
    leiningen.core.project$apply_middleware.invokeStatic (project.clj:812)
    leiningen.core.project$apply_middleware.invoke (project.clj:810)
    leiningen.core.project$activate_middleware.invokeStatic (project.clj:844)
    leiningen.core.project$activate_middleware.invoke (project.clj:840)
    leiningen.core.project$init_project.invokeStatic (project.clj:986)
    leiningen.core.project$init_project.invoke (project.clj:974)
    leiningen.core.project$read.invokeStatic (project.clj:1057)
    leiningen.core.project$read.invoke (project.clj:1054)
    leiningen.core.project$read.invokeStatic (project.clj:1058)
    leiningen.core.project$read.invoke (project.clj:1054)
    leiningen.core.main$_main$fn__6681.invoke (main.clj:447)
    leiningen.core.main$_main.invokeStatic (main.clj:442)
    leiningen.core.main$_main.doInvoke (main.clj:439)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:665)
    clojure.main$main_opt.invokeStatic (main.clj:491)
    clojure.main$main_opt.invoke (main.clj:487)
    clojure.main$main.invokeStatic (main.clj:598)
    clojure.main$main.doInvoke (main.clj:561)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.main.main (main.java:37)

@hlolli
Copy link

hlolli commented Jun 28, 2019

Perhaps it's because currently, clojure isn't a binary on the path, but a powershell function

PS C:\Users\User\Documents\panaeolus> Get-Command clojure

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           clojure -> Invoke-Clojure                          1.10.1.447 ClojureTools


PS C:\Users\User\Documents\panaeolus> Get-Command Invoke-Clojure

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Invoke-Clojure                                     1.10.1.447 ClojureTools

@RickMoynihan
Copy link
Owner

Perhaps it's because currently, clojure isn't a binary on the path, but a powershell function

@hlolli isn't this what @zhanghuabin is saying you need to do here:

i.e. that you need to wrap the powershell command with a .bat or .cmd on the path? (I've not used windows for over a decade so I don't know; just guessing)

If you can confirm this works, I'd be happy to merge this PR if it would also include instructions for how to make this work on windows.

@RickMoynihan
Copy link
Owner

Note this issue also seems related: #85

If the windows users here can assemble a PR with all the changes required to work on windows with any required additional steps in the README, and can perhaps review it amongst yourselves then I'll consider merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants