introduce a class to assist in building gems
cover introduce a class to assist in building gems
For a while now we have had functionality in meta-cloud-services in Yocto to assist in building Ruby gems in to the rootfs images. Many of these gems and the ruby.bbclass that was written to facilitate the building of gems are not specific to our work in meta-cloud-services and should be made more widely available by moving them to meta-ruby. So this is my first attempt to get things moved and in doing so make the meta-ruby layer more comprehensive.
We have used this ruby.bbclass in meta-cloud-services to build about 25 gems and in doing so we have worked out a number of issues and have been successful in adding new gem recipes easily. Although at this time focus has been on x86 and x86-64 so we have not yet attempting any cross ARCH cross compiling. Since there are many parallels between Ruby and Python we expect that when we do start to cross-compile we will run into similar issues and don't anticipate major obstacles.
For now I have included a recipe for single gem, bundler. Including this gem in your image will demonstrate that the class is able to perform as advertised and examining bundler on the target we can confirm the validity of the build:
--
root@qemux86-64:~# cat Gemfile source 'https://rubygems.org' gem 'rspec', :require => 'spec'
root@qemux86-64:~# bundle install Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine. Fetching gem metadata from https://rubygems.org/......... Resolving dependencies... Using diff-lcs 1.2.5 Installing rspec-support 3.1.0 Installing rspec-core 3.1.0 Installing rspec-expectations 3.1.0 Installing rspec-mocks 3.1.0 Installing rspec 3.1.0 Using bundler 1.6.2 Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
root@qemux86-64:~# bundle show Gems included by the bundle: * bundler (1.6.2) * diff-lcs (1.2.5) * rspec (3.1.0) * rspec-core (3.1.0) * rspec-expectations (3.1.0) * rspec-mocks (3.1.0) * rspec-support (3.1.0) --
Once ruby.bbclass is accepted in to meta-ruby I will submit additional reviews to copy more of our gem recipes from meta-cloud-services.
I look forward to hearing feedback and hope that I can get things to a point where we can get this merged.
Regards,
Mark
PATCH 1/1 ruby.bbclass: introduce a class to assist in building gems
In order to allow the building of gems we have created a ruby.bbclass. The building of gems is much like the building of python packages in that we rely on building up -native gems in order to facilitate the cross compiling of the gems that will be built for the target. When dependencies exist between gems they must be satisfied by the -native gems installed in the host sysroot. This approach is feasible since the build process is able to query installed gems without being affected by the ARCH they were built for. At this point I have yet to come across a situation where the assumption associated with this approach have failed but so far focus has only been on x86 and x86-64 builds.
The recipes which inherit the ruby.bbclass can optionally define a BPV in the case where the gemspec version doesn't always map 1:1 to the PV. This situation has only been encountered on a few occasions so the class has been made to default BPV to PV.
To demonstrate the ruby.bbclass in use we have included a recipe to build the bundler gem. Bundler can be used on a running target to install gems from rubygems.org, which can be useful in itself when you don't have recipes available for gems but want to try installing and running pre-built gems.
--- meta-ruby/classes/ruby.bbclass | 125 +++++++++++++++++++++++++ meta-ruby/recipes-devtools/ruby/bundler_git.bb | 29 ++++++ 2 files changed, 154 insertions(+) create mode 100644 meta-ruby/classes/ruby.bbclass create mode 100644 meta-ruby/recipes-devtools/ruby/bundler_git.bb
meta-ruby/classes/ruby.bbclass new file +125 -0
@@ -0,0 +1,125 @@ +BPV ?= "${PV}" + +DEPENDS += " \ + ruby-native \ +" +RDEPENDS_${PN} += " \ + ruby \ +" + +def get_rubyversion(p): + import re + from os.path import isfile + import subprocess + found_version = "SOMETHING FAILED!" + + cmd = "%s/ruby" % p + + if not isfile(cmd): + return found_version + + version = subprocess.Popen([cmd, "--version"], stdout=subprocess.PIPE).communicate()[0] + + r = re.compile("ruby ([0-9]+\.[0-9]+\.[0-9]+)*") + m = r.match(version) + if m: + found_version = m.group(1) + + return found_version + +def get_rubygemslocation(p): + import re + from os.path import isfile + import subprocess + found_loc = "SOMETHING FAILED!" + + cmd = "%s/gem" % p + + if not isfile(cmd): + return found_loc + + loc = subprocess.Popen([cmd, "env"], stdout=subprocess.PIPE).communicate()[0] + + r = re.compile(".*\- (/usr.*/ruby/gems/.*)") + for line in loc.split('\n'): + m = r.match(line) + if m: + found_loc = m.group(1) + break + + return found_loc + +def get_rubygemsversion(p): + import re + from os.path import isfile + import subprocess + found_version = "SOMETHING FAILED!" + + cmd = "%s/gem" % p + + if not isfile(cmd): + return found_version + + version = subprocess.Popen([cmd, "env", "gemdir"], stdout=subprocess.PIPE).communicate()[0] + + r = re.compile(".*([0-9]+\.[0-9]+\.[0-9]+)$") + m = r.match(version) + if m: + found_version = m.group(1) + + return found_version + +RUBY_VERSION ?= "${@get_rubyversion("${STAGING_BINDIR_NATIVE}")}" +RUBY_GEM_DIRECTORY ?= "${@get_rubygemslocation("${STAGING_BINDIR_NATIVE}")}" +RUBY_GEM_VERSION ?= "${@get_rubygemsversion("${STAGING_BINDIR_NATIVE}")}" + +export GEM_HOME = "${STAGING_DIR_NATIVE}/usr/lib/ruby/gems/${RUBY_GEM_VERSION}" + +RUBY_BUILD_GEMS ?= "${BPN}.gemspec" +RUBY_INSTALL_GEMS ?= "${BPN}-${BPV}.gem" + +RUBY_COMPILE_FLAGS ?= 'LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8"' + +ruby_do_compile() { + for gem in ${RUBY_BUILD_GEMS}; do + ${RUBY_COMPILE_FLAGS} gem build $gem + done +} + + +ruby_do_install() { + for gem in ${RUBY_INSTALL_GEMS}; do + gem install --ignore-dependencies --local --env-shebang --install-dir ${D}/${libdir}/ruby/gems/${RUBY_GEM_VERSION}/ $gem + done + + # create symlink from the gems bin directory to /usr/bin + for i in ${D}/${libdir}/ruby/gems/${RUBY_GEM_VERSION}/bin/*; do + if [ -e "$i" ]; then + if [ ! -d ${D}/${bindir} ]; then mkdir -p ${D}/${bindir}; fi + b=`basename $i` + ln -sf ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/bin/$b ${D}/${bindir}/$b + fi + done +} + +EXPORT_FUNCTIONS do_compile do_install + +PACKAGES = "${PN}-dbg ${PN} ${PN}-doc ${PN}-dev" + +FILES_${PN}-dbg += " \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems/*/*/.debug \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems/*/*/*/.debug \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems/*/*/*/*/.debug \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems/*/*/*/*/*/.debug \ + " + +FILES_${PN} += " \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/cache \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/bin \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/specifications \ + " + +FILES_${PN}-doc += " \ + ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/doc \ + "
meta-ruby/recipes-devtools/ruby/bundler_git.bb new file +29 -0
@@ -0,0 +1,29 @@ +SUMMARY = "Makes sure Ruby applications run the same code on every machine." +DESCRIPTION = "Bundler makes sure Ruby applications run the same code \ +on every machine. It does this by managing the gems that the \ +application depends on. Given a list of gems, it can automatically \ +download and install those gems, as well as any other gems needed by \ +the gems that are listed. Before installing gems, it checks the \ +versions of every gem to make sure that they are compatible, and can \ +all be loaded at the same time. After the gems have been installed, \ +Bundler can help you update some or all of them when new versions \ +become available. Finally, it records the exact versions that have \ +been installed, so that others can install the exact same gems." + +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://LICENSE.md;md5=196bb963e601609817d7e9ac9a64a867" + +PR = "r0" + +PV = "1.6.2" +SRCREV = "06e3647c117da210ffd15a174624497830addd7b" + +S = "${WORKDIR}/git" + +SRC_URI = " \ + git://github.com/bundler/bundler.git \ + " + +inherit ruby + +BBCLASSEXTEND = "native"
Signature · 1 line
1.8.3.2