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

Allow path options to use user specific paths #4852

Conversation

davido
Copy link
Contributor

@davido davido commented Mar 14, 2018

Fixes #2054.

Allow users to be able to specify user specific paths. With this option
we can now commit bazel configuration file and force local action cache
activation per default:

$ cat tools/bazel.rc
build --experimental_local_disk_cache_path=~/.gerrit/bazel-cache/cas
build --experimental_local_disk_cache
build --experimental_strict_action_env

Test Plan:

$ bazel test //src/test/java/com/google/devtools/build/lib:util_test

@buchgr
Copy link
Contributor

buchgr commented Mar 16, 2018

@laszlocsomor does this also work for Windows users?

@buchgr buchgr self-assigned this Mar 16, 2018
@@ -103,7 +104,11 @@ public static String asFilteredShellEscapedString(OptionsProvider options) {

@Override
public PathFragment convert(String input) {
return PathFragment.create(input);
String path = Preconditions.checkNotNull(input);
if (!path.isEmpty() && path.charAt(0) == '~') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an OS.getCurrent() check around this if, and only replace "~" on Linux/macOS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(OS in the same Java package)

Copy link
Contributor Author

@davido davido Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, user.home should be resolved just fine on Windows and recent JDK versions: [1]. On Windows, on Java 8, we have:

public class Test {
  public static void main(String[] args) {
    String path = "~/foo/";
    path = path.replace("~", System.getProperty("user.home"));
    System.out.println(path);
  }
}

Running it produces:

C:\>java Test
C:\Users\davido/foo/

FTR: I backported this solution from that Buck feature: Add support for user home in cache directory name that I added to Buck 4 years ago. And of course, Buck is platform independent.

[1] https://bugs.java.com/view_bug.do?bug_id=4787931
[2] https://stackoverflow.com/questions/2134338/java-user-home-is-being-set-to-userprofile-and-not-being-resolved

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but ~abc is a valid directory name on Windows. So I'm reluctant to expand "~" to user.home on Windows too.

Copy link
Contributor Author

@davido davido Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a working and platform independent solution to configure local action path per default and commit it in (D)VCS. I am open to any suggestions, but we just can't solve the problem at hand for Linux/macOS, and ignore Windows users.

Should we compare for "~/" instead on all platforms, a lá:

 if (path.startsWith("~/")) {
 [...]

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please, that'd be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -123,6 +128,9 @@ public String getTypeDescription() {
List<PathFragment> list = new ArrayList<>();
for (String piece : input.split(":")) {
if (!piece.isEmpty()) {
if (piece.charAt(0) == '~') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

Fixes bazelbuild#2054.

Allow users to be able to specify user specific paths. With this option
we can now commit bazel configuration file and force local action cache
activation per default:

  $ cat tools/bazel.rc
  build --experimental_local_disk_cache_path=~/.gerrit/bazel-cache/cas
  build --experimental_local_disk_cache
  build --experimental_strict_action_env

Test Plan:

  $ bazel test //src/test/java/com/google/devtools/build/lib:util_test
@davido davido force-pushed the allow-path-options-to-use-home-directory-character branch from cbe4ecb to f05d535 Compare March 19, 2018 21:50
Copy link
Contributor

@laszlocsomor laszlocsomor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@laszlocsomor
Copy link
Contributor

@tomlu FYI

@bazel-io bazel-io closed this in f87a656 Mar 20, 2018
@davido davido deleted the allow-path-options-to-use-home-directory-character branch March 20, 2018 18:24
lucamilanesio pushed a commit to GerritCodeReview/gerrit that referenced this pull request Jun 4, 2018
During migration from Buck to Bazel we lost action caches activation per
default. For one, local action cache wasn't implemented in Bazel, for
another, there was no option to specify HOME directory. I fixed both
problems and starting with Bazel 0.14.0 both features are included in
released Bazel version: [1], [2].

There is still one not implemented option, limit the cache directory
with max size: [3]. But for now the advantage to activate the caches per
default far outweigh the disadvantage of unlimited growth of size of
cache directory beyound imaginary max size of say 10 GB. In meantime we
add a warning to watch the size of the directory cache and periodically
clean cache directory:

  $ rm -rf ~/.gerritcodereview/bazel-cache/cas/*

[1] https://bazel-review.googlesource.com/#/c/bazel/+/16810
[2] bazelbuild/bazel#4852
[3] bazelbuild/bazel#5139

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

Successfully merging this pull request may close these issues.

4 participants