Пример #1
0
def build(args):
    """Build the code."""
    if not args.src_dir:
        logging.info("--src_dir not set")
        args.src_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), ".."))
    logging.info("Use --src_dir=%s", args.src_dir)

    go_dir = os.getenv("GOPATH")
    if not go_dir:
        raise ValueError("Environment variable GOPATH must be set.")

    go_src_dir = os.path.join(go_dir, "src", "github.com", REPO_ORG, REPO_NAME)

    if not os.path.exists(go_src_dir):
        logging.info("%s does not exist.", go_src_dir)

        # Create a symbolic link in the go path.
        parent_dir = os.path.dirname(go_src_dir)
        if not os.path.exists(parent_dir):
            os.makedirs(parent_dir)
        logging.info("Creating symbolic link %s pointing to %s", go_src_dir,
                     args.src_dir)
        os.symlink(args.src_dir, go_src_dir)

    # Check that the directory in the go src path correctly points to
    # the same directory as args.src_dir
    if os.path.islink(go_src_dir):
        target = os.path.realpath(go_src_dir)

        if target != args.src_dir:
            message = "{0} is a symbolic link to {1}; but --src_dir={2}".format(
                go_src_dir, target, args.src_dir)
            logging.error(message)
            raise ValueError(message)
    elif go_src_dir != args.src_dir:
        message = "{0} doesn't equal --src_dir={1}".format(
            go_src_dir, args.src_dir)
        logging.error(message)
        raise ValueError(message)

    vendor_dir = os.path.join(args.src_dir, "vendor")
    if not os.path.exists(vendor_dir):
        logging.info("Installing go dependencies")
        util.install_go_deps(args.src_dir)
    else:
        logging.info(
            "vendor directory exists; not installing go dependencies.")

    # TODO(jlewi): We can stop passing go_dir because we not rely on go_dir
    # being set in the environment.
    build_and_push(go_dir, args.src_dir, args)
Пример #2
0
def build_commit(args, branches):
  top_dir = args.src_dir or tempfile.mkdtemp(prefix="tmpTFJobSrc")
  logging.info("Top level directory for source: %s", top_dir)

  go_dir = os.path.join(top_dir, "go")
  os.environ["GOPATH"] = go_dir
  logging.info("Temporary go_dir: %s", go_dir)

  clone_dir = os.path.join(top_dir, REPO_DIR)
  src_dir = os.path.join(go_dir, "src", "github.com", REPO_ORG, REPO_NAME)

  util.clone_repo(clone_dir, REPO_ORG, REPO_NAME, args.commit, branches)

  # Create a symbolic link in the go path.
  os.makedirs(os.path.dirname(src_dir))
  logging.info("Creating symbolic link %s pointing to %s", src_dir, clone_dir)
  os.symlink(clone_dir, src_dir)
  util.install_go_deps(clone_dir)
  build_and_push(go_dir, src_dir, args)