Repository navigation
ci(nightly): share compiler-cache settings between warmer, PR Release and nightly Release #30128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec881de
ci(nightly): share the managed fleet compiler-cache integration
teamleaderleo 79210d2
ci(cache): include shared settings in product and incremental identities
teamleaderleo 24b81a7
test(ci): keep fixture Unix sockets within the path limit
teamleaderleo 7bdeb6f
test(ci): register cache fixtures and classify cold-cache control
teamleaderleo beb297f
test(ci): run cache fixture directly in the existing guard step
teamleaderleo 14a5455
ci(cache): align warmer and PR Release settings
teamleaderleo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
| # Print one allowlisted Xcode setting per line. Shared by app-host admission | ||
| # and nightly Release builds; an absent or unhealthy managed CAS stays local. | ||
| set -euo pipefail | ||
|
|
||
| fleet_cache_setting=( | ||
| # Keep cache keys stable when a PR runner's checkout and DerivedData live | ||
| # under a different absolute root than the fleet CAS writer. | ||
| SWIFT_ENABLE_PREFIX_MAPPING=YES | ||
| CLANG_ENABLE_PREFIX_MAPPING=YES | ||
| SWIFT_ENABLE_PROJECT_PREFIX_MAPPING=YES | ||
| CLANG_ENABLE_PROJECT_PREFIX_MAPPING=YES | ||
| # Xcode 26.6 emits one bounded remark per cache query. The build metrics | ||
| # receipt turns those remarks into cacheable-task and hit counters. | ||
| COMPILATION_CACHE_ENABLE_DIAGNOSTIC_REMARKS=YES | ||
| ) | ||
| # Keep mapping and diagnostics when caching is disabled, as admission did. | ||
| if [ "${CMUX_CI_DISABLE_COMPILATION_CACHE:-}" != 1 ]; then | ||
| fleet_cas_root="${CMUX_FLEET_CAS_ROOT:-/Users/Shared/cmux-build-fleet/xcode}" | ||
| fleet_cas_settings="${CMUX_FLEET_CAS_SETTINGS:-$fleet_cas_root/bin/fleet-cas-settings.sh}" | ||
| fleet_cas_socket="${CMUX_FLEET_CAS_SOCKET:-$fleet_cas_root/fleet-cas.sock}" | ||
| if [ -x "$fleet_cas_settings" ] && [ -S "$fleet_cas_socket" ]; then | ||
| fleet_settings='' | ||
| fleet_settings="$("$fleet_cas_settings" "$fleet_cas_socket" 2>/dev/null | head -n 8)" || fleet_settings='' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The helper call has no timeout, so a hung fleet node blocks the build instead of falling back to local compilation. Bound the call with a timeout, and send its stderr to the build log instead of Prompt for AI agents |
||
| fleet_plugin_ok=0 | ||
| fleet_remote_ok=0 | ||
| while IFS= read -r setting; do | ||
| case "$setting" in | ||
| COMPILATION_CACHE_ENABLE_PLUGIN=YES) fleet_plugin_ok=1 ;; | ||
| COMPILATION_CACHE_REMOTE_SERVICE_PATH=/*) fleet_remote_ok=1 ;; | ||
| COMPILATION_CACHE_CAS_PATH=/*) ;; | ||
| esac | ||
| done <<< "$fleet_settings" | ||
| if [ "$fleet_plugin_ok" -eq 1 ] && [ "$fleet_remote_ok" -eq 1 ]; then | ||
| fleet_cache_setting+=("COMPILATION_CACHE_CAS_PATH=$fleet_cas_root/cas") | ||
| while IFS= read -r setting; do | ||
| case "$setting" in | ||
| COMPILATION_CACHE_ENABLE_PLUGIN=YES|COMPILATION_CACHE_REMOTE_SERVICE_PATH=/*) | ||
| fleet_cache_setting+=("$setting") | ||
| ;; | ||
| esac | ||
| done <<< "$fleet_settings" | ||
| fi | ||
| fi | ||
| fi | ||
| printf '%s\n' "${fleet_cache_setting[@]}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #!/usr/bin/env python3 | ||
| """Exercise managed CAS settings and the nightly's emitted Xcode command.""" | ||
| import json | ||
| import os | ||
| from pathlib import Path | ||
| import shutil | ||
| import socket | ||
| import subprocess | ||
| import tempfile | ||
| import unittest | ||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
| SETTINGS = ROOT / "scripts/ci/fleet-compilation-cache.sh" | ||
|
|
||
|
|
||
| class FleetCacheTests(unittest.TestCase): | ||
| def setUp(self): | ||
| # Runner TMPDIR may exceed sockaddr_un's ~100-byte pathname limit. | ||
| self.scratch = tempfile.TemporaryDirectory(prefix="fleet-cas-", dir="/tmp") | ||
| self.addCleanup(self.scratch.cleanup) | ||
| self.root = Path(self.scratch.name) | ||
| self.cache = self.root / "cache with spaces" | ||
| self.cache.mkdir() | ||
| self.sock = socket.socket(socket.AF_UNIX) | ||
| self.addCleanup(self.sock.close) | ||
| self.sock.bind(str(self.cache / "fleet-cas.sock")) | ||
| self.helper = self.cache / "settings.sh" | ||
| self.env = {**os.environ, "CMUX_FLEET_CAS_ROOT": str(self.cache), | ||
| "CMUX_FLEET_CAS_SETTINGS": str(self.helper), | ||
| "CMUX_FLEET_CAS_SOCKET": str(self.cache / "fleet-cas.sock"), | ||
| "CMUX_CI_DISABLE_COMPILATION_CACHE": ""} | ||
| self.helper.write_text('#!/bin/bash\nprintf "%s\\n" COMPILATION_CACHE_ENABLE_PLUGIN=YES ' | ||
| '"COMPILATION_CACHE_REMOTE_SERVICE_PATH=$1" ' | ||
| 'COMPILATION_CACHE_CAS_PATH=/untrusted ' | ||
| 'OTHER_SWIFT_FLAGS=-unsafe\n') | ||
| self.helper.chmod(0o755) | ||
|
|
||
| def settings(self): | ||
| return subprocess.check_output(["bash", str(SETTINGS)], env=self.env, text=True).splitlines() | ||
|
|
||
| def assert_local(self): | ||
| settings = self.settings() | ||
| self.assertIn("SWIFT_ENABLE_PREFIX_MAPPING=YES", settings) | ||
| self.assertIn("CLANG_ENABLE_PROJECT_PREFIX_MAPPING=YES", settings) | ||
| self.assertFalse(any("REMOTE_SERVICE" in s or "CAS_PATH=" in s or "ENABLE_PLUGIN" in s for s in settings)) | ||
|
|
||
| def test_healthy_node_uses_fixed_cas_and_filters_helper_settings(self): | ||
| settings = self.settings() | ||
| self.assertIn(f"COMPILATION_CACHE_CAS_PATH={self.cache}/cas", settings) | ||
| self.assertIn(f"COMPILATION_CACHE_REMOTE_SERVICE_PATH={self.cache}/fleet-cas.sock", settings) | ||
| self.assertNotIn("COMPILATION_CACHE_CAS_PATH=/untrusted", settings) | ||
| self.assertNotIn("OTHER_SWIFT_FLAGS=-unsafe", settings) | ||
|
|
||
| def test_missing_socket_keeps_local_cache(self): | ||
| self.env["CMUX_FLEET_CAS_SOCKET"] = str(self.root / "absent.sock") | ||
| self.assert_local() | ||
|
|
||
| def test_failed_helper_keeps_local_cache(self): | ||
| self.helper.write_text("#!/bin/bash\nexit 1\n") | ||
| self.assert_local() | ||
|
|
||
| def test_partial_response_keeps_local_cache(self): | ||
| self.helper.write_text("#!/bin/bash\necho COMPILATION_CACHE_ENABLE_PLUGIN=YES\n") | ||
| self.assert_local() | ||
|
|
||
| def test_disabled_cache_never_probes_node(self): | ||
| self.env["CMUX_CI_DISABLE_COMPILATION_CACHE"] = "1" | ||
| marker = self.root / "probed" | ||
| self.helper.write_text(f"#!/bin/bash\ntouch '{marker}'\n") | ||
| self.assert_local() | ||
| self.assertFalse(marker.exists()) | ||
|
|
||
| def test_nightly_xcode_command_receives_shared_settings(self): | ||
| # Execute the workflow's actual compile command through tiny pass-through | ||
| # wrappers. No Xcode or compiler runs; the last executable records argv. | ||
| workflow = (ROOT / ".github/workflows/nightly.yml").read_text() | ||
| step = workflow.split(" - name: Build nightly app (Release)\n", 1)[1].split(" - name:", 1)[0] | ||
| command = step[step.index(" fleet_cache_settings=()") :] | ||
| command = "\n".join(line[10:] for line in command.splitlines() if line.startswith(" ")) | ||
| command = command.replace("${{ needs.decide.outputs.cold_cache == 'true' && '1' || '' }}", "") | ||
| scripts = self.root / "scripts/ci" | ||
| scripts.mkdir(parents=True) | ||
| shutil.copyfile(SETTINGS, scripts / SETTINGS.name) | ||
| (scripts / "run-with-helper-prebuild.py").write_text( | ||
| "import os,sys\na=sys.argv[sys.argv.index('--')+1:]\nos.execvp(a[0],a)\n") | ||
| wrapper = scripts / "run-xcodebuild-with-diagnostics.sh" | ||
| wrapper.write_text('#!/bin/bash\nshift\nexec "$@"\n') | ||
| wrapper.chmod(0o755) | ||
| xcode = self.root / "xcodebuild" | ||
| xcode.write_text('#!/usr/bin/env python3\nimport json,sys\nprint(json.dumps(sys.argv[1:]))\n') | ||
| xcode.chmod(0o755) | ||
| env = {**self.env, "PATH": str(self.root) + os.pathsep + self.env["PATH"], | ||
| "RUNNER_TEMP": str(self.root), "CHANNEL_ICON_NAME": "AppIcon-Nightly"} | ||
| result = subprocess.run(["bash", "-euc", 'archs=arm64; only_active=YES; notary_test_flags=(build)\n' + command], | ||
| cwd=self.root, env=env, text=True, capture_output=True, check=True) | ||
| args = json.loads(result.stdout) | ||
| self.assertIn(f"COMPILATION_CACHE_CAS_PATH={self.cache}/cas", args) | ||
| self.assertIn("COMPILATION_CACHE_ENABLE_PLUGIN=YES", args) | ||
| self.assertIn("SWIFT_ENABLE_PROJECT_PREFIX_MAPPING=YES", args) | ||
| self.assertIn("CODE_SIGNING_ALLOWED=NO", args) | ||
| self.assertEqual(args[-1], "build") | ||
|
|
||
| def test_warmer_and_pr_release_use_the_same_cache_settings(self): | ||
| nightly = (ROOT / ".github/workflows/nightly.yml").read_text() | ||
| ci_macos = (ROOT / ".github/workflows/ci-macos.yml").read_text() | ||
| warmer = nightly.split(" - name: Refresh universal nightly compilation cache\n", 1)[1].split(" - name:", 1)[0] | ||
| release = ci_macos.split(" - name: Build app (Release)\n", 1)[1].split(" - name:", 1)[0] | ||
| for step in (warmer, release): | ||
| self.assertIn("bash scripts/ci/fleet-compilation-cache.sh", step) | ||
| self.assertIn('"${fleet_cache_settings[@]}"', step) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: A failing
fleet-compilation-cache.shis ignored here, so the build continues without the prefix-mapping and diagnostic settings and gets silent cache misses. Capture the output with a plain assignment soset -estops the build on helper failure.Prompt for AI agents