bloop icon indicating copy to clipboard operation
bloop copied to clipboard

Unexpected working directory for sub-projects

Open tpolecat opened this issue 4 years ago • 2 comments

Hi,

The change in #1175 doesn't actually change the working directory when you run from a sub-project. Relative paths are still relative to the project root; it's only when they're canonicalized (getAbsolutePath for example) that they are reinterpreted as being rooted at user.dir.

Here is a little program, in subproject main under modules/main in my project:

object Test {

  def main(args: Array[String]): Unit = {
    val cwd = new java.io.File(".")
    println(cwd.getAbsolutePath)
    println(cwd.listFiles().toList)
  }

}

When when I run it I see this:

itac (cli *)$ bloop run main -m Test
/Users/rnorris/Scala/itac/.
List(./target, ./src)

However they don't correspond as expected.

itac (cli *)$ ls /Users/rnorris/Scala/itac/.
arch/      build.sbt  modules/   project/   src/       target/    work/

Running from sbt gives the expected result.

tac (cli *)$ sbt "main/runMain Test"
[info] Loading global plugins from /Users/rnorris/.sbt/1.0/plugins
...
[info] running Test 
/Users/rnorris/Scala/itac/.
List(./.metals, ./.DS_Store, ./target, ./project, ./.gitignore, ./.bloop, ./work, ./arch, ./.git, ./modules, ./build.sbt, ./src)
[success] Total time: 1 s, completed Mar 23, 2020 12:17:00 PM
itac (cli *)$

There is a JDK issue about this and the evaluation begins:

"user.dir", which is initialized during jvm startup, should be used as an informative/readonly system property, try to customize it via command line -Duser.dir=xyz will end up at implementation dependend/unspecified behavior.

So I think bloop shouldn't do this. Instead is it possible to set cwd in the process builder?

Thanks!

tpolecat avatar Mar 23 '20 17:03 tpolecat

Thank you for reporting! What Bloop version are you using?

❯ bloop about
bloop v1.4.0-RC1-105-118a551b

olafurpg avatar Mar 24 '20 08:03 olafurpg

You can start a new version of bloop with the commands

bloop exit
coursier launch ch.epfl.scala:bloopgun-core_2.12:1.4.0-RC1-105-118a551b -- help

I believe the latest version of master uses the -Duser.dir option to determine the working directory of the forked process.

olafurpg avatar Mar 24 '20 11:03 olafurpg