Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Add support for user home in cache directory name
Browse files Browse the repository at this point in the history
Summary:
Make it possible to provide the following cache directory name
in .buckconfig file:

  dir = ~/.gerritcodereview/buck-cache

This allows to share the same Buck cache directory for multiple
source trees.

Closes #120

Test Plan: unit tests
  • Loading branch information
davido authored and oconnor663 committed Jun 11, 2014
1 parent a0cd969 commit a1ba001
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/com/facebook/buck/cli/BuckConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,12 @@ ImmutableList<String> getArtifactCacheModes() {
@VisibleForTesting
Path getCacheDir() {
String cacheDir = getValue("cache", "dir").or(DEFAULT_CACHE_DIR);
if (!cacheDir.isEmpty() && cacheDir.charAt(0) == '/') {
return Paths.get(cacheDir);
if (!cacheDir.isEmpty()) {
if (cacheDir.charAt(0) == '/') {
return Paths.get(cacheDir);
} else if (cacheDir.charAt(0) == '~') {
return Paths.get(cacheDir.replace("~", System.getProperty("user.home")));
}
}
return projectFilesystem.getAbsolutifier().apply(Paths.get(cacheDir));
}
Expand Down
25 changes: 25 additions & 0 deletions test/com/facebook/buck/cli/BuckConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,31 @@ public void testIgnorePathsWithAbsoluteCacheDir() throws IOException {
EasyMock.verify(filesystem, parser);
}

@Test
public void testIgnorePathsWithUserHomeCacheDir() throws IOException {

ProjectFilesystem filesystem = EasyMock.createMock(ProjectFilesystem.class);
BuildTargetParser parser = EasyMock.createMock(BuildTargetParser.class);
EasyMock.replay(filesystem, parser);
Reader reader = new StringReader(Joiner.on('\n').join(
"[cache]",
"dir = ~/cache_dir"));
BuckConfig config = BuckConfig.createFromReader(
reader,
filesystem,
parser,
Platform.detect(),
ImmutableMap.copyOf(System.getenv()));

ImmutableSet<Path> ignorePaths = config.getIgnorePaths();
assertFalse("User home cache directory should not be in set of ignored paths",
ignorePaths.contains(System.getProperty("user.home") +
File.separator +
"cache_dir"));

EasyMock.verify(filesystem, parser);
}

@Test
public void testBuckPyIgnorePaths() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
Expand Down

0 comments on commit a1ba001

Please sign in to comment.