Skip to content

Commit

Permalink
Use codesync from fbcode if /var/www is not available (#855)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: facebookincubator/zstrong#855

Reviewed By: chadaustin

Differential Revision: D58055452

fbshipit-source-id: a58817e6e81db73462947f8dc286eaacb7e18c54
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Jun 3, 2024
1 parent d1b6bad commit f5e4e9c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
28 changes: 24 additions & 4 deletions build/fbcode_builder/getdeps/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,29 @@ def get_src_dir(self):


class ShipitTransformerFetcher(Fetcher):
SHIPIT = "/var/www/scripts/opensource/codesync"
@classmethod
def _shipit_paths(cls, build_options):
www_path = ["/var/www/scripts/opensource/codesync"]
if build_options.fbsource_dir:
fbcode_path = [
os.path.join(
build_options.fbsource_dir,
"fbcode/opensource/codesync/codesync-cli/codesync",
)
]
else:
fbcode_path = []
return www_path + fbcode_path

def __init__(self, build_options, project_name) -> None:
self.build_options = build_options
self.project_name = project_name
self.repo_dir = os.path.join(build_options.scratch_dir, "shipit", project_name)
self.shipit = None
for path in ShipitTransformerFetcher._shipit_paths(build_options):
if os.path.exists(path):
self.shipit = path
break

def update(self) -> ChangeStatus:
if os.path.exists(self.repo_dir):
Expand All @@ -606,8 +623,11 @@ def clean(self) -> None:
shutil.rmtree(self.repo_dir)

@classmethod
def available(cls):
return os.path.exists(cls.SHIPIT)
def available(cls, build_options):
return any(
os.path.exists(path)
for path in ShipitTransformerFetcher._shipit_paths(build_options)
)

def run_shipit(self) -> None:
tmp_path = self.repo_dir + ".new"
Expand All @@ -619,7 +639,7 @@ def run_shipit(self) -> None:
# Run shipit
run_cmd(
[
ShipitTransformerFetcher.SHIPIT,
self.shipit,
"shipit",
"--project=" + self.project_name,
"--create-new-repo",
Expand Down
5 changes: 3 additions & 2 deletions build/fbcode_builder/getdeps/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ def get_repo_url(self, ctx):
return self.get("git", "repo_url", ctx=ctx)

def create_fetcher(self, build_options, ctx):
use_real_shipit = ShipitTransformerFetcher.available() and (
real_shipit_available = ShipitTransformerFetcher.available(build_options)
use_real_shipit = real_shipit_available and (
build_options.use_shipit
or self.get("manifest", "use_shipit", defval="false", ctx=ctx) == "true"
)
Expand All @@ -413,7 +414,7 @@ def create_fetcher(self, build_options, ctx):
self.fbsource_path
and build_options.fbsource_dir
and self.shipit_project
and ShipitTransformerFetcher.available()
and real_shipit_available
):
# We can use the code from fbsource
return ShipitTransformerFetcher(build_options, self.shipit_project)
Expand Down

0 comments on commit f5e4e9c

Please sign in to comment.