Skip to content

Commit

Permalink
allow getdeps github actions to free up disk (facebookincubator#6927)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookincubator#6927

allow getdeps github actions to free up disk

Allow getdeps to free up some disk from the runner and intermediate build steps as some runs (notably the linux eden and mononoke ones) are hitting disk space limits

X-link: facebook/sapling#689

Test Plan:
Regenerate and run CI for mononoke.   Mononoke Mac should continue to work Mononoke Linux should go from broken to working
```
./build/fbcode_builder/getdeps.py --allow-system-packages generate-github-actions --free-up-disk --src-dir=.  --output-dir=.github/workflows --job-name="Mononoke " --job-file-prefix=mononoke_ mononoke
```

 ---
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/sapling/pull/689).
* facebook/sapling#693
* facebook/sapling#696
* facebook/sapling#692
* facebook/sapling#691
* facebook/sapling#682
* __->__ facebook/sapling#689
* facebook/sapling#697
* facebook/sapling#706
* facebook/sapling#730

Reviewed By: sggutier

Differential Revision: D49875256

Pulled By: genevievehelsel

fbshipit-source-id: 251f21866c16310c34280ea112710767fdfbb1a4
  • Loading branch information
ahornby authored and facebook-github-bot committed Oct 6, 2023
1 parent 117b10d commit 2dee554
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
30 changes: 29 additions & 1 deletion build/fbcode_builder/getdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,12 @@ def setup_project_cmd_parser(self, parser):
action="store_true",
default=False,
)
parser.add_argument(
"--free-up-disk",
help="Remove unused tools and clean up intermediate files if possible to maximise space for the build",
action="store_true",
default=False,
)


@cmd("fixup-dyn-deps", "Adjusts dynamic dependencies for packaging purposes")
Expand Down Expand Up @@ -1015,6 +1021,19 @@ def write_job_for_platform(self, platform, args): # noqa: C901

out.write(" - uses: actions/checkout@v2\n")

if build_opts.free_up_disk:
free_up_disk = "--free-up-disk "
if not build_opts.is_windows():
out.write(" - name: Show disk space at start\n")
out.write(" run: df -h\n")
# remove the unused github supplied android dev tools
out.write(" - name: Free up disk space\n")
out.write(" run: sudo rm -rf /usr/local/lib/android\n")
out.write(" - name: Show disk space after freeing up\n")
out.write(" run: df -h\n")
else:
free_up_disk = ""

allow_sys_arg = ""
if (
build_opts.allow_system_packages
Expand Down Expand Up @@ -1065,7 +1084,7 @@ def write_job_for_platform(self, platform, args): # noqa: C901
has_same_repo_dep = True
out.write(" - name: Build %s\n" % m.name)
out.write(
f" run: {getdepscmd}{allow_sys_arg} build {src_dir_arg}--no-tests {m.name}\n"
f" run: {getdepscmd}{allow_sys_arg} build {src_dir_arg}{free_up_disk}--no-tests {m.name}\n"
)

out.write(" - name: Build %s\n" % manifest.name)
Expand Down Expand Up @@ -1111,6 +1130,9 @@ def write_job_for_platform(self, platform, args): # noqa: C901
out.write(
f" run: {getdepscmd}{allow_sys_arg} test --src-dir=. {manifest.name} {project_prefix}\n"
)
if build_opts.free_up_disk and not build_opts.is_windows():
out.write(" - name: Show disk space at end\n")
out.write(" run: df -h\n")

def setup_project_cmd_parser(self, parser):
parser.add_argument(
Expand Down Expand Up @@ -1155,6 +1177,12 @@ def setup_project_cmd_parser(self, parser):
help="add a prefix to all job names",
default=None,
)
parser.add_argument(
"--free-up-disk",
help="Remove unused tools and clean up intermediate files if possible to maximise space for the build",
action="store_true",
default=False,
)


def get_arg_var_name(args):
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 @@ -136,6 +136,16 @@ def build(self, install_dirs, reconfigure: bool) -> None:
self._prepare(install_dirs=install_dirs, reconfigure=reconfigure)
self._build(install_dirs=install_dirs, reconfigure=reconfigure)

if self.build_opts.free_up_disk:
# don't clean --src-dir=. case as user may want to build again or run tests on the build
if self.src_dir.startswith(self.build_opts.scratch_dir) and os.path.isdir(
self.build_dir
):
if os.path.islink(self.build_dir):
os.remove(self.build_dir)
else:
shutil.rmtree(self.build_dir)

# On Windows, emit a wrapper script that can be used to run build artifacts
# directly from the build directory, without installing them. On Windows $PATH
# needs to be updated to include all of the directories containing the runtime
Expand Down
4 changes: 4 additions & 0 deletions build/fbcode_builder/getdeps/buildopts.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
lfs_path=None,
shared_libs: bool = False,
facebook_internal=None,
free_up_disk: bool = False,
) -> None:
"""fbcode_builder_dir - the path to either the in-fbsource fbcode_builder dir,
or for shipit-transformed repos, the build dir that
Expand All @@ -65,6 +66,7 @@ def __init__(
use_shipit - use real shipit instead of the simple shipit transformer
vcvars_path - Path to external VS toolchain's vsvarsall.bat
shared_libs - whether to build shared libraries
free_up_disk - take extra actions to save runner disk space
"""

if not install_dir:
Expand Down Expand Up @@ -103,6 +105,7 @@ def __init__(
self.allow_system_packages = allow_system_packages
self.lfs_path = lfs_path
self.shared_libs = shared_libs
self.free_up_disk = free_up_disk

lib_path = None
if self.is_darwin():
Expand Down Expand Up @@ -602,6 +605,7 @@ def setup_build_options(args, host_type=None) -> BuildOptions:
"allow_system_packages",
"lfs_path",
"shared_libs",
"free_up_disk",
}
}

Expand Down

0 comments on commit 2dee554

Please sign in to comment.