Skip to content

Commit

Permalink
Add debug command
Browse files Browse the repository at this point in the history
Summary:
Starts a shell in the build dir, with the environment set up in the
same way as for the build. Useful for experimenting and testing.

Reviewed By: chadaustin

Differential Revision: D58082246

fbshipit-source-id: 82b275401528d7616c2560d80b4c187de67f6032
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Jun 4, 2024
1 parent 60d4573 commit a8987ee
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 35 deletions.
88 changes: 53 additions & 35 deletions build/fbcode_builder/getdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,31 @@ def setup_parser(self, parser):
def setup_project_cmd_parser(self, parser):
pass

# For commands that don't build but need the full list of install_dirs from
# dependencies (test, debug).
def get_install_dirs(self, loader, manifest):
install_dirs = []
for m in loader.manifests_in_dependency_order():
if m != manifest:
install_dirs.append(loader.get_project_install_dir(m))
return install_dirs

def create_builder(self, loader, manifest):
fetcher = loader.create_fetcher(manifest)
src_dir = fetcher.get_src_dir()
ctx = loader.ctx_gen.get_context(manifest.name)
build_dir = loader.get_project_build_dir(manifest)
inst_dir = loader.get_project_install_dir(manifest)
return manifest.create_builder(
loader.build_opts, src_dir, build_dir, inst_dir, ctx, loader
)

def check_built(self, loader, manifest):
built_marker = os.path.join(
loader.get_project_install_dir(manifest), ".built-by-getdeps"
)
return os.path.exists(built_marker)


class CachedProject(object):
"""A helper that allows calling the cache logic for a project
Expand Down Expand Up @@ -855,41 +880,20 @@ def setup_project_cmd_parser(self, parser):
@cmd("test", "test a given project")
class TestCmd(ProjectCmdBase):
def run_project_cmd(self, args, loader, manifest):
projects = loader.manifests_in_dependency_order()

# Accumulate the install directories so that the test steps
# can find their dep installation
install_dirs = []

for m in projects:
inst_dir = loader.get_project_install_dir(m)

if m == manifest or args.test_dependencies:
built_marker = os.path.join(inst_dir, ".built-by-getdeps")
if not os.path.exists(built_marker):
print("project %s has not been built" % m.name)
# TODO: we could just go ahead and build it here, but I
# want to tackle that as part of adding build-for-test
# support.
return 1
fetcher = loader.create_fetcher(m)
src_dir = fetcher.get_src_dir()
ctx = loader.ctx_gen.get_context(m.name)
build_dir = loader.get_project_build_dir(m)
builder = m.create_builder(
loader.build_opts, src_dir, build_dir, inst_dir, ctx, loader
)

builder.run_tests(
install_dirs,
schedule_type=args.schedule_type,
owner=args.test_owner,
test_filter=args.filter,
retry=args.retry,
no_testpilot=args.no_testpilot,
)

install_dirs.append(inst_dir)
if not self.check_built(loader, manifest):
print("project %s has not been built" % manifest.name)
return 1
builder = self.create_builder(loader, manifest)
install_dirs = self.get_install_dirs(loader, manifest)

builder.run_tests(
install_dirs,
schedule_type=args.schedule_type,
owner=args.test_owner,
test_filter=args.filter,
retry=args.retry,
no_testpilot=args.no_testpilot,
)

def setup_project_cmd_parser(self, parser):
parser.add_argument(
Expand All @@ -911,6 +915,20 @@ def setup_project_cmd_parser(self, parser):
)


@cmd(
"debug",
"start a shell in the given project's build dir with the correct environment for running the build",
)
class DebugCmd(ProjectCmdBase):
def run_project_cmd(self, args, loader, manifest):
if not self.check_built(loader, manifest):
print("project %s has not been built" % manifest.name)
return 1
install_dirs = self.get_install_dirs(loader, manifest)
builder = self.create_builder(loader, manifest)
builder.debug(install_dirs, reconfigure=False)


@cmd("generate-github-actions", "generate a GitHub actions configuration")
class GenerateGitHubActionsCmd(ProjectCmdBase):
RUN_ON_ALL = """ [push, pull_request]"""
Expand Down
10 changes: 10 additions & 0 deletions build/fbcode_builder/getdeps/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ def prepare(self, install_dirs, reconfigure: bool) -> None:
self._apply_patchfile()
self._prepare(install_dirs=install_dirs, reconfigure=reconfigure)

def debug(self, install_dirs, reconfigure: bool) -> None:
reconfigure = self._reconfigure(reconfigure)
self._apply_patchfile()
self._prepare(install_dirs=install_dirs, reconfigure=reconfigure)
env = self._compute_env(install_dirs)
print("Starting a shell in %s, ^D to exit..." % self.build_dir)
# TODO: print the command to run the build
shell = ["powershell.exe"] if sys.platform == "win32" else ["/bin/sh", "-i"]
self._run_cmd(shell, cwd=self.build_dir, env=env)

def build(self, install_dirs, reconfigure: bool) -> None:
print("Building %s..." % self.manifest.name)
reconfigure = self._reconfigure(reconfigure)
Expand Down

0 comments on commit a8987ee

Please sign in to comment.