fuchsia代码管理

google官方讲述代码获取的说明文档路径如下:https://fuchsia.googlesource.com/docs/+/ea2fce2874556205204d3ef70c60e25074dc7ffd/development/source_code/README.md。使用如下以curl开始的命令组合,最后部分的layer可以指定为topaz、peridot和garnet,或者指定仅下载操作系统代码zircon。

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

为方便起见,此处不指定layer参数,下载全部的fuchsia代码。所需时间与网速有很大关系,没有做计算,我是晚上开始下载,第二天早起看已经下载完成。

$ curl -s "https://fuchsia.googlesource.com/fuchsia/+/master/scripts/bootstrap?format=TEXT" | base64 --decode | bash
~/fuchsia/.jiri_root/bin ~
cipd bootstrapped to path:"/home/kai/fuchsia/.jiri_root/bin/cipd"
~
Please add /home/kai/fuchsia/.jiri_root/bin to your PATH

Updating all projects
Done creating a Platform Source Tree at "/home/kai/fuchsia".
Recommended: export PATH="/home/kai/fuchsia/.jiri_root/bin:$PATH"

首先curl命令下载网址https://fuchsia.googlesource.com/fuchsia/+/master/scripts/bootstrap?format=TEXT中的文件,也可以在浏览器中输入此网址,通过浏览器进行下载,文件名为bootstrap.txt,其内容为base64编码。以下通过curl命令下载,内容打印在终端上(内容有省略):

$ curl  "https://fuchsia.googlesource.com/fuchsia/+/master/scripts/bootstrap?format=TEXT"  
IyEvYmluL2Jhc2gKIyBDb3B5cmlnaHQgMjAxNyBUaGUgRnVjaHNpYSBBdXRob3JzLiBBbGwgcmlnaHRzIHJlc2VydmVkLgojIFVzZSBvZiB0........
$ 

 

使用工具base64解码bootstrap.txt文件,解码之后为bash脚本文件,内容如下(省略了一些非关键内容)。由脚本中的注释可知,其将下载一个新的名称为bootstrap_jiri.txt的脚本,由新脚本完成fuchsia目录的创建,以及下载jiri工具到目录"fuchsia/.jiri_root/bin"中。jiri工具可同时管理多个git代码仓库,包括同步、代码恢复等功能,Fuchsia正是使用jiri管理其代码仓库。

关于bootstrap_jiri.txt脚本稍后介绍。

$ cat bootstrap.txt | base64 --decode
#!/bin/bash

# The fetched script will
# - create "fuchsia" directory if it does not exist,
# - download "jiri" command to "fuchsia/.jiri_root/bin"
curl -s "https://fuchsia.googlesource.com/jiri/+/master/scripts/bootstrap_jiri?format=TEXT" | base64 --decode | bash -s fuchsia
cd fuchsia

.jiri_root/bin/jiri import -name=integration flower https://fuchsia.googlesource.com/integration
.jiri_root/bin/jiri override fuchsia https://fuchsia.googlesource.com/fuchsia
.jiri_root/bin/jiri update

echo "Done creating a Platform Source Tree at \"$(pwd)\"."
echo "Recommended: export PATH=\"$(pwd)/.jiri_root/bin:\$PATH\""

 

之后,使用jiri命令在fuchsia目录下创建其manifest文件 .jiri_manifest。其内容如下。jiri update命令执行时,将同步manifest文件中指定的工程(代码仓库)。此处显式指定了一个工程project,名称为fuchsia,代码仓库地址为:"https://fuchsia.googlesource.com/fuchsia",并且其使用了overrides标签,意味着其将替换已有同名的工程,仅在根manifest文件中允许此标签。

~/fuchsia$ cat .jiri_manifest 

  
    
  
  
    
  

~/fuchsia$ 

 

另外,在文件中引入了另外一个manifest文件,其仓库地址为"https://fuchsia.googlesource.com/integration",下载之后,内容如下:

~/fuchsia$ cat integration/flower 


  
    
    
    
    
    
  
  
    
  

~/fuchsia$ 

 

在此仓库中,有已下载的manifest文件:minimal、stem、third_party/flower、topaz/minimal和topaz/third_party。如下所以。由于manifest文件的嵌套,最终,会包含非常多的project(代码仓库)进来。
 

~/fuchsia$ ls integration/
flower  garnet  infra  jiri.lock  minimal  peridot  prebuilts  README.md  stem  third_party  topaz  zircon
~/fuchsia$ 

 

可使用如下的jiri project命令查看包含的工程情况。如下fuchsia总共包含有182个代码仓库。

~/fuchsia$ .jiri_root/bin/jiri project
* project canonical-json-go
  Path:     /home/kai/fuchsia/third_party/golibs/github.com/tent/canonical-json-go
  Remote:   https://fuchsia.googlesource.com/third_party/canonical-json-go
  Revision: 96e4ba3a7613a1216cbd1badca4efe382adea337
  Branches: none
* project cobalt
  Path:     /home/kai/fuchsia/third_party/cobalt
  Remote:   https://fuchsia.googlesource.com/cobalt
  Revision: 83d0db4528c0a36b14d54f34d7dbbd516c1184b0
  Branches: none
  ...
~/fuchsia$
~/fuchsia$ .jiri_root/bin/jiri project | grep project | wc -l
182
~/fuchsia$ 

 


最后,运行jiri update命令,同步所有指定的代码仓库。


来看一下bootstrap_jiri.txt脚本的功能。如下curl命令获取其内容,使用base64工具解码。有文件注释可知,此脚本将创建fuchsia目录,以及其下子目录.jiri_root和.jiri_root/bin/jiri命令二进制执行文件。jiri自身的代码仓库位于地址:https://fuchsia.googlesource.com/jiri。

$ curl -s https://fuchsia.googlesource.com/jiri/+/master/scripts/bootstrap_jiri?format=TEXT | base64 --decode
$ 
#!/usr/bin/env bash

# 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"

以下脚本内容,使用uname命令获取本机的ARCH处理器架构,由于使用的为intel处理器,uname -m命令的输出为x86_64,ARCH赋值为amd64。并且使用mkdir命令创建bin目录,由于指定了-p选项,连带的将根目录fuchsia和其子目录.jiri_root创建了出来。

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)
)

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

mkdir -p "${BIN_DIR}"

 

其中,由于使用的是Ubuntu系统,HOST_OS的值为linux,所以TARGET变量为linux-amd64。首先使用curl命令获取jiri代码仓库的最新提交commit ID版本号,但是随后并没有使用此版本号。之后使用curl获取jiri代码仓库的提交日志信息,此次将获取到一个版本号数组(每次提交commit将产生一个commit id版本)。最后,循环遍历VERSIONS数组中的每个版本号,与TARGET和GS_BUCKET_URL变量值(即预编译的jiri工具的保存路径)组合为一个URL,使用curl检查此url是否存在。存在的话,将jiri二进制文件下载到目录"${BIN_DIR}/jiri"中。

# 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
100  5004    0  5004    0     0    574      0 --:--:--  0:00:08 --:--:--  1195
}"
        break
  fi
done

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"

 

例如JIRI_URL=https://fuchsia-build.storage.googleapis.com/jiri/linux-amd64/e0c5efcc7081e09845f3f17944fceb6ff179b981。最后,使用命令jiri bootstrap cipd下载cipd二进制程序。

# 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
$ 

 

END

 

你可能感兴趣的:(fuchsia)