コンテンツにスキップ

「Ruby Gem パッケージガイドライン」の版間の差分

提供: ArchWiki
削除された内容 追加された内容
ページの作成:「Category:パッケージ開発 en:Ruby Gem package guidelines it:Ruby Gem Package Guidelines {{Package Guidelines}} Ruby で書かれたソフトウェ...」
 
Kgx (トーク | 投稿記録)
参照を追加
 
(2人の利用者による、間の6版が非表示)
7行目: 7行目:


== パッケージの命名規則 ==
== パッケージの命名規則 ==
ライブラリの場合、{{Ic|ruby-$gemname}} を使って下さい。アプリケーションの場合、プログラムの名前を使って下さい。どちらの場合でも名前は小文字である必要があります。


ライブラリの場合は、{{ic|ruby-$_name}} を使用します ({{ic|$_name}} は上流のプロジェクト名です)。アプリケーションの場合は、プロジェクト名 ({{ic|ruby-}} 接頭辞なし) を使用し、オプションで {{ic|ruby-$_name}} を {{ic|provides}} に追加します。
たとえ {{Ic|$gemname}} に {{Ic|ruby}} が含まれている場合でも {{Ic|ruby-}} を最初に付けるようにしてください。後で gem の名前が短くなったときに困らないようにするためです。また、ツールによって簡単に名前を解析できるようにするためでもあります (PKGBUILD ジェネレータやバージョン・依存関係チェッカーなど)。例: {{AUR|ruby-ruby-protocol-buffers}}.


== ビルドとテスト ==
====バージョン付きパッケージ====
If you need to add a versioned package then use {{Ic|ruby-$gemname-$version}}, e.g. {{Ic|ruby-builder-3.2.1}}. So rubygem dependency {{Ic|builder=3.2.1}} will turn into {{Ic|ruby-builder-3.2.1}} Arch package.


Ruby パッケージは、ビルドに透過的な信頼チェーンを提供するため、上流のソースからビルドする必要があります。既存の Ruby パッケージのセットとの統合を確実にするために、{{Pkg|ruby-rake}} または {{Pkg|ruby-rspec}} を使用してテストを実行することが期待されます。
In case if you need to resolve "approximately greater" dependency {{Ic|~>}} then package should use version without the last part, e.g. rubygem dependency {{Ic|builder~>3.2.1}} will turn into {{Ic|ruby-builder-3.2}}. An exception for this rule is when "approximately greater" dependency matches the latest version of the gem - in this case avoid introducing a new versioned package and use just {{Ic|ruby-$gemname}} instead (the HEAD version).


{{Note|プロジェクトのリリース間の依存関係の変更を検出するには、更新時に {{ic|.gemspec}} または {{ic|Gemfile}} をよく調べてください。}}
Another problem with versioned packages is that it can conflict with other versions, e.g. because the packages install the same files in {{ic|/usr/bin}}. One solution for this problem is that versioned packages should not install such files - only HEAD version package can do this.


== ンプ ==
== ンプレート ==
{{AUR|ruby-rethinkdb}} {{AUR|ruby-json_pure}} {{Pkg|ruby-hpricot}} などを見て下さい。


{{hc|head=PKGBUILD|output=
== ノート ==
prepare() {
Add {{Ic|--verbose}} to '''gem''' arguments to receive additional information in case of troubles.
cd "${_name}-${pkgver}"


# update gemspec/Gemfile to allow newer version of the dependencies
{{Note|Usage of {{ic|--no-user-install}} '''gem''' argument is mandatory since latest Ruby versions (See {{Bug|28681}} for details).}}
sed --in-place --regexp-extended 's{{!}}~>{{!}}>={{!}}g' "${_name}.gemspec"
}


build() {
== 配慮事項 ==
cd "${_name}-${pkgver}"
=== Package contains reference to $pkgdir ===
たまにパッケージのビルド時に {{Ic|WARNING: Package contains reference to $pkgdir}} という警告が表示されることがあります。パッケージ化したファイルの中にパッケージをビルドしたディレクトリの絶対パスが含まれています。問題のファイルを探すために {{ic|cd pkg && grep -R "$(pwd)" .}} を実行してください。ほとんどの場合、{{Ic|.../ext/Makefile}} 内にハードコードされたパスが原因です。
{{note|folder {{ic|ext}} contains native extension code usually written in C. During the package installation rubygems generates a Makefile using {{ic|mkmf}} library. Then {{Ic|make}} is called, it compiles a shared library and copies one to {{ic|lib}} gem directory.}}
After {{ic|gem install}} is over the {{Ic|Makefile}} is not needed anymore. In fact none of the files in {{Ic|ext}} is needed and it can be completely removed by adding {{ic|rm -rf "$pkgdir/$_gemdir/gems/$_gemname-$pkgver/ext"}} to {{ic|package()}} function.


local _gemdir="$(gem env gemdir)"
== サンプル PKGBUILD ==
サンプル PKGBUILD は {{Pkg|abs}} パッケージの {{Ic|/usr/share/pacman/PKGBUILD-rubygem.proto}} にあります。


gem build "${_name}.gemspec"
== 自動化 ==
The gem installation can be automated completely with the tool {{AUR|pacgem}} which creates a temporary PKGBUILD, calls [[makepkg]] and [[namcap]]. The resulting package is then installed with {{Ic|sudo pacman}}.


gem install \
There is also {{AUR|gem2arch}} tools which aid in automating the process of creating a ruby gem PKGBUILD. Make sure to manually check the PKGBUILD after generation.
--local \
--verbose \
--ignore-dependencies \
--no-user-install \
--install-dir "tmp_install/${_gemdir}" \
--bindir "tmp_install/usr/bin" \
"${_name}-${pkgver}.gem"

# remove unrepreducible files
rm --force --recursive --verbose \
"tmp_install/${_gemdir}/cache/" \
"tmp_install/${_gemdir}/gems/${_name}-${pkgver}/vendor/" \
"tmp_install/${_gemdir}/doc/${_name}-${pkgver}/ri/ext/"

find "tmp_install/${_gemdir}/gems/" \
-type f \
\( \
-iname "*.o" -o \
-iname "*.c" -o \
-iname "*.so" -o \
-iname "*.time" -o \
-iname "gem.build_complete" -o \
-iname "Makefile" \
\) \
-delete

find "tmp_install/${_gemdir}/extensions/" \
-type f \
\( \
-iname "mkmf.log" -o \
-iname "gem_make.out" \
\) \
-delete
}

check() {
cd "${_name}-${pkgver}"

local _gemdir="$(gem env gemdir)"

GEM_HOME="tmp_install/${_gemdir}" rake test
}

package() {
cd "${_name}-${pkgver}"

cp --archive --verbose tmp_install/* "${pkgdir}"

install --verbose -D --mode=0644 LICENSE --target-directory "${pkgdir}/usr/share/licenses/${pkgname}"
install --verbose -D --mode=0644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}
}}

== ヒントとテクニック ==

=== gem は "git ls-files" を使用して追加するファイルを派生しています ===

この場合、次の {{ic|sed}} コマンドを {{ic|prepare()}} 関数に追加できます。

{{bc|
# we don't build from a git checkout
sed --in-place --regexp-extended 's{{!}}git ls-files{{!}}find . -type f -not -path "*/\.git/*"{{!}}' "${_name}.gemspec"
}}

=== 上流のプロジェクトでは、テストの実行に "rspec" を使用している ===

この場合、{{ic|check()}} 関数のコード行を次のように置き換えることができます。

GEM_HOME="tmp_install/${_gemdir}" rspec

== 参照 ==

* [https://www.ruby-lang.org/en/documentation/ Ruby 言語のドキュメント]
* [https://ruby.github.io/rake/ Rake ドキュメント]
* [https://guides.rubygems.org/ Rubygems ドキュメント]
* {{man|1|ruby}}

2023年6月28日 (水) 22:39時点における最新版

Ruby で書かれたソフトウェアの PKGBUILD の書き方。

パッケージの命名規則

ライブラリの場合は、ruby-$_name を使用します ($_name は上流のプロジェクト名です)。アプリケーションの場合は、プロジェクト名 (ruby- 接頭辞なし) を使用し、オプションで ruby-$_nameprovides に追加します。

ビルドとテスト

Ruby パッケージは、ビルドに透過的な信頼チェーンを提供するため、上流のソースからビルドする必要があります。既存の Ruby パッケージのセットとの統合を確実にするために、ruby-rake または ruby-rspec を使用してテストを実行することが期待されます。

ノート プロジェクトのリリース間の依存関係の変更を検出するには、更新時に .gemspec または Gemfile をよく調べてください。

テンプレート

PKGBUILD
prepare() {
  cd "${_name}-${pkgver}"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed --in-place --regexp-extended 's|~>|>=|g' "${_name}.gemspec"
}

build() {
  cd "${_name}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem build "${_name}.gemspec"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/${_gemdir}" \
    --bindir "tmp_install/usr/bin" \
    "${_name}-${pkgver}.gem"

  # remove unrepreducible files
  rm --force --recursive --verbose \
    "tmp_install/${_gemdir}/cache/" \
    "tmp_install/${_gemdir}/gems/${_name}-${pkgver}/vendor/" \
    "tmp_install/${_gemdir}/doc/${_name}-${pkgver}/ri/ext/"

  find "tmp_install/${_gemdir}/gems/" \
    -type f \
    \( \
      -iname "*.o" -o \
      -iname "*.c" -o \
      -iname "*.so" -o \
      -iname "*.time" -o \
      -iname "gem.build_complete" -o \
      -iname "Makefile" \
    \) \
    -delete

  find "tmp_install/${_gemdir}/extensions/" \
    -type f \
    \( \
      -iname "mkmf.log" -o \
      -iname "gem_make.out" \
    \) \
    -delete
}

check() {
  cd "${_name}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  GEM_HOME="tmp_install/${_gemdir}" rake test
}

package() {
  cd "${_name}-${pkgver}"

  cp --archive --verbose tmp_install/* "${pkgdir}"

  install --verbose -D --mode=0644 LICENSE --target-directory "${pkgdir}/usr/share/licenses/${pkgname}"
  install --verbose -D --mode=0644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}

ヒントとテクニック

gem は "git ls-files" を使用して追加するファイルを派生しています

この場合、次の sed コマンドを prepare() 関数に追加できます。

# we don't build from a git checkout
sed --in-place --regexp-extended 's|git ls-files|find . -type f -not -path "*/\.git/*"|' "${_name}.gemspec"

上流のプロジェクトでは、テストの実行に "rspec" を使用している

この場合、check() 関数のコード行を次のように置き換えることができます。

GEM_HOME="tmp_install/${_gemdir}" rspec

参照