2021年2月3日水曜日

Vim をソースからビルドして、 Yocto のレイヤーとして追加する

前回からの続き。

前回作成したイメージに、ソースからビルドした Vim を追加する。

レシピ作成

devtool add myvim https://github.com/vim/vim.git

レシピ編集

レシピ作成で生成される myvim_git.bb を編集する。

vim workspace/recipes/myvim/myvim_git.bb

myvim_git.bb

do_configure, do_compile, do_install 内に、それぞれのフェーズで実行するコマンドを列挙する。

詳細は以下ファイルを参照。

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

レシピのビルド

devtool build myvim

エラーが出た。

checking for linking with ncurses library... configure: error: FAILED
WARNING: exit code 1 from a shell command.

パッケージ ncurses が足りないようだ。 DEPENDS += " ncurses" を追加。

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

DEPENDS += " ncurses"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

また、エラーが出た。

ERROR: myvim-1.0+git999-r0 do_package: QA Issue: File '/usr/bin/vim' from myvim was already stripped, this will prevent future debugging! [already-stripped]
ERROR: myvim-1.0+git999-r0 do_package: QA Issue: File '/usr/bin/xxd' from myvim was already stripped, this will prevent future debugging! [already-stripped]
ERROR: myvim-1.0+git999-r0 do_package: QA Issue: myvim: Files/directories were installed but not shipped in any package:

以下 2 点に対応する。

  1. コンパイルで strip 済みバイナリを生成すると、 myvim was already stripped というエラーになるようだ
    • INSANE_SKIP_${PN} += "already-stripped" を追加
  2. FILES_${PN} 書き忘れ

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

FILES_${PN} = " \
        ${bindir} \
        ${prefix}/share \
"

DEPENDS += " ncurses"

INSANE_SKIP_${PN} += "already-stripped"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

レイヤーを作成し、レシピをレイヤーに追加

bitbake-layers create-layer "$BUILDDIR/meta-myvim"
bitbake-layers add-layer "$BUILDDIR/meta-myvim"
devtool finish myvim meta-myvim

echo 'CORE_IMAGE_EXTRA_INSTALL += "myvim"' >> conf/local.conf

レイヤーを追加したイメージをビルド

bitbake core-image-minimal

またまた、エラー。

ERROR: myvim-1.0+gitAUTOINC+e7bebc495d-r0 do_package_qa: QA Issue: /usr/share/vim/vim82/tools/demoserver.py contained in package myvim requires /usr/bin/python, but no providers found in RDEPENDS_myvim? [file-rdeps]
ERROR: myvim-1.0+gitAUTOINC+e7bebc495d-r0 do_package_qa: QA Issue: /usr/share/vim/vim82/tools/efm_perl.pl contained in package myvim requires /work/poky/build/tmp/hosttools/perl, but no providers found in RDEPENDS_myvim? [file-rdeps]
ERROR: myvim-1.0+gitAUTOINC+e7bebc495d-r0 do_package_qa: QA Issue: /usr/share/vim/vim82/tools/mve.awk contained in package myvim requires /work/poky/build/tmp/hosttools/gawk, but no providers found in RDEPENDS_myvim? [file-rdeps]
ERROR: myvim-1.0+gitAUTOINC+e7bebc495d-r0 do_package_qa: QA Issue: /usr/share/vim/vim82/tools/vim132 contained in package myvim requires /bin/csh, but no providers found in RDEPENDS_myvim? [file-rdeps]

python, perl, gawk, csh が必要。

  1. python, perl, gawk のパッケージ依存を追加
    • RDEPENDS_${PN} += " python3 perl gawk" を追加
  2. エラー対象のスクリプトの、 shebang を修正
    1. patch を作る
    2. SRC_URI に patch のパスを指定

devtool finish を実行した後は、 myvim_git.bbmeta-myvim/recipes-myvim/myvim/myvim_git.bb に移動しているのでそれを修正。

RDEPENDS_${PN} の追加

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

FILES_${PN} = " \
        ${bindir} \
        ${prefix}/share \
"

RDEPENDS_${PN} += " python3 perl gawk"
DEPENDS += " ncurses"

INSANE_SKIP_${PN} += "already-stripped"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

Shebang の修正とパッチ作成

Shebang 修正

エラーに表示された以下ファイルの Shebang を修正する。

  • /usr/share/vim/vim82/tools/demoserver.py
    • #!/usr/bin/python -> #!/usr/bin/env python
  • /usr/share/vim/vim82/tools/efm_perl.pl
    • #!/usr/bin/perl -w -> #!/usr/bin/env perl -w
  • /usr/share/vim/vim82/tools/mve.awk
    • #!/usr/bin/nawk -f -> #!/usr/bin/env nawk -f
  • /usr/share/vim/vim82/tools/vim132
    • #!/bin/csh -f -> #!/bin/sh

パッチ作成

cd workspace/sources/myvim
git diff > ../../../meta-myvim/recipes-myvim/shebang.patch
cd ../../..

SRC_URI にパッチのパスを設定

今回の場合、 SRC_URI += " file:///work/poky/build/meta-myvim/recipes-myvim/shebang.patch;patch=1" を追加。

myvim_git.bb

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
#
# The following license files were not able to be identified and are
# represented as "Unknown" below, you will need to check them yourself:
#   LICENSE
#   src/xdiff/COPYING
#   src/xpm/COPYRIGHT
#
# NOTE: multiple licenses have been detected; they have been separated with &
# in the LICENSE value for now since it is a reasonable assumption that all
# of the licenses apply. If instead there is a choice between the multiple
# licenses then you should change the value to separate the licenses with |
# instead of &. If there is any doubt, check the accompanying documentation
# to determine which situation is applicable.
LICENSE = "Unknown & MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=6b30ea4fa660c483b619924bc709ef99 \
                    file://src/libvterm/LICENSE;md5=be5681ffe0dc58ccc9756bc6260fe0cd \
                    file://src/xdiff/COPYING;md5=278f2557e3b277b94e9a8430f6a6d0a9 \
                    file://src/xpm/COPYRIGHT;md5=1e8b098093f3bb7a8fed64938e8e465e"

SRC_URI = "git://github.com/vim/vim.git;protocol=https"
SRC_URI += " file:///work/poky/build/meta-myvim/recipes-myvim/shebang.patch;patch=1"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "0346b799fc228a3b48967ca0747e6b23586dbaa6"

S = "${WORKDIR}/git"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
    # specify any needed configure commands here
    :
    export vim_cv_toupper_broken="no"
    export vim_cv_terminfo="yes"
    export vim_cv_tgetent="zero"
    export vim_cv_getcwd_broken="no"
    export vim_cv_stat_ignores_slash="yes"
    export vim_cv_memmove_handles_overlap="yes"
    ./configure --build=x86_64-linux --host=-arm-poly-linux-gnueabi --with-features=huge --enable-fail-if-missing --with-tlib=ncurses --prefix=${D}/${prefix}
}

do_compile () {
    # You will almost certainly need to add additional arguments here
    :
    make
}

do_install () {
    # NOTE: unable to determine what to put here - there is a Makefile but no
    # target named "install", so you will need to define this yourself
    :
    make install
}

再度ビルドに挑戦。

bitbake core-image-minimal

WARNING が大量に出つつも成功。

ビルド成果物を qemu-system-arm で実行

root でログインして vim コマンドで clone してきた vim が起動することを確認。

qemu-system-arm -M virt -m 1024 \
  -kernel tmp/deploy/images/qemuarm/zImage \
  -drive if=none,file=tmp/deploy/images/qemuarm/core-image-minimal-qemuarm.ext4,format=raw,id=hd \
  -device virtio-blk-device,drive=hd \
  -netdev user,id=usernet \
  -device virtio-net-device,netdev=usernet \
  -append "root=/dev/vda" \
  -nographic -no-reboot

以上。

参考資料

0 件のコメント:

コメントを投稿