Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

[インデックス 11615] ファイルの概要

このコミットは、Go言語のビルドシステムにおいて、従来のシェルスクリプトベースのビルドプロセスを、cmd/distという新しい内部ツールを使用するように移行するものです。これにより、ビルドプロセスの合理化、堅牢性の向上、およびメンテナンスの容易化が図られています。特に、Goの自己ホスト型ビルドプロセスにおける重要な変更であり、Goディストリビューションのブートストラップ、ビルド、テストの方法に影響を与えます。

コミット

  • コミットハッシュ: 829053686478c980b122bb7b255354f8c64ef0bd
  • Author: Russ Cox rsc@golang.org
  • Date: Sat Feb 4 00:54:08 2012 -0500

GitHub上でのコミットページへのリンク

https://github.com/golang/go/commit/829053686478c980b122bb7b255354f8c64ef0bd

元コミット内容

    build: use cmd/dist
    
    R=bradfitz, ality, r, r, iant, mikioh.mikioh
    CC=golang-dev
    https://golang.org/cl/5615058

変更の背景

Go言語の初期のビルドシステムは、主にbashスクリプトとmakeファイルに依存していました。これは、Goのコンパイラやツールチェイン自体がGoで書かれる「自己ホスト型」になる以前の段階では一般的でした。しかし、このアプローチにはいくつかの課題がありました。

  1. 複雑性: 複数のシェルスクリプトが相互に依存し、環境変数の設定、クリーンアップ、ビルド、テストといった様々なタスクを分散して行っていました。これにより、ビルドプロセスの全体像を把握し、デバッグすることが困難でした。
  2. プラットフォーム依存性: シェルスクリプトは、異なるオペレーティングシステムやシェル環境での互換性の問題を引き起こす可能性がありました。特に、Windows環境でのビルドは、MSYSなどのUnixライクな環境を必要とすることが多く、設定が複雑でした。
  3. メンテナンス性: ビルドロジックがスクリプトに散在しているため、変更や機能追加が難しく、エラーが発生しやすい状態でした。
  4. Go言語の成熟: Go言語自体が成熟し、自己ホスト型ビルドが可能になったことで、ビルドプロセス自体をGoで記述する方が、より堅牢でプラットフォームに依存しない方法として適切であるという認識が高まりました。

これらの背景から、GoのビルドプロセスをGo言語で書かれた単一のツールcmd/distに集約し、従来のシェルスクリプトを置き換えることで、ビルドシステムの堅牢性、移植性、メンテナンス性を向上させる必要がありました。

前提知識の解説

Go言語のビルドプロセス

Go言語は「自己ホスト型」の言語であり、Goコンパイラや標準ライブラリの多くがGo言語自体で書かれています。Goのビルドプロセスは、この自己ホスト型という特性を活かして、GoのソースコードからGoのツールチェイン(コンパイラ、リンカ、アセンブラなど)を構築し、そのツールチェインを使ってGoの標準ライブラリやその他のツールをビルドするという多段階のプロセスを踏みます。

初期のGoのビルドは、C言語で書かれたブートストラップコンパイラ(cmd/distのC言語部分がその名残)や、bashスクリプト、makeファイルに大きく依存していました。これは、Goコンパイラがまだ十分に成熟しておらず、自身をコンパイルできなかったためです。

cmd/distとは

cmd/distは、Go言語のディストリビューションをブートストラップ、ビルド、テストするために使用される内部コマンドラインツールです。これは、Goプロジェクトの自己ホスト型ビルドプロセスにおいて非常に重要な役割を担っています。

cmd/distの主な機能は以下の通りです。

  • ブートストラップとビルド: Goディストリビューション全体を再構築するのに役立ちます。初期のGoコンパイラをC言語でビルドし、そのコンパイラを使ってGo言語で書かれたGoコンパイラをビルドするという、多段階のブートストラッププロセスを管理します。
  • テスト: ディストリビューションのビルドプロセスの一部としてGoのテストを実行できます。
  • 環境管理: Goビルドに関連する環境変数(GOOS, GOARCH, GOROOT, GOBINなど)を設定および出力できます。
  • プラットフォーム検出: Goビルド中にホストのオペレーティングシステムとアーキテクチャを検出します。

cmd/distは、Goプロジェクトの開発にとって不可欠なツールですが、一般のGoユーザーが自身のGoアプリケーションをビルドしたり配布したりするために直接使用するものではありません。ユーザーアプリケーションのビルドには通常、go buildgo installコマンドが使用されます。

シェルスクリプトとmakeファイル

Goのビルドシステムがcmd/distに移行する前は、src/all.bash, src/clean.bash, src/env.bash, src/make.bash, src/run.bash, src/sudo.bashといった一連のbashスクリプトと、Make.incのようなmakeファイルがビルドプロセスを制御していました。

  • all.bash: 全体のビルドとテストを実行するエントリポイント。
  • clean.bash: ビルド成果物をクリーンアップする。
  • env.bash: Goのビルドに必要な環境変数(GOROOT, GOBIN, PATHなど)を設定し、必要な外部ツール(gcc, make, bisonなど)の存在を確認する。
  • make.bash: 実際のビルドロジック(コンパイラのビルド、標準ライブラリのインストールなど)を実行する。
  • run.bash: テストを実行する。
  • sudo.bash: デバッガなどのツールを特権付きでインストールする。

これらのスクリプトは、Goのビルドに必要な複雑な手順を自動化していましたが、前述の通り、複雑性、プラットフォーム依存性、メンテナンス性の課題を抱えていました。

技術的詳細

このコミットの技術的な核心は、Goのビルドプロセスをシェルスクリプトの集合体から、Go言語で書かれた単一の実行可能ファイルcmd/distに移行することです。これにより、ビルドロジックがGoのコードとして一元化され、以下の利点が得られます。

  1. Go言語の利用: ビルドロジックがGo言語で記述されることで、Goの強力な型システム、並行処理、エラーハンドリングなどの機能を利用できるようになります。これにより、ビルドスクリプトの堅牢性が向上し、バグの発生を抑制できます。
  2. プラットフォーム独立性: Go言語はクロスプラットフォーム対応に優れているため、cmd/distは様々なオペレーティングシステム(Linux, macOS, Windowsなど)で一貫した動作を提供します。これにより、シェルスクリプトに起因するプラットフォーム固有の問題が解消されます。
  3. ブートストラップの簡素化: cmd/distは、Goのブートストラッププロセスをより効率的に管理します。C言語で書かれたブートストラップコンパイラ(cmd/distの一部)を使用して、Go言語で書かれたGoコンパイラをビルドし、その後、そのGoコンパイラを使用してGoの標準ライブラリやツールをビルドするという多段階のプロセスを自動化します。
  4. コードの削減と集約: 従来の複数のシェルスクリプトに分散していたビルドロジックがcmd/distに集約されることで、コードベースが大幅に削減され、理解しやすくなります。このコミットでは、合計で272行の削除と45行の追加が行われており、これはビルドスクリプトの簡素化と効率化を明確に示しています。
  5. 環境変数の管理: cmd/distは、Goのビルドに必要な環境変数をより適切に管理します。例えば、../bin/tool/dist envコマンドを使用して、Goのビルド環境変数を取得できるようになります。これにより、手動での環境変数設定や、env.bashのようなスクリプトの必要性がなくなります。
  6. クリーンアッププロセスの改善: cmd/dist cleanコマンドにより、ビルド成果物のクリーンアップがより体系的に行われるようになります。従来のclean.bashスクリプトは、手動でファイルを削除するロジックを含んでいましたが、cmd/distはGoのビルドシステムと連携して、より正確なクリーンアップを実行できます。

この変更は、Go言語が自己ホスト型言語として成熟し、そのビルドシステム自体もGo言語の恩恵を受けるようになったことを象徴しています。

コアとなるコードの変更箇所

このコミットでは、以下のファイルが変更されています。

  • src/all.bash: 7行変更 (2追加, 5削除)
  • src/clean.bash: 33行変更 (3追加, 30削除)
  • src/env.bash: 107行削除 (ファイル自体が削除)
  • src/make.bash: 123行変更 (10追加, 113削除)
  • src/run.bash: 41行変更 (7追加, 34削除)
  • src/sudo.bash: 2行変更 (1追加, 1削除)
  • test/run: 4行変更 (2追加, 2削除)

合計で45行の追加と272行の削除が行われています。特に注目すべきは、src/env.bashファイルが完全に削除されている点です。

コアとなるコードの解説

src/all.bash

all.bashは、Goのビルドとテストの全体的なフローを制御するスクリプトです。 変更前は./make.bashを直接呼び出し、run.bashを実行していました。 変更後は、./make.bash --no-bannerを呼び出し、run.bash --no-rebuildを実行しています。 最も重要な変更は、ビルド情報の表示に../bin/tool/dist bannerを使用するようになった点です。これにより、ビルド情報の表示もcmd/distによって管理されるようになりました。

--- a/src/all.bash
+++ b/src/all.bash
@@ -8,7 +8,6 @@ if [ ! -f make.bash ]; then
 	echo 'all.bash must be run from $GOROOT/src' 1>&2
 	exit 1
 fi
-. ./make.bash
-bash run.bash --no-env --no-rebuild
-installed  # function defined by make.bash
-.
+. ./make.bash --no-banner
+bash run.bash --no-rebuild
+../bin/tool/dist banner  # print build info

src/clean.bash

clean.bashは、ビルド成果物をクリーンアップするスクリプトです。 変更前は、env.bashを読み込み、rm -rfコマンドやgo clean stdなどを使って手動でクリーンアップを行っていました。 変更後は、../bin/tool/distが存在するかどうかを確認し、eval $(../bin/tool/dist env)で環境変数を設定した後、"$GOBIN/go" clean -i std../bin/tool/dist cleanを呼び出すことで、クリーンアップ処理をcmd/distに委譲しています。これにより、クリーンアップロジックがGoのビルドシステムとより密接に連携するようになりました。

--- a/src/clean.bash
+++ b/src/clean.bash
@@ -5,34 +5,11 @@
 
 set -e
 
-if [ ! -f env.bash ]; then
-	echo 'clean.bash must be run from $GOROOT/src' 1>&2
+if [ ! -x ../bin/tool/dist ]; then
+	echo 'cannot find ../bin/tool/dist; nothing to clean' >&2
 	exit 1
 fi
-. ./env.bash
-if [ ! -f Make.inc ] ; then
-    GOROOT_FINAL=${GOROOT_FINAL:-$GOROOT}
-    sed 's!@@GOROOT@@!'\"$GOROOT_FINAL\"'!g' Make.inc.in >Make.inc
-fi
-
-if [ "$1" != "--nopkg" ]; then
-	rm -rf "$GOROOT"/pkg/${GOOS}_$GOARCH
-fi
-rm -f "$GOROOT"/lib/*.a
-for i in lib9 libbio libmach cmd
-do
-	# Do not use gomake here. It may not be available.
-	$MAKE -C "$GOROOT/src/$i" clean
-done
-
-if [ -x "$GOBIN/go" ]; then
-	go clean std || true  # go command might not know about clean
-	
-	# TODO: Make clean work in directories outside $GOPATH
-	true || go clean \
-		../misc/cgo/gmp ../misc/cgo/stdio \
-		../misc/cgo/life ../misc/cgo/test \
-		../misc/dashboard/builder ../misc/goplay\
-		../doc/codelab/wiki\
-		../test/bench/shootout ../test/bench/garbage ../test/bench/go1
-fi
+eval $(../bin/tool/dist env)
+"$GOBIN/go" clean -i std
+../bin/tool/dist clean

src/env.bash

このファイルは完全に削除されました。 変更前は、Goのビルドに必要な環境変数(GOROOT, GOBIN, PATHなど)を設定し、必要な外部ツール(gcc, make, bisonなど)の存在を確認する役割を担っていました。 このスクリプトの削除は、これらの環境設定とツールチェックのロジックがcmd/dist内部に統合されたことを意味します。これにより、ビルド環境のセットアップがより自動化され、シェルスクリプトに依存しない形になりました。

--- a/src/env.bash
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2009 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-# If set to a Windows-style path convert to an MSYS-Unix 
-# one using the built-in shell commands.   
-if [[ "$GOROOT" == *:* ]]; then
-	GOROOT=$(cd "$GOROOT"; pwd)
-fi
-
-if [[ "$GOBIN" == *:* ]]; then
-	GOBIN=$(cd "$GOBIN"; pwd)
-fi
-
-export GOROOT=${GOROOT:-$(cd ..; pwd)}
-
-if ! test -f "$GOROOT"/include/u.h
-then
-	echo '$GOROOT is not set correctly or not exported: '$GOROOT 1>&2
-	exit 1
-fi
-
-# Double-check that we're in $GOROOT, for people with multiple Go trees.
-# Various aspects of the build cd into $GOROOT-rooted paths,
-# making it easy to jump to a different tree and get confused.
-DIR1=$(cd ..; pwd)
-DIR2=$(cd "$GOROOT"; pwd)
-if [ "$DIR1" != "$DIR2" ]; then
-	echo 'Suspicious $GOROOT '"$GOROOT"': does not match current directory.' 1>&2
-	exit 1
-fi
-
-export GOBIN=${GOBIN:-"$GOROOT/bin"}
-if [ ! -d "$GOBIN" -a "$GOBIN" != "$GOROOT/bin" ]; then
-	echo '$GOBIN is not a directory or does not exist' 1>&2
-	echo 'create it or set $GOBIN differently' 1>&2
-	exit 1
-fi
-
-export OLDPATH=$PATH
-export PATH="$GOBIN":$PATH
-
-MAKE=make
-if ! make --version 2>/dev/null | grep 'GNU Make' >/dev/null; then
-	MAKE=gmake
-fi
-
-PROGS="
-	ar
-	awk
-	bash
-	bison
-	chmod
-	cp
-	cut
-	echo
-	egrep
-	gcc
-	grep
-	ls
-	$MAKE
-	mkdir
-	mv
-	pwd
-	rm
-	sed
-	sort
-	tee
-	touch
-	tr
-	true
-	uname
-	uniq
-"
-
-for i in $PROGS; do
-	if ! which $i >/dev/null 2>&1; then
-		echo "Cannot find '$i' on search path." 1>&2
-		echo "See http://golang.org/doc/install.html#ctools" 1>&2
-		exit 1
-	fi
-done
-
-if bison --version 2>&1 | grep 'bison++' >/dev/null 2>&1; then
-	echo "Your system's 'bison' is bison++."
-	echo "Go needs the original bison instead." 1>&2
-	echo "See http://golang.org/doc/install.html#ctools" 1>&2
-	exit 1
-fi
-
-# Issue 2020: some users configure bash to default to
-#	set -o noclobber
-# which makes >x fail if x already exists.  Restore sanity.
-set +o noclobber
-
-# Tried to use . <($MAKE ...) here, but it cannot set environment
-# variables in the version of bash that ships with OS X.  Amazing.
-eval $($MAKE --no-print-directory -f Make.inc go-env | egrep 'GOARCH|GOOS|GOHOSTARCH|GOHOSTOS|GO_ENV|CGO_ENABLED')
-
-# Shell doesn't tell us whether make succeeded,
-# so Make.inc generates a fake variable name.
-if [ "$MAKE_GO_ENV_WORKED" != 1 ]; then
-	echo 'Did not find Go environment variables.' 1>&2
-	exit 1
-fi
-unset MAKE_GO_ENV_WORKED

src/make.bash

make.bashは、Goのビルドの主要なロジックを含むスクリプトです。 変更前は、env.bashを読み込み、手動でディレクトリを作成したり、古いバイナリを削除したり、quietgccのようなツールをセットアップしたり、lib9, libbio, libmach, cmdなどのパッケージをgomakeでビルドしたりしていました。また、runtimeパッケージの生成ファイルも手動で処理していました。 変更後は、これらの手動のステップのほとんどが削除され、代わりにcmd/distの呼び出しに置き換えられています。

特に重要な変更点は以下の通りです。

  1. env.bashの読み込み削除: env.bashが削除されたため、その読み込みも不要になりました。
  2. cmd/distのブートストラップ: 最初にC言語で../bin/tool/distをビルドしています。これは、Goのビルドプロセスが自己ホスト型であるため、Goコンパイラ自体をビルドするために必要な最初のステップです。
    gcc -O2 -Wall -Werror -o ../bin/tool/dist -Icmd/dist cmd/dist/*.c
    
  3. cmd/distによるビルドの実行:
    • ../bin/tool/dist bootstrap -v: コンパイラとGoブートストラップツール(go_bootstrap)をビルドします。
    • ../bin/tool/go_bootstrap clean std: 標準ライブラリをクリーンアップします。
    • ../bin/tool/go_bootstrap install -a -v std: パッケージとコマンドをインストールします。
    • rm -f ../bin/tool/go_bootstrap: ブートストラップツールを削除します。
    • ../bin/tool/dist banner: ビルド情報を表示します(--no-bannerオプションがない場合)。

これらの変更により、ビルドロジックがcmd/distに集約され、make.bashcmd/distを呼び出す薄いラッパーのような役割になりました。

--- a/src/make.bash
+++ b/src/make.bash
@@ -4,12 +4,12 @@
 # license that can be found in the LICENSE file.
 
 set -e
-if [ ! -f env.bash ]; then
+if [ ! -f run.bash ]; then
 	echo 'make.bash must be run from $GOROOT/src' 1>&2
 	exit 1
 fi
-. ./env.bash
 
+# Test for bad ld.
 if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then
 	echo 'ERROR: Your system has gold 2.20 installed.'
 	echo 'This version is shipped by Ubuntu even though'
@@ -21,48 +21,9 @@ if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then
 	exit 1
 fi
 
-# Create target directories
-mkdir -p "$GOROOT/bin/tool"
-mkdir -p "$GOROOT/pkg"
-
-# Remove old, pre-tool binaries.
-rm -rf "$GOROOT"/bin/go-tool
-rm -f "$GOROOT"/bin/[568][acgl]
-rm -f "$GOROOT"/bin/{6cov,6nm,cgo,ebnflint,goapi,gofix,goinstall,gomake,gopack,gopprof,gotest,gotype,govet,goyacc,quietgcc}
-
-# If GOBIN is set and it has a Go compiler, it must also be cleaned.
-if [ -n "GOBIN" ]; then
-	if [ -x "$GOBIN"/5g -o -x "$GOBIN"/6g -o -x "$GOBIN"/8g ]; then
-		rm -f "$GOBIN"/[568][acgl]
-		rm -f "$GOBIN"/{6cov,6nm,cgo,ebnflint,goapi,gofix,goinstall,gomake,gopack,gopprof,gotest,gotype,govet,goyacc,quietgcc}
-	fi
-fi
-
-GOROOT_FINAL=${GOROOT_FINAL:-$GOROOT}
-
-MAKEFLAGS=${MAKEFLAGS:-\"-j4\"}
-export MAKEFLAGS
-unset CDPATH	# in case user has it set
-
-rm -f "$GOBIN"/quietgcc
-rm -f "$GOROOT/bin/tool/quietgcc"
-CC=${CC:-gcc}
-export CC
-sed -e "s|@CC@|$CC|" < "$GOROOT"/src/quietgcc.bash > "$GOROOT"/bin/tool/quietgcc
-chmod +x "$GOROOT"/bin/tool/quietgcc
-
-export GOMAKE="$GOROOT"/bin/tool/make
-rm -f "$GOBIN"/gomake
-rm -f "$GOMAKE"
-(
-	echo '#!/bin/sh'
-	echo 'export GOROOT=${GOROOT:-'$GOROOT_FINAL'}'
-	echo 'exec '$MAKE' "$@"'
-) >"$GOMAKE"
-chmod +x "$GOMAKE"
-
-# on Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux,\n-# so loop through the possible selinux mount points
+# Test for bad SELinux.
+# On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux,
+# so loop through the possible selinux mount points.
 for se_mount in /selinux /sys/fs/selinux
 do
 	if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
@@ -82,39 +43,23 @@ do
 	fi
 done
 
-bash "$GOROOT"/src/clean.bash
-
-# pkg builds runtime/cgo and the Go programs in cmd.
-for i in lib9 libbio libmach cmd
-do
-	echo; echo; echo %%%% making $i %%%%; echo
-	"$GOMAKE" -C $i install
-done
-
-echo; echo; echo %%%% making runtime generated files %%%%; echo
-
-(
-	cd "$GOROOT"/src/pkg/runtime
-	./autogen.sh
-	"$GOMAKE" install; "$GOMAKE" clean # copy runtime.h to pkg directory
-) || exit 1
+# Finally!  Run the build.
 
+echo '# Building C bootstrap tool.'
+mkdir -p ../bin/tool
+gcc -O2 -Wall -Werror -o ../bin/tool/dist -Icmd/dist cmd/dist/*.c
 echo
-echo '# Building go_bootstrap command from bootstrap script.'
-if ! ./buildscript/${GOOS}_$GOARCH.sh; then
-\techo '# Bootstrap script failed.'
-\tif [ ! -x "$GOBIN/go" ]; then
-\t\texit 1
-\tfi
-\techo '# Regenerating bootstrap script using pre-existing go binary.'
-\t./buildscript.sh
-\t./buildscript/${GOOS}_$GOARCH.sh
-fi
-
-# Clean what clean.bash couldn't.
-go_bootstrap clean std
-
-echo '# Building Go code.'
-go_bootstrap install -a -v std
-rm -f "$GOBIN/go_bootstrap"
+echo '# Building compilers and Go bootstrap tool.'
+../bin/tool/dist bootstrap -v # builds go_bootstrap
+echo
 
-# Print post-install messages.
-# Implemented as a function so that all.bash can repeat the output
-# after run.bash finishes running all the tests.\n-installed() {
-\teval $("$GOMAKE" --no-print-directory -f Make.inc go-env)
-\techo
-\techo ---
-\techo Installed Go for $GOOS/$GOARCH in "$GOROOT".
-\techo Installed commands in "$GOBIN".
-\tcase "$OLDPATH" in
-\t"$GOBIN:"* | *":$GOBIN" | *":$GOBIN:"*)\
-\t\t;;\
-\t*)\
-\t\techo '***' "You need to add $GOBIN to your "'$PATH.' '***'
-\tesac
-\tif [ "$(uname)" = "Darwin" ]; then
-\t\techo
-\t\techo On OS X the debuggers must be installed setgrp procmod.
-\t\techo Read and run ./sudo.bash to install the debuggers.
-\tfi
-\tif [ "$GOROOT_FINAL" != "$GOROOT" ]; then
-\t\techo
-\t\techo The binaries expect "$GOROOT" to be copied or moved to "$GOROOT_FINAL".
-\tfi
-}
+echo '# Building packages and commands.'
+../bin/tool/go_bootstrap clean std
+../bin/tool/go_bootstrap install -a -v std
+rm -f ../bin/tool/go_bootstrap
+echo
 
-(installed)  # run in sub-shell to avoid polluting environment
+if [ "$1" != "--no-banner" ]; then
+	../bin/tool/dist banner
+fi

src/run.bash

run.bashは、Goのテストを実行するスクリプトです。 変更前は、env.bashを読み込み、go install -a -v stdでパッケージをビルドした後、go test stdなどでテストを実行していました。 変更後は、eval $(../bin/tool/dist env -p)を呼び出すことで、cmd/distから環境変数を取得するようになりました。また、go installの実行は、all.bashからの呼び出し時に--no-rebuildオプションが指定されていない場合にのみ行われるようになりました。これにより、テスト実行前のビルドステップもcmd/distの管理下に置かれ、より効率的なテストフローが実現されています。

--- a/src/run.bash
+++ b/src/run.bash
@@ -4,53 +4,40 @@
 # license that can be found in the LICENSE file.
 
 set -e
-if [ "$1" = "--no-env" ]; then
-	# caller has already run env.bash
-	shift
-else
-	. ./env.bash
-fi
 
-unset MAKEFLAGS  # single-threaded make
+eval $(../bin/tool/dist env -p)
+\
 unset CDPATH	# in case user has it set
 
 # no core files, please
 ulimit -c 0
 
-# allow make.bash to avoid double-build of everything
+# allow all.bash to avoid double-build of everything
 rebuild=true
 if [ "$1" = "--no-rebuild" ]; then
-\trebuild=false
 	shift
-fi
-\t\t
-xcd() {\n-\techo
-\techo --- cd $1
-\tbuiltin cd "$GOROOT"/src/$1
-}
-\n-if $rebuild; then
-\techo
-\techo '# Package builds'
+\trebuild=false
+else
+\techo '# Building packages and commands.'
 \ttime go install -a -v std
+\techo
 fi
 
-echo
-echo '# Package tests'
+echo '# Testing packages.'
 time go test std -short -timeout=120s
-\n echo
+\n echo
+\n echo '# runtime -cpu=1,2,4'
+go test runtime -short -timeout=120s -cpu=1,2,4
+\n echo
+\n echo '# sync -cpu=10'
+go test sync -short -timeout=120s -cpu=10
+\n+xcd() {\n+\techo
+\techo --- cd $1
+\tbuiltin cd "$GOROOT"/src/$1
+}
-\n echo '# runtime -cpu=1,2,4'
-go test runtime -short -timeout=120s -cpu=1,2,4
-\n echo
-\n echo '# sync -cpu=10'
-go test sync -short -timeout=120s -cpu=10
-\n-echo
-\n-echo '# Build bootstrap scripts'
-./buildscript.sh
 \n BROKEN=true
 \n

src/sudo.bash

sudo.bashは、デバッガなどのツールを特権付きでインストールするためのスクリプトです。 変更前は、$GOROOT/src/cmd/$i/$iからバイナリをコピーしていましたが、変更後は$GOROOT/bin/tool/$iからコピーするように変更されました。これは、cmd/distによってビルドされたツールが../bin/toolディレクトリに配置されるようになったためです。

--- a/src/sudo.bash
+++ b/src/sudo.bash
@@ -23,7 +23,7 @@ do
 	# Remove old binaries if present
 	sudo rm -f /usr/local/bin/6$i
 	# Install new binaries
-\tsudo cp "$GOROOT"/src/cmd/$i/$i /usr/local/bin/go$i
+\tsudo cp "$GOROOT"/bin/tool/$i /usr/local/bin/go$i
 	sudo chgrp procmod /usr/local/bin/go$i
 	sudo chmod g+s /usr/local/bin/go$i
 done

test/run

test/runは、テストスイートを実行するためのスクリプトです。 変更前は、../bin/tool/makeを使って環境変数を取得していましたが、変更後は../bin/tool/dist envを使って環境変数を取得し、GOARCH, GOOS, GOROOTをエクスポートするように変更されました。これにより、テスト実行環境のセットアップもcmd/distに依存するようになりました。

--- a/test/run
+++ b/test/run
@@ -3,8 +3,8 @@
 # Use of this source code is governed by a BSD-style
 # license that can be found in the LICENSE file.
 
-eval $(../bin/tool/make --no-print-directory -f ../src/Make.inc go-env)\n-\n+eval $(../bin/tool/dist env)
+export GOARCH GOOS GOROOT
 export E=\n \n case X"$GOARCH" in

関連リンク

参考にした情報源リンク