Skip to content

Commit

Permalink
[infra] Fix not initializing RBE before gn.
Browse files Browse the repository at this point in the history
Bug: b/296994239
Change-Id: I344f07fa7f389fa5b0f5e65b24168f2d05daacbf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355683
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: Jonas Termansen <sortie@google.com>
  • Loading branch information
sortie authored and Commit Queue committed Mar 5, 2024
1 parent a4e1566 commit a27993d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
17 changes: 1 addition & 16 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,6 @@ def StartRBE(out_dir, use_goma, env):
if not os.path.exists(rbe_dir) or not os.path.isdir(rbe_dir):
print(f'Could not find {rbe} at {rbe_dir}')
return False
RBE_cfg = 'RBE_CFG' if HOST_OS == 'win32' else 'RBE_cfg'
RBE_server_address = ('RBE_SERVER_ADDRESS'
if HOST_OS == 'win32' else 'RBE_server_address')
if not use_goma and not RBE_cfg in env:
env[RBE_cfg] = os.path.join(
os.getcwd(), 'build', 'rbe',
'windows.cfg' if HOST_OS == 'win32' else 'unix.cfg')
if not use_goma and not RBE_server_address in env:
with open(env[RBE_cfg], 'r') as f:
if not any([l.startswith('server_address') for l in f.readlines()]):
schema = 'pipe' if HOST_OS == 'win32' else 'unix'
socket = os.path.join(os.getcwd(), out_dir, 'reproxy.sock')
if HOST_OS == 'win32':
socket = socket.replace('\\', '_').replace(':', '_')
env[RBE_server_address] = f'{schema}://{socket}'
bootstrap = 'goma_ctl.py' if use_goma else 'bootstrap'
bootstrap_path = os.path.join(rbe_dir, bootstrap)
bootstrap_command = [bootstrap_path]
Expand Down Expand Up @@ -342,7 +327,7 @@ def Main():
env.pop('SDKROOT', None)

# Always run GN before building.
gn_py.RunGnOnConfiguredConfigurations(options)
gn_py.RunGnOnConfiguredConfigurations(options, env)

# Build all targets for each requested configuration.
configs = []
Expand Down
28 changes: 26 additions & 2 deletions tools/gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,26 @@ def parse_args(args):
return options


def InitializeRBE(out_dir, env):
RBE_cfg = 'RBE_CFG' if HOST_OS == 'win32' else 'RBE_cfg'
RBE_server_address = ('RBE_SERVER_ADDRESS'
if HOST_OS == 'win32' else 'RBE_server_address')
# Default RBE_cfg to the appropriate configuration file.
if not RBE_cfg in env:
env[RBE_cfg] = os.path.join(
os.getcwd(), 'build', 'rbe',
'windows.cfg' if HOST_OS == 'win32' else 'unix.cfg')
# Default RBE_server_address to inside the build directory.
if not RBE_server_address in env:
with open(env[RBE_cfg], 'r') as f:
if not any([l.startswith('server_address') for l in f.readlines()]):
schema = 'pipe' if HOST_OS == 'win32' else 'unix'
socket = os.path.join(os.getcwd(), out_dir, 'reproxy.sock')
if HOST_OS == 'win32':
socket = socket.replace('\\', '_').replace(':', '_')
env[RBE_server_address] = f'{schema}://{socket}'


def ExecutableName(basename):
if utils.IsWindows():
return f'{basename}.exe'
Expand Down Expand Up @@ -652,13 +672,17 @@ def BuildGnCommand(args, mode, arch, target_os, sanitizer, out_dir):
return command


def RunGnOnConfiguredConfigurations(args):
def RunGnOnConfiguredConfigurations(args, env={}):
initialized_rbe = False
commands = []
for target_os in args.os:
for mode in args.mode:
for arch in args.arch:
for sanitizer in args.sanitizer:
out_dir = GetOutDir(mode, arch, target_os, sanitizer)
if args.rbe and not initialized_rbe:
InitializeRBE(out_dir, env)
initialized_rbe = True
commands.append(
BuildGnCommand(args, mode, arch, target_os, sanitizer,
out_dir))
Expand All @@ -674,7 +698,7 @@ def cleanup(command):

for command in commands:
try:
process = subprocess.Popen(command, cwd=DART_ROOT)
process = subprocess.Popen(command, cwd=DART_ROOT, env=env)
active_commands.append([command, process])
except Exception as e:
print('Error: %s' % e)
Expand Down

0 comments on commit a27993d

Please sign in to comment.