summaryrefslogtreecommitdiffstats
path: root/meta-ruby/classes
diff options
context:
space:
mode:
authorMark Asselstine <mark.asselstine@windriver.com>2014-09-05 11:07:13 -0400
committerMartin Jansa <Martin.Jansa@gmail.com>2014-09-26 05:42:52 +0200
commit8c2e27e68642224df084eed14c2ad1de4f1bb0a5 (patch)
tree4a8d1aaceac36d1cfb6f93242eae6826ab0a809d /meta-ruby/classes
parented698c4dba606b9d0c36c68023004046417db251 (diff)
downloadmeta-openembedded-8c2e27e68642224df084eed14c2ad1de4f1bb0a5.tar.gz
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. Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Diffstat (limited to 'meta-ruby/classes')
-rw-r--r--meta-ruby/classes/ruby.bbclass125
1 files changed, 125 insertions, 0 deletions
diff --git a/meta-ruby/classes/ruby.bbclass b/meta-ruby/classes/ruby.bbclass
new file mode 100644
index 000000000..9c4fcf9c3
--- /dev/null
+++ b/meta-ruby/classes/ruby.bbclass
@@ -0,0 +1,125 @@
1BPV ?= "${PV}"
2
3DEPENDS += " \
4 ruby-native \
5"
6RDEPENDS_${PN} += " \
7 ruby \
8"
9
10def get_rubyversion(p):
11 import re
12 from os.path import isfile
13 import subprocess
14 found_version = "SOMETHING FAILED!"
15
16 cmd = "%s/ruby" % p
17
18 if not isfile(cmd):
19 return found_version
20
21 version = subprocess.Popen([cmd, "--version"], stdout=subprocess.PIPE).communicate()[0]
22
23 r = re.compile("ruby ([0-9]+\.[0-9]+\.[0-9]+)*")
24 m = r.match(version)
25 if m:
26 found_version = m.group(1)
27
28 return found_version
29
30def get_rubygemslocation(p):
31 import re
32 from os.path import isfile
33 import subprocess
34 found_loc = "SOMETHING FAILED!"
35
36 cmd = "%s/gem" % p
37
38 if not isfile(cmd):
39 return found_loc
40
41 loc = subprocess.Popen([cmd, "env"], stdout=subprocess.PIPE).communicate()[0]
42
43 r = re.compile(".*\- (/usr.*/ruby/gems/.*)")
44 for line in loc.split('\n'):
45 m = r.match(line)
46 if m:
47 found_loc = m.group(1)
48 break
49
50 return found_loc
51
52def get_rubygemsversion(p):
53 import re
54 from os.path import isfile
55 import subprocess
56 found_version = "SOMETHING FAILED!"
57
58 cmd = "%s/gem" % p
59
60 if not isfile(cmd):
61 return found_version
62
63 version = subprocess.Popen([cmd, "env", "gemdir"], stdout=subprocess.PIPE).communicate()[0]
64
65 r = re.compile(".*([0-9]+\.[0-9]+\.[0-9]+)$")
66 m = r.match(version)
67 if m:
68 found_version = m.group(1)
69
70 return found_version
71
72RUBY_VERSION ?= "${@get_rubyversion("${STAGING_BINDIR_NATIVE}")}"
73RUBY_GEM_DIRECTORY ?= "${@get_rubygemslocation("${STAGING_BINDIR_NATIVE}")}"
74RUBY_GEM_VERSION ?= "${@get_rubygemsversion("${STAGING_BINDIR_NATIVE}")}"
75
76export GEM_HOME = "${STAGING_DIR_NATIVE}/usr/lib/ruby/gems/${RUBY_GEM_VERSION}"
77
78RUBY_BUILD_GEMS ?= "${BPN}.gemspec"
79RUBY_INSTALL_GEMS ?= "${BPN}-${BPV}.gem"
80
81RUBY_COMPILE_FLAGS ?= 'LANG="en_US.UTF-8" LC_ALL="en_US.UTF-8"'
82
83ruby_do_compile() {
84 for gem in ${RUBY_BUILD_GEMS}; do
85 ${RUBY_COMPILE_FLAGS} gem build $gem
86 done
87}
88
89
90ruby_do_install() {
91 for gem in ${RUBY_INSTALL_GEMS}; do
92 gem install --ignore-dependencies --local --env-shebang --install-dir ${D}/${libdir}/ruby/gems/${RUBY_GEM_VERSION}/ $gem
93 done
94
95 # create symlink from the gems bin directory to /usr/bin
96 for i in ${D}/${libdir}/ruby/gems/${RUBY_GEM_VERSION}/bin/*; do
97 if [ -e "$i" ]; then
98 if [ ! -d ${D}/${bindir} ]; then mkdir -p ${D}/${bindir}; fi
99 b=`basename $i`
100 ln -sf ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/bin/$b ${D}/${bindir}/$b
101 fi
102 done
103}
104
105EXPORT_FUNCTIONS do_compile do_install
106
107PACKAGES = "${PN}-dbg ${PN} ${PN}-doc ${PN}-dev"
108
109FILES_${PN}-dbg += " \
110 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems/*/*/.debug \
111 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems/*/*/*/.debug \
112 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems/*/*/*/*/.debug \
113 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems/*/*/*/*/*/.debug \
114 "
115
116FILES_${PN} += " \
117 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/gems \
118 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/cache \
119 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/bin \
120 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/specifications \
121 "
122
123FILES_${PN}-doc += " \
124 ${libdir}/ruby/gems/${RUBY_GEM_VERSION}/doc \
125 "