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

Commit

Permalink
Fixed location of the generated workspace
Browse files Browse the repository at this point in the history
Summary:
Before the diff, when generating a project of a target in a cell, it would put the workspace in the folder
in the main cell and not in the specific cell.

```
$ buck project foobar//path/to:target
```

It would write the workspace to [main-cell-path]/path/to (a) instead of [foobar-cell-path]/path/to (b).
The expected location is (b). Especially, since the project for [foobar-cell-path]/path/to is generated in that folder.

This diff makes sure that the workspace is generated at the correct location when the target is in a cell.

Reviewed By: williamtwilson

fbshipit-source-id: e98c4f159a
  • Loading branch information
dinhvh authored and facebook-github-bot committed Mar 22, 2019
1 parent 6f67bdf commit ac3081b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PrintStreamPathOutputPresenter(PrintStream outputStream, Mode mode, Path
public void present(String prefix, Path path) {
Path prettyPath;
if (outputMode == Mode.FULL) {
prettyPath = repoRoot.resolve(path);
prettyPath = repoRoot.resolve(path).normalize();
} else if (outputMode == Mode.SIMPLE) {
prettyPath = path;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2920,8 +2920,11 @@ private void createMergedHeaderMap() throws IOException {
// Writes the resulting header map.
Path mergedHeaderMapRoot = getPathToMergedHeaderMap();
Path headerMapLocation = getHeaderMapLocationFromSymlinkTreeRoot(mergedHeaderMapRoot);
projectFilesystem.mkdirs(mergedHeaderMapRoot);
projectFilesystem.writeBytesToPath(headerMapBuilder.build().getBytes(), headerMapLocation);
Cell workspaceCell = projectCell.getCell(workspaceTarget.get());
workspaceCell.getFilesystem().mkdirs(mergedHeaderMapRoot);
workspaceCell
.getFilesystem()
.writeBytesToPath(headerMapBuilder.build().getBytes(), headerMapLocation);
}

private void createHeaderSymlinkTree(
Expand Down Expand Up @@ -3585,8 +3588,9 @@ private ImmutableSet<Path> collectRecursiveHeaderSearchPaths(
getHeaderSearchPathFromSymlinkTreeRoot(
getHeaderSymlinkTreePath(targetNode, HeaderVisibility.PRIVATE)));
if (options.shouldUseAbsoluteHeaderMapPaths()) {
builder.add(
getHeaderSearchPathFromSymlinkTreeRoot(getPathToMergedHeaderMap().toAbsolutePath()));
Cell workspaceCell = projectCell.getCell(workspaceTarget.get());
Path absolutePath = workspaceCell.getFilesystem().resolve(getPathToMergedHeaderMap());
builder.add(getHeaderSearchPathFromSymlinkTreeRoot(absolutePath));
} else {
builder.add(getHeaderSearchPathFromSymlinkTreeRoot(getRelativePathToMergedHeaderMap()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,11 @@ static ImmutableSet<BuildTarget> generateWorkspacesForTargets(

CxxPlatform defaultCxxPlatform =
cxxPlatformsProvider.getDefaultUnresolvedCxxPlatform().getLegacyTotallyUnsafe();
Cell workspaceCell = cell.getCell(inputTarget);
WorkspaceAndProjectGenerator generator =
new WorkspaceAndProjectGenerator(
xcodeDescriptions,
cell,
workspaceCell,
targetGraphAndTargets.getTargetGraph(),
workspaceArgs,
inputTarget,
Expand Down Expand Up @@ -525,7 +526,9 @@ static ImmutableSet<BuildTarget> generateWorkspacesForTargets(
inputTarget, requiredBuildTargetsForWorkspace);
requiredBuildTargetsBuilder.addAll(requiredBuildTargetsForWorkspace);

presenter.present(inputTarget.getFullyQualifiedName(), outputPath);
Path absolutePath = workspaceCell.getFilesystem().resolve(outputPath);
Path relativePath = cell.getFilesystem().relativize(absolutePath);
presenter.present(inputTarget.getFullyQualifiedName(), relativePath);
}

return requiredBuildTargetsBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,33 @@ public void testBuckProjectWithEmbeddedCellBuckoutAndMergedHeaderMap()
runXcodebuild(workspace, "Apps/TestApp.xcworkspace", "TestApp");
}

@Test
public void testBuckProjectOtherCell() throws IOException, InterruptedException {
assumeTrue(Platform.detect() == Platform.MACOS);
assumeTrue(AppleNativeIntegrationTestUtils.isApplePlatformAvailable(ApplePlatform.MACOSX));
ProjectWorkspace workspace =
TestDataHelper.createProjectWorkspaceForScenario(
this, "project_with_cell", temporaryFolder);
workspace.setUp();

ProcessResult result =
workspace.runBuckCommand(
"project",
"--config",
"project.embedded_cell_buck_out_enabled=true",
"--config",
"apple.merge_header_maps_in_xcode=true",
"--show-output",
"bar//Dep2:Dep2");
result.assertSuccess();

assertEquals(
"bar//Dep2:Dep2#default,static "
+ Paths.get("bar", "Dep2", "Dep2.xcworkspace")
+ System.lineSeparator(),
result.getStdout());
}

@Test
public void testBuckProjectWithSwiftDependencyOnModularObjectiveCLibrary()
throws IOException, InterruptedException {
Expand Down

0 comments on commit ac3081b

Please sign in to comment.