Skip to content

Commit

Permalink
[wheel] Speed up local rebuilds (#22391)
Browse files Browse the repository at this point in the history
When building locally, the "incubator" layer was being unnecessarily
rebuilt every time due to gzip mtime nondeterminism. With this fix,
local wheel builds are incremental (fast) again.
  • Loading branch information
jwnimmer-tri authored Jan 4, 2025
1 parent 0011cd8 commit e97dc74
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tools/wheel/wheel_builder/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# //tools/wheel:builder for the user interface.

import argparse
import gzip
import io
import locale
import os
import pathlib
import re
import shutil
import subprocess
Expand Down Expand Up @@ -81,7 +84,8 @@ def create_snopt_tgz(*, snopt_path, output):
shutil.copy(src=snopt_path, dst=output)
return
print('[-] Creating SNOPT archive...', flush=True)
tgz = tarfile.open(output, 'w:gz')
tar_buffer = io.BytesIO()
tar_writer = tarfile.open(mode='w', fileobj=tar_buffer)

# Ask Bazel where it keeps its externals.
command = ['bazel', 'info', 'output_base']
Expand All @@ -97,8 +101,8 @@ def create_snopt_tgz(*, snopt_path, output):
]
subprocess.run(command, check=True, cwd=resource_root)

# Compress the files into the required tgz format. We only want the files
# from these subdirectories (and not recursively):
# Compress the files into a tar archive. We only want the files from these
# subdirectories (and not recursively):
keep_dirs = [
'interfaces/include',
'interfaces/src',
Expand All @@ -122,9 +126,14 @@ def create_snopt_tgz(*, snopt_path, output):
if tgz_file.endswith('.orig'):
tgz_file = tgz_file[:-len('.orig')]
# Add the file.
tgz.add(full_file, tgz_file, recursive=False,
filter=strip_tar_metadata)
tgz.close()
tar_writer.add(full_file, tgz_file, recursive=False,
filter=strip_tar_metadata)
tar_writer.close()

# Write to disk and gzip (as required by Drake's SNOPT_PATH).
tar_buffer.seek(0)
tgz_data = gzip.compress(tar_buffer.read(), compresslevel=0, mtime=0)
pathlib.Path(output).write_bytes(tgz_data)


def find_tests(*test_subdirs):
Expand Down

0 comments on commit e97dc74

Please sign in to comment.