On Tuesday, April 7, 2015 at 6:13:53 AM UTC-7, Han-Wen Nienhuys wrote:
> Do you have a workspace name defined in WORKSPACE ? What happens if
> you rename the directory you are building bazel in to something else?
> Does the erroneous path component change along?
>
I do not have a workspace name defined in WORKSPACE, it's just a blank WORKSPACE file (this is all done in a copy of bazel's base_workspace directory).
I renamed the bazel build directory to bazel2, updated the tools and third_party symlinks, as well as the arguments to build in .bazelrc to point to the new location. Once again, bazel build succeeds and generates the files, but when I open the project in Xcode, Xcode will give the same errors, except it now complains that it can't find things with the path component changed along to the new bazel2 directory.
I don't have any knowledge of how xcode projects should work, but I popped open the generated project.pbxproj and searched through it as text. The full path to the bazel director appears 6 times in the XML of this file, always in a complex of XML that suggests it is the value for a key. Examples:
----
<dict>
<key>isa</key>
<string>PBXGroup</string>
<key>name</key>
<string>mainGroup</string>
<key>path</key>
<string>/Users/David/Documents/Development/bazel2</string>
<key>sourceTree</key>
<string><![CDATA[<group>]]></string>
<key>children</key>
<array>
<string>B401C979DCDB0B5300000000</string>
<string>B401C9799EF61BFC00000000</string>
<string>B401C9792FADE24C00000000</string>
</array>
</dict>
----
and
----
<dict>
<key>isa</key>
<string>XCBuildConfiguration</string>
<key>name</key>
<string>Debug</string>
<key>buildSettings</key>
<dict>
<key>USER_HEADER_SEARCH_PATHS</key>
<array>
<string>$(WORKSPACE_ROOT)</string>
<string>$(WORKSPACE_ROOT)/bazel-out/local_darwin-fastbuild/genfiles</string>
<string>$(WORKSPACE_ROOT)</string>
</array>
<key>HEADER_SEARCH_PATHS</key>
<array>
<string>$(inherited)</string>
</array>
<key>FRAMEWORK_SEARCH_PATHS</key>
<array>
<string>$(SDKROOT)/Developer/Library/Frameworks</string>
<string>$(PLATFORM_DIR)/Developer/Library/Frameworks</string>
</array>
<key>WORKSPACE_ROOT</key>
<string>/Users/David/Documents/Development/bazel2</string>
...
(plenty more)
...
----
The path to my project workspace and source code does not appear in the pbxproj.
I tried to do a little searching through the bazel source code. I'm way too new to this code to really know what is going on, but I did notice the function com.google.devtools.build.xcode.xcodegen.XcodeprojGeneration.xcodeproj() takes an argument called workspaceRoot. This function appears, according to grep, to only be called from com.google.devtools.build.xcode.xcodegen.XcodeGen.main(). In the function, workspaceRoot is created with this code:
----
Path workspaceRoot;
if (!Files.exists(symlinkToInsideWorkspace)) {
workspaceRoot = XcodeprojGeneration.relativeWorkspaceRoot(pbxprojPath);
} else {
// Get the absolute path to the workspace root.
// TODO(bazel-team): Remove this hack, possibly by converting Xcodegen to be run with
// "bazel run" and using RUNFILES to get the workspace root. For now, this is needed to work
// around Xcode's handling of symlinks not playing nicely with how Bazel stores output
// artifacts in /private/var/tmp. This means a relative path from .xcodeproj in bazel-out to
// the workspace root in .xcodeproj will not work properly at certain times during
// Xcode/xcodebuild execution.
workspaceRoot = symlinkToInsideWorkspace
.toRealPath()
.resolve("../../..")
.normalize();
}
----
I could be totally off in the weeds, but it seems relevant. I don't know what to change there to see if there's any improvement, though.
David