Skip to content

Unexpected working directory for sub-projects #1210

Open
@tpolecat

Description

@tpolecat

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions