google / copybara

Copybara: A tool for transforming and moving code between repositories.
Apache License 2.0
2.13k stars 263 forks source link

$HOME not found in Windows #38

Open mikelalcon opened 6 years ago

mikelalcon commented 6 years ago

From : https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/copybara-discuss/XPTFivEHJUg/B_mlkpc5CgAJ

Hi Mikel,

Thanks for replying. Yes, I am using windows. Here is the stack trace:

Task: Cleaning output directory. java.lang.NullPointerException: $HOME environment var is not set at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787) at com.google.copybara.GeneralOptions.getDirFactory(GeneralOptions.java:208) at com.google.copybara.Main.lambda$cleanupOutputDir$0(Main.java:351) at com.google.copybara.GeneralOptions.ioRepoTask(GeneralOptions.java:189) at com.google.copybara.Main.cleanupOutputDir(Main.java:345) at com.google.copybara.Main.initEnvironment(Main.java:337) at com.google.copybara.Main.runInternal(Main.java:160) at com.google.copybara.Main.run(Main.java:107) at com.google.copybara.Main.main(Main.java:86)

natalieReppekus commented 4 years ago

Hi Mikel,

What happend to this issue. Is there a solution now?

mikelalcon commented 4 years ago

Hi Natalie,

We didn't investigate as it was tricky to have a windows environment. But if you use the --output-root flag it shouldn't hit that codepath (But there might be a failure later in the process, as we don't test in Windows). Our general recommendation is to run it in Linux or OSX, but let us know how it goes.

natalieReppekus commented 4 years ago

Hi, I switched to Linux and it works for me now :)

hcoona commented 2 years ago

I think windows won't automatically set $HOME environment variable. We need to use $HOMEDRIVE + $HOMEPATH instead.

Vertexwahn commented 1 day ago

Would be nice if the tool would also work on Windows - got the same error with current master

It seems to use USERPROFILE in the case HOME is not set fixes the issue on Windows:

    if (getOutputRoot() != null) {
      return new DirFactory(getOutputRoot());
    } else {
      String home = checkNotNull(environment.get("HOME"), "$HOME environment var is not set");
      String home = environment.get("HOME");
      if (home == null) {
        home = environment.get("USERPROFILE");
      }
      return new DirFactory(fileSystem.getPath(home).resolve("copybara"));
    }
  }
hsudhof commented 1 day ago

See the comment about --output-root