Skip to content

Commit ea42a4b

Browse files
committed
Allow setting XCODE_VERSION_OVERRIDE to a DEVELOPER_DIR path
Support for this was added in Bazel commit d2e8c82570c63e9a0c6ef369ef458a86f587e819. It can be used to force the use of a specific version of Xcode.
1 parent 97cfb22 commit ea42a4b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

pkg/runner/apple_xcode_resolving_runner.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sync"
1111

1212
runner_pb "github.com/buildbarn/bb-remote-execution/pkg/proto/runner"
13+
"github.com/buildbarn/bb-storage/pkg/filesystem/path"
1314
"github.com/buildbarn/bb-storage/pkg/util"
1415

1516
"google.golang.org/grpc/codes"
@@ -134,7 +135,14 @@ func (r *appleXcodeResolvingRunner) Run(ctx context.Context, oldRequest *runner_
134135

135136
developerDir, ok := r.developerDirectories[xcodeVersion]
136137
if !ok {
137-
return nil, status.Errorf(codes.FailedPrecondition, "Attempted to use Xcode installation with version %#v, while only %s are supported", xcodeVersion, r.supportedVersions)
138+
// Bazel 8.3 and later also allow XCODE_VERSION_OVERRIDE
139+
// to be set to a DEVELOPER_DIR path. This can be used
140+
// to force the use of a specific copy of Xcode.
141+
developerDirBuilder, scopeWalker := path.EmptyBuilder.Join(path.NewAbsoluteScopeWalker(path.VoidComponentWalker))
142+
if err := path.Resolve(path.UNIXFormat.NewParser(xcodeVersion), scopeWalker); err != nil {
143+
return nil, status.Errorf(codes.FailedPrecondition, "Attempted to use Xcode installation with version %#v, while only %s are supported", xcodeVersion, r.supportedVersions)
144+
}
145+
developerDir = developerDirBuilder.GetUNIXString()
138146
}
139147

140148
var newRequest runner_pb.RunRequest

pkg/runner/apple_xcode_resolving_runner_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,31 @@ func TestAppleXcodeResolvingRunner(t *testing.T) {
164164
require.NoError(t, err)
165165
testutil.RequireEqualProto(t, response, observedResponse)
166166
})
167+
168+
t.Run("XcodeVersionOverrideIsDeveloperDir", func(t *testing.T) {
169+
// Bazel 8.3 and later also allow XCODE_VERSION_OVERRIDE
170+
// to be set to a DEVELOPER_DIR path. This can be used
171+
// to force the use of a specific copy of Xcode.
172+
sdkRootResolver.EXPECT().Call(ctx, "/Applications/Xcode12.app/Contents/Developer", "macosx").
173+
Return("/Applications/Xcode12.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk", nil)
174+
baseRunner.EXPECT().Run(ctx, testutil.EqProto(t, &runner_pb.RunRequest{
175+
Arguments: []string{"cc", "-o", "hello.o", "hello.c"},
176+
EnvironmentVariables: map[string]string{
177+
"APPLE_SDK_PLATFORM": "MacOSX",
178+
"DEVELOPER_DIR": "/Applications/Xcode12.app/Contents/Developer",
179+
"SDKROOT": "/Applications/Xcode12.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk",
180+
"XCODE_VERSION_OVERRIDE": "/Applications/Xcode12.app/Contents/Developer",
181+
},
182+
})).Return(response, nil)
183+
184+
observedResponse, err := runner.Run(ctx, &runner_pb.RunRequest{
185+
Arguments: []string{"cc", "-o", "hello.o", "hello.c"},
186+
EnvironmentVariables: map[string]string{
187+
"APPLE_SDK_PLATFORM": "MacOSX",
188+
"XCODE_VERSION_OVERRIDE": "/Applications/Xcode12.app/Contents/Developer",
189+
},
190+
})
191+
require.NoError(t, err)
192+
testutil.RequireEqualProto(t, response, observedResponse)
193+
})
167194
}

0 commit comments

Comments
 (0)