DeveloperWiki:クリーンな chroot 内でビルドする

提供: ArchWiki
2020年5月27日 (水) 12:24時点におけるNy-a (トーク | 投稿記録)による版 (→‎chroot のセットアップ: 訳出)
ナビゲーションに移動 検索に移動

導入

このページは en:DeveloperWiki の一部です。

理由

クリーンな chroot 内でビルドすることは、望んでいないリンクか PKGBUILD の depends 配列からパッケージが欠けているかに関わらず、パッケージの依存の不足を防ぎます。これを使うことで、[testing] からパッケージをインストールしているときに、安定したリポジトリ (core, extra, community) のパッケージをビルドすることができるようになります。

便利な方法

余計な操作なしに簡単にクリーンな chroot 内でパッケージをビルドするには、devtools パッケージのヘルパースクリプトを使うことができます。

ヘルパースクリプトは、makepkg と同じように PKGBUILD があるディレクトリで呼ばれる必要があります。具体的には、extra-x86_64-build は自動的に chroot を /var/lib/archbuild のクリーンな chroot マトリックスからセットアップし、それをアップデートして、extra リポジトリのパッケージをビルドします。multilib のビルドには、アーキテクチャなしの multilib-build があります。特定のリポジトリとアーキテクチャにビルドするときにどのスクリプトを使うべきかの情報は下の表を参照してください。

-c 引数は chroot マトリックスをリセットするため、破損したときに便利です。これはクリーンな chroot 内でビルドするときには必要ありません。

ノート: [core] にパッケージが入る前に [testing] を通る必要があるため、[core] は省かれています。
ノート: 目的が [core] パッケージをローカルで使うためにビルドすることであれば、testing の代わりに安定したリポジトリを使う方が好ましいかもしれません。この場合は単に extra のビルドスクリプトを使ってください。
ターゲットのリポジトリ アーキテクチャ 使うビルドスクリプト 使われる pacman 設定ファイル
extra / community x86_64 extra-x86_64-build /usr/share/devtools/pacman-extra.conf
testing / community-testing x86_64 testing-x86_64-build /usr/share/devtools/pacman-testing.conf
staging / community-staging x86_64 staging-x86_64-build /usr/share/devtools/pacman-staging.conf
multilib x86_64 multilib-build /usr/share/devtools/pacman-multilib.conf
multilib-testing x86_64 multilib-testing-build /usr/share/devtools/pacman-multilib-testing.conf
multilib-staging x86_64 multilib-staging-build /usr/share/devtools/pacman-multilib-staging.conf

従来の方法

chroot のセットアップ

devtools パッケージはクリーンな chroot 内で作成・ビルドするためのツールを提供します。インストールしていなければインストールしてください。

クリーンな chroot を作るには、chroot が入るディレクトリを作成してください。例えば、$HOME/chroot です。

$ mkdir ~/chroot

CHROOT 変数を定義してください。

$ CHROOT=$HOME/chroot

chroot を作成します ($CHROOT ディレクトリにはクリーンなワーキングコピーが入る他のサブディレクトリが作成されるため、サブディレクトリ root は必須です)。

$ mkarchroot $CHROOT/root base-devel
ノート: 同じ場所を繰り返し使う場合は、CHROOT 変数を export コマンドを使って $HOME/.bashrc で定義することもできます。
ノート: btrfs ディスクでは、chroot はサブボリュームとして作成されるため、削除するには # btrfs subvolume delete $CHROOT/root を使ってサブボリュームを削除する必要があります。

~/.makepkg.conf を編集して、パッケージャ名と makeflags をセットします。必要であれば、$CHROOT/root/etc/pacman.d/mirrorlistミラーリスト を調整して、$CHROOT/root/etc/pacman.conftesting リポジトリを有効化してください。

ノート: ~$HOME 変数は makechrootpkg スクリプトにより /root/ に解決されます (下で説明)。

pacman.conf のカスタマイズ

Alternatively, provide a custom pacman.conf and makepkg.conf with the following:

$ mkarchroot -C <pacman.conf> -M <makepkg.conf> $CHROOT/root base-devel
警告: Using a custom pacman.conf or makepkg.conf during the initial creation of clean chroot can result in unintended custom adjustments to the chroot environment. Use with caution.

chroot の中でビルドする

Firstly, make sure the base chroot ($CHROOT/root) is up to date:

$ arch-nspawn $CHROOT/root pacman -Syu

Then, build a package by calling makechrootpkg in the directory containing its PKGBUILD:

$ makechrootpkg -c -r $CHROOT
ノート: Passing the -c flag to makechrootpkg ensures that the working chroot ($CHROOT/$USER) is cleaned before building.

必要なパッケージを事前にインストールする

To build a package with dependencies unavailable from the repositories enabled in $CHROOT/root/pacman.conf, pre-install them to the working chroot with -I <package>:

$ makechrootpkg -c -r $CHROOT -I build-dependency-1.0-1-x86_64.pkg.tar.xz -I required-package-2.0-2-x86_64.pkg.tar.xz

makepkg に引数を渡す

To pass arguments to makepkg, list them after an end-of-options marker; e.g., to force a check():

$ makechrootpkg -c -r $CHROOT -- --check

一般的なリビルドを扱う

The cleanest way to handle a major rebuild is to use the [staging] repositories. Build the first package against [extra] and push it to [staging]. Then rebuild all following packages against [staging] and push them there.

If you can't use [staging], you can build against custom packages using a command like this:

# extra-x86_64-build -- -I ~/packages/foobar/foobar-2-1-any.pkg.tar.xz

You can specify more than one package to be installed using multiple -I arguments.

A simpler, but dirtier way to handle a major rebuild is to install all built packages in the chroot, never cleaning it. Build the first package using:

# extra-x86_64-build

And build all following packages using:

# makechrootpkg -n -r /var/lib/archbuild/extra-x86_64

Running namcap (the -n argument) implies installing the package in the chroot. *-build also does this by default.

ヒントとテクニック

tmpfs 内でビルドする

If the system has enough RAM, it is possible to specify a tmpfs for the devtools build scripts.

# mkdir -p /mnt/chroots/arch
# mount -t tmpfs -o defaults,size=20G /mnt/chroots/arch
# extra-x86_64-build -c -r /mnt/chroots/arch