fuchsia笔记-代码下载

环境:Ubuntu18.04

官方提供的checkout命令

curl -s "https://fuchsia.googlesource.com/fuchsia/+/master/scripts/bootstrap?format=TEXT" | base64 --decode | bash

实际上是下载bootstrap脚本,并执行 

#!/bin/bash
# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

set -e

function usage {
  cat <

其中下载了另外一个bootstrap_jiri来声明一些环境变量

#!/usr/bin/env bash
# Copyright 2015 The Vanadium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

# bootstrap_jiri initializes a root directory for jiri.  The following
# directories and files will be created:
#                            - root directory (picked by user)
#   /.jiri_root              - root metadata directory
#   /.jiri_root/bin/jiri     - jiri binary
#
# The jiri sources are downloaded and built into a temp directory, which is
# always deleted when this script finishes.  The  is deleted on any
# failure.

set -euf -o pipefail

# Jiri repo, from which we will download the jiri script wrapper.
readonly JIRI_REPO_URL="https://fuchsia.googlesource.com/jiri"

# Google Storage bucket that contains prebuilt versions of jiri.
readonly GS_BUCKET_URL="https://fuchsia-build.storage.googleapis.com/jiri"

# fatal prints an error message, followed by the usage string, and then exits.
fatal() {
  usage='

Usage:
   bootstrap_jiri 

A typical bootstrap workflow looks like this:

$ curl -s https://fuchsia.googlesource.com/jiri/+/master/scripts/bootstrap_jiri?format=TEXT | base64 --decode | bash -s myroot
$ export PATH=myroot/.jiri_root/bin:$PATH
$ cd myroot
$ jiri import manifest https://example.com/manifest
$ jiri update'
  echo "ERROR: $@${usage}" 1>&2
  exit 1
}

readonly HOST_ARCH=$(uname -m)
if [ "$HOST_ARCH" == "aarch64" ]; then
  readonly ARCH="arm64"
elif [ "$HOST_ARCH" == "x86_64" ]; then
  readonly ARCH="amd64"
else
  echo "Arch not supported: $HOST_ARCH"
  exit 1
fi

# toabs converts the possibly relative argument into an absolute path.  Run in a
# subshell to avoid changing the caller's working directory.
toabs() (
  cd $(dirname $1)
  echo ${PWD}/$(basename $1)
)

# Check the  argument is supplied.
if [[ $# -ne 1 ]]; then
  fatal "need  argument"
fi

readonly ROOT_DIR="$(toabs $1)"
readonly BIN_DIR="${ROOT_DIR}/.jiri_root/bin"

# If ROOT_DIR doesn't already exist, we will destroy it during the exit trap,
# otherwise we will only destroy the BIN_DIR
if [[ -d "${ROOT_DIR}" ]]; then
  CLEANUP_DIR="${BIN_DIR}"
else
  CLEANUP_DIR="${ROOT_DIR}"
fi
mkdir -p "${BIN_DIR}"

# Remove the root_dir if this script fails so as to not leave the environment in a strange half-state.
trap "rm -rf -- \"${CLEANUP_DIR}\"" INT TERM EXIT

# Determine and validate the version of jiri.
readonly HOST_OS=$(uname | tr '[:upper:]' '[:lower:]')
readonly TARGET="${HOST_OS}-${ARCH}"
readonly COMMIT_URL="${JIRI_REPO_URL}/+refs/heads/master?format=JSON"
readonly LOG_URL="${JIRI_REPO_URL}/+log/refs/heads/master?format=JSON"
readonly VERSION=$(curl -sSf "${COMMIT_URL}" | sed -n 's/.*"value": "\([0-9a-f]\{40\}\)"/\1/p')
readonly VERSIONS=$(curl -sSf "${LOG_URL}" | sed -n 's/.*"commit": "\([0-9a-f]\{40\}\)".*/\1/p')

JIRI_URL=""
for version in ${VERSIONS}; do
  url="${GS_BUCKET_URL}/${TARGET}/${version}"
  if curl --output /dev/null --silent --head --fail "${url}"; then
    JIRI_URL="${url}"
	break
  fi
done

if [[ -z "${JIRI_URL}" ]]; then
  echo "Cannot find prebuilt Jiri binary." 1>&2
  exit 1
fi

if ! curl -sf -o "${BIN_DIR}/jiri" "${JIRI_URL}"; then
  echo "Failed downloading prebuilt Jiri binary." 1>&2
  exit 1
fi
chmod 755 "${BIN_DIR}/jiri"
if [ "$ARCH" == "arm64" ]; then
  echo "WARNING: Jiri doesn't support timely updates for arch '$HOST_ARCH'. This or future binaries of Jiri might be out of date."
fi

# Install cipd, which is frequently needed to use manifests.
pushd "${BIN_DIR}"
if ! "${BIN_DIR}/jiri" bootstrap cipd; then
  echo "Running jiri bootstrap failed." 1>&2
  popd
  exit 1
fi
popd

echo "Please add ${BIN_DIR} to your PATH"

trap - EXIT

 第一次下载遇到的错误:

Updating all projects
ERROR: Creating project "fuchsia": 'git fetch https://fuchsia.googlesource.com/fuchsia +refs/heads/*:refs/remotes/origin/*' failed:
stdout:

stderr:
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

command fail error: exit status 128

可能是网络问题,重新执行一次就好了。

还碰到了下面的错误:

Updating all projects
ERROR: context deadline exceeded

不清楚为什么,但是目录下代码已经同步完成。暂时忽略

下载时间比较长,可能会出问题,可以用shell脚本来update:

#! /bin/bash

# make_sure_update.sh

while true; do
	jiri update -v && break
done

 

把jiri声明到环境变量:

export PATH=$PATH:$(pwd)/.jiri_root/bin

之后就可以使用jiri update来更新代码。

 

如果下载失败,可以直接使用国内源码镜像,下载完整代码包:

https://mirrors.hexang.org/fuchsia/source-code/

https://fuchsia-china.com/fuchsia-source-code-china-mirror/

你可能感兴趣的:(fuchsia)