Skip to content

Commit

Permalink
[orion-builder] Test patch to fix taskboot clone of PR
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwartzentruber committed Dec 1, 2021
1 parent 1dfd634 commit 44a031a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion services/orion-builder/src/orion_builder/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
"""CLI for Orion builder/build script"""
import logging
import subprocess
import sys
from os import getenv
from pathlib import Path
Expand All @@ -14,6 +16,38 @@
from .cli import CommonArgs, configure_logging
from .stage_deps import stage_deps

logger = logging.getLogger(__name__)


class PatchedTarget(Target):
def clone(self, repository, revision):
logger.info("Cloning {} @ {}".format(repository, revision))

# Clone
cmd = ["git", "clone", "--quiet", repository, self.dir]
subprocess.check_output(cmd)
logger.info("Cloned into {}".format(self.dir))

# Explicitly fetch revision if it isn't present
# This is necessary when revision is from a fork and repository
# is the base repo (eg. private repo).
if (
subprocess.run(
["git", "show", revision],
cwd=self.dir,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode
!= 0
):
cmd = ["git", "fetch", "--quiet", "origin", revision]
subprocess.check_output(cmd, cwd=self.dir)

# Checkout revision to pull modifications
cmd = ["git", "checkout", revision, "-b", "taskboot"]
subprocess.check_output(cmd, cwd=self.dir)
logger.info("Checked out revision {}".format(revision))


class BuildArgs(CommonArgs):
"""CLI arguments for Orion builder"""
Expand Down Expand Up @@ -99,7 +133,7 @@ def main(argv=None):
"""Build entrypoint. Does not return."""
args = BuildArgs.parse_args(argv)
configure_logging(level=args.log_level)
target = Target(args)
target = PatchedTarget(args)
if args.load_deps:
stage_deps(target, args)
try:
Expand Down

0 comments on commit 44a031a

Please sign in to comment.