Skip to content

Commit

Permalink
Subprojects support
Browse files Browse the repository at this point in the history
Summary:
X-link: facebookincubator/zstrong#857

Where one project should be checked out in a subdirectory of another
project. Like git submodules.

This is how the Glean build currently works: hsthrift is a separate
git repo, but Glean builds with hsthrift checked out in a
subdirectory.

Reviewed By: chadaustin

Differential Revision: D58055066

fbshipit-source-id: 1a22abaa8c5261c40b752d685a03d01625215b12
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Jun 3, 2024
1 parent f9c572b commit 45694fe
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
33 changes: 33 additions & 0 deletions build/fbcode_builder/getdeps/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,39 @@ def get_src_dir(self):
return self.repo_dir


class SubFetcher(Fetcher):
"""Fetcher for a project with subprojects"""

def __init__(self, base, subs) -> None:
self.base = base
self.subs = subs

def update(self) -> ChangeStatus:
base = self.base.update()
changed = base.build_changed() or base.sources_changed()
for fetcher, dir in self.subs:
stat = fetcher.update()
if stat.build_changed() or stat.sources_changed():
changed = True
link = self.base.get_src_dir() + "/" + dir
if not os.path.exists(link):
os.symlink(fetcher.get_src_dir(), link)
return ChangeStatus(changed)

def clean(self) -> None:
self.base.clean()
for fetcher, _ in self.subs:
fetcher.clean()

def hash(self) -> None:
hash = self.base.hash()
for fetcher, _ in self.subs:
hash += fetcher.hash()

def get_src_dir(self):
return self.base.get_src_dir()


class ShipitTransformerFetcher(Fetcher):
@classmethod
def _shipit_paths(cls, build_options):
Expand Down
2 changes: 1 addition & 1 deletion build/fbcode_builder/getdeps/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def create_fetcher(self, manifest):
return override

ctx = self.ctx_gen.get_context(manifest.name)
return manifest.create_fetcher(self.build_opts, ctx)
return manifest.create_fetcher(self.build_opts, self, ctx)

def get_project_hash(self, manifest):
h = self._project_hashes.get(manifest.name)
Expand Down
17 changes: 16 additions & 1 deletion build/fbcode_builder/getdeps/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
PreinstalledNopFetcher,
ShipitTransformerFetcher,
SimpleShipitTransformerFetcher,
SubFetcher,
SystemPackageFetcher,
)
from .py_wheel_builder import PythonWheelBuilder
Expand Down Expand Up @@ -105,6 +106,7 @@
"shipit.pathmap": {"optional_section": True},
"shipit.strip": {"optional_section": True},
"install.files": {"optional_section": True},
"subprojects": {"optional_section": True},
# fb-only
"sandcastle": {"optional_section": True, "fields": {"run_tests": OPTIONAL}},
}
Expand Down Expand Up @@ -396,7 +398,7 @@ def _is_satisfied_by_preinstalled_environment(self, ctx):
def get_repo_url(self, ctx):
return self.get("git", "repo_url", ctx=ctx)

def create_fetcher(self, build_options, ctx):
def _create_fetcher(self, build_options, ctx):
real_shipit_available = ShipitTransformerFetcher.available(build_options)
use_real_shipit = real_shipit_available and (
build_options.use_shipit
Expand Down Expand Up @@ -456,6 +458,19 @@ def create_fetcher(self, build_options, ctx):
"project %s has no fetcher configuration matching %s" % (self.name, ctx)
)

def create_fetcher(self, build_options, loader, ctx):
fetcher = self._create_fetcher(build_options, ctx)
subprojects = self.get_section_as_ordered_pairs("subprojects", ctx)
if subprojects:
subs = []
for project, subdir in subprojects:
submanifest = loader.load_manifest(project)
subfetcher = submanifest.create_fetcher(build_options, loader, ctx)
subs.append((subfetcher, subdir))
return SubFetcher(fetcher, subs)
else:
return fetcher

def get_builder_name(self, ctx):
builder = self.get("build", "builder", ctx=ctx)
if not builder:
Expand Down

0 comments on commit 45694fe

Please sign in to comment.