Skip to content

Commit cf1e649

Browse files
ahornbymeta-codesync[bot]
authored andcommitted
populate cache from base_retry
Summary: Enable cache upload for runs from base_retry on public commits Reviewed By: bigfootjon Differential Revision: D86308695 fbshipit-source-id: 1ebf1b18e89cc752634559e3c6041288d09b1358
1 parent f85dc4c commit cf1e649

4 files changed

Lines changed: 107 additions & 12 deletions

File tree

build/fbcode_builder/getdeps.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from getdeps.errors import TransientFailure
2323
from getdeps.fetcher import (
2424
file_name_is_cmake_file,
25+
is_public_commit,
2526
list_files_under_dir_newer_than_timestamp,
2627
SystemPackageFetcher,
2728
)
@@ -732,12 +733,13 @@ def run_project_cmd(self, args, loader, manifest):
732733

733734
# Only populate the cache from continuous build runs, and
734735
# only if we have a built_marker.
735-
if (
736-
not args.skip_upload
737-
and args.schedule_type == "continuous"
738-
and has_built_marker
739-
):
740-
cached_project.upload()
736+
if not args.skip_upload and has_built_marker:
737+
if args.schedule_type == "continuous":
738+
cached_project.upload()
739+
elif args.schedule_type == "base_retry":
740+
# Check if on public commit before uploading
741+
if is_public_commit(loader.build_opts):
742+
cached_project.upload()
741743
elif args.verbose:
742744
print("found good %s" % built_marker)
743745

@@ -856,9 +858,6 @@ def setup_project_cmd_parser(self, parser):
856858
dest="use_build_cache",
857859
help="Do not attempt to use the build cache.",
858860
)
859-
parser.add_argument(
860-
"--schedule-type", help="Indicates how the build was activated"
861-
)
862861
parser.add_argument(
863862
"--cmake-target",
864863
help=("Target for cmake build."),
@@ -944,9 +943,6 @@ def run_project_cmd(self, args, loader, manifest):
944943
)
945944

946945
def setup_project_cmd_parser(self, parser):
947-
parser.add_argument(
948-
"--schedule-type", help="Indicates how the build was activated"
949-
)
950946
parser.add_argument("--test-owner", help="Owner for testpilot")
951947
parser.add_argument("--filter", help="Only run the tests matching the regex")
952948
parser.add_argument(
@@ -1554,6 +1550,11 @@ def add_common_arg(*args, **kwargs):
15541550
"version of the archive with a different hash"
15551551
),
15561552
)
1553+
add_common_arg(
1554+
"--schedule-type",
1555+
nargs="?",
1556+
help="Indicates how the build was activated",
1557+
)
15571558

15581559
ap = argparse.ArgumentParser(
15591560
description="Get and build dependencies and projects", parents=[common_args]

build/fbcode_builder/getdeps/builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ def __init__(
703703
self.loader = loader
704704
if build_opts.shared_libs:
705705
self.defines["BUILD_SHARED_LIBS"] = "ON"
706+
self.defines["BOOST_LINK_STATIC"] = "OFF"
706707

707708
def _invalidate_cache(self) -> None:
708709
for name in [

build/fbcode_builder/getdeps/fetcher.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,97 @@ def get_fbsource_repo_data(build_options) -> FbsourceRepoData:
564564
return cached_data
565565

566566

567+
def is_public_commit(build_options) -> bool: # noqa: C901
568+
"""Check if the current commit is public (shipped/will be shipped to remote).
569+
570+
Works across git, sapling (sl), and hg repositories:
571+
- For hg/sapling: Uses 'phase' command to check if commit is public
572+
- For git: Checks if commit exists in remote branches
573+
574+
Returns True if public, False if draft/local-only or on error (conservative).
575+
"""
576+
# Use fbsource_dir if available (Meta internal), otherwise fall back to repo_root
577+
repo_dir = build_options.fbsource_dir or build_options.repo_root
578+
if not repo_dir:
579+
# No repository detected, be conservative
580+
return False
581+
582+
env = Env()
583+
env.set("HGPLAIN", "1")
584+
env_dict = dict(env.items())
585+
586+
try:
587+
# Try hg/sapling phase command first (works for both hg and sl)
588+
# Try 'sl' first as it's the preferred tool at Meta
589+
for cmd in [["sl", "phase", "-r", "."], ["hg", "phase", "-r", "."]]:
590+
try:
591+
output = (
592+
subprocess.check_output(
593+
cmd, cwd=repo_dir, env=env_dict, stderr=subprocess.DEVNULL
594+
)
595+
.decode("ascii")
596+
.strip()
597+
)
598+
# Output format: "hash: public" or "hash: draft"
599+
return "public" in output
600+
except (subprocess.CalledProcessError, FileNotFoundError):
601+
continue
602+
603+
# Try git if hg/sl didn't work
604+
try:
605+
# Detect the default branch for origin remote
606+
default_branch = None
607+
try:
608+
# Get the symbolic ref for origin/HEAD to find default branch
609+
output = (
610+
subprocess.check_output(
611+
["git", "symbolic-ref", "refs/remotes/origin/HEAD"],
612+
cwd=repo_dir,
613+
stderr=subprocess.DEVNULL,
614+
)
615+
.decode("ascii")
616+
.strip()
617+
)
618+
# Output format: "refs/remotes/origin/main"
619+
if output.startswith("refs/remotes/"):
620+
default_branch = output
621+
except subprocess.CalledProcessError:
622+
# If symbolic-ref fails, fall back to common names
623+
pass
624+
625+
# Build list of branches to check
626+
branches_to_check = []
627+
if default_branch:
628+
branches_to_check.append(default_branch)
629+
# Also try common defaults as fallback
630+
branches_to_check.extend(["origin/main", "origin/master"])
631+
632+
# Check if HEAD is an ancestor of any of these branches
633+
for branch in branches_to_check:
634+
try:
635+
subprocess.check_output(
636+
["git", "merge-base", "--is-ancestor", "HEAD", branch],
637+
cwd=repo_dir,
638+
stderr=subprocess.DEVNULL,
639+
)
640+
# If command succeeds (exit 0), HEAD is an ancestor of the branch
641+
return True
642+
except subprocess.CalledProcessError:
643+
# Not an ancestor of this branch, try next
644+
continue
645+
# HEAD is not in any default branch
646+
return False
647+
except FileNotFoundError:
648+
pass
649+
650+
# If all VCS commands failed, be conservative and don't upload
651+
return False
652+
653+
except Exception:
654+
# On any unexpected error, be conservative and don't upload
655+
return False
656+
657+
567658
class SimpleShipitTransformerFetcher(Fetcher):
568659
def __init__(self, build_options, manifest, ctx) -> None:
569660
self.build_options = build_options

build/fbcode_builder/manifests/folly

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ fbcode/folly = folly
6363

6464
[cmake.defines]
6565
BUILD_SHARED_LIBS=OFF
66+
67+
[cmake.defines.not(os=windows)]
6668
BOOST_LINK_STATIC=ON
6769

6870
[cmake.defines.os=freebsd]

0 commit comments

Comments
 (0)