Skip to content

Commit

Permalink
Checkpoint for prototyping a bundled Ruby build
Browse files Browse the repository at this point in the history
- installing some gemspecs ordinarily installed under
  ${STAGEDIR}${PREFIX}/lib/ruby/gems/${RUBY_VER}/specifications/default/*.gemspec

- installing Ruby and all platform binary scripts under a RUBY_LIBEXEC
  prefix, with symlinks into host bindir

Multiple issues

1) This installation without a version suffix on 'ruby' and other tools
   may cause issues under gem build reusing features of the original
   build definition

~~~~
====> Compressing man pages (compress-man)
===>  Building package for ruby30-gems-3.0.8
pkg-static: Unable to access file /usr/home/u1000/wk/dist_wk/ports_main/devel/ruby-gems/work/stage/usr/local/bin/gem30:Nosuch file or directory
*** Error code 1

Stop.
make[1]: stopped in /usr/home/u1000/wk/dist_wk/ports_main/devel/ruby-gems
~~~~

2) TBD @ recursive lock error for the 'irb' script as installed under
   this build configuration

  cf. Gem.activate_bin_path in /usr/local/lib/ruby/site_ruby/3.0/rubygems.rb
      under Gem::LOADED_SPECS_MUTEX

      ... and subsq. loading of gem dependencies, under a
      single-threaded application

~~~~
[u1000@riparian ~/wk/dist_wk/ports_main/devel/ruby-gems ]$ env RUBYOPT='--debug -W2 -r debug'  /usr/local/libexec/ruby/3.0/bin/irb
[...]
Debug.rb
Emacs support available.

/usr/local/libexec/ruby/3.0/bin/irb:9:require 'rubygems'
(rdb:1) cont
[...]
Exception `ThreadError' at /usr/local/lib/ruby/site_ruby/3.0/rubygems/core_ext/kernel_gem.rb:67 - deadlock; recursive locking
Exception `ThreadError' at /usr/local/lib/ruby/site_ruby/3.0/rubygems/core_ext/kernel_require.rb:45 - deadlock; recursive locking
/usr/local/lib/ruby/site_ruby/3.0/rubygems/core_ext/kernel_require.rb:45: `deadlock; recursive locking' (ThreadError)
        from /usr/local/lib/ruby/site_ruby/3.0/rubygems.rb:306:in `block in activate_bin_path'
        from /usr/local/lib/ruby/site_ruby/3.0/rubygems.rb:304:in `synchronize'
        from /usr/local/lib/ruby/site_ruby/3.0/rubygems.rb:304:in `activate_bin_path'
        from /usr/local/libexec/ruby/3.0/bin/irb:23:in `<main>'
/usr/local/lib/ruby/site_ruby/3.0/rubygems/core_ext/kernel_require.rb:45:        raise
(rdb:1) w
--> freebsd#1 /usr/local/lib/ruby/site_ruby/3.0/rubygems/core_ext/kernel_require.rb:45:in `require'
    freebsd#2 /usr/local/lib/ruby/site_ruby/3.0/rubygems/request_set.rb:2:in `require'
    freebsd#3 /usr/local/lib/ruby/site_ruby/3.0/rubygems.rb:306:in `activate_bin_path'
    freebsd#4 /usr/local/libexec/ruby/3.0/bin/irb:23
~~~
  • Loading branch information
spchamp committed Dec 28, 2021
1 parent 8f26115 commit 297b7b7
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 184 deletions.
77 changes: 61 additions & 16 deletions lang/ruby30/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

PORTNAME= ruby
PORTVERSION= ${RUBY_PORTVERSION}
PORTREVISION= ${RUBY_PORTREVISION}
PORTREVISION= 1-refactor
PORTEPOCH= ${RUBY_PORTEPOCH}
CATEGORIES= lang ruby
MASTER_SITES= RUBY/${MASTER_SITE_SUBDIR_RUBY}
Expand All @@ -24,15 +24,19 @@ RUN_DEPENDS= libffi>=0:devel/libffi

USES= autoreconf cpe ssl tar:xz

CONFIGURE_ARGS= ${RUBY_CONFIGURE_ARGS} \
CONFIGURE_ARGS= ${RUBY_CONFIGURE_ARGS:N--program-suffix=*} \
--program-suffix="" \
--without-baseruby \
--disable-rpath \
--enable-pthread \
--enable-shared \
--enable-install-static-library \
--bindir="${PREFIX}/${RUBY_LIBEXEC}/bin" \
--mandir="${PREFIX}/${RUBY_LIBEXEC}/man" \
--with-ruby-version=minor \
--with-sitedir="${PREFIX}/lib/ruby/site_ruby" \
--with-vendordir="${PREFIX}/lib/ruby/vendor_ruby"
CONFIGURE_ENV= debugflags=
CONFIGURE_ENV+= debugflags=
CPPFLAGS+= -I${LOCALBASE}/include
GNU_CONFIGURE= yes
# Keep this, else ruby will fail to load libraries dependent of libpthread.
Expand All @@ -44,6 +48,8 @@ RUBY_VER= 3.0
USE_RUBY= yes
RUBY_NO_BUILD_DEPENDS= yes
RUBY_NO_RUN_DEPENDS= yes
## RUBY_LIBEXEC: Installation prefix for platform bin/man files, relative to PREFIX
RUBY_LIBEXEC= libexec/ruby/${RUBY_VER}

OPTIONS_DEFINE= CAPIDOCS DEBUG DOCS EXAMPLES GMP RDOC
OPTIONS_DEFAULT= RDOC LIBEDIT
Expand Down Expand Up @@ -71,6 +77,8 @@ CPE_VENDOR= ruby-lang
CPE_VERSION= ${RUBY_RELVERSION}
CPE_UPDATE= p${RUBY_PATCHLEVEL}

MANDIRS+= ${PREFIX}/libexec/ruby/${RUBY_VER}/man

.include <bsd.port.pre.mk>

# PORTREVISION/PORTEPOCH hack
Expand Down Expand Up @@ -112,8 +120,15 @@ PKGNAMESUFFIX= ${RUBY_SUFFIX}
PLIST_SUB+= IF_DEFAULT="@comment "
.endif

INSTALLED_SCRIPTS= ruby
INSTALLED_MANUALS= ruby
PLIST_SUB+= RUBY_LIBEXEC=${RUBY_LIBEXEC}

## POST_PLIST tgts will be used under _STAGE_SEQ,
## after the pkg-plist is processed during 'make stage'
POST_PLIST= add-plist-system-gems

HOST_SCRIPTS= ruby
HOST_MANUALS= ruby
INSTALLED_MANUALS= ${HOST_MANUALS} erb ri irb

EXTSAMPLES= bigdecimal/sample/*.rb

Expand All @@ -125,12 +140,6 @@ EXTDOCS= readline/README \
# Macros to change variables in rbconfig.rb
RB_SET_CONF_VAR=${SH} -c '${REINPLACE_CMD} -E -e "s,(CONFIG\[\"$$0\"\][[:space:]]*=[[:space:]]*)(\(?)(.*)(\)?),\1\2$$1\4," ${WRKSRC}/rbconfig.rb' --

post-patch:
# We get these from other ports
.for d in bin/* ext/dbm ext/gdbm ext/win32* lib/bundler* libexec/bundler* man/bundle* man/erb.1 man/gemfile* man/irb.1 man/ri.1
@${RM} -r ${BUILD_WRKSRC}/${d}
.endfor

post-build:
#
# Hack to allow modules to be installed into separate PREFIX and/or under user
Expand Down Expand Up @@ -159,19 +168,55 @@ pre-install-RDOC-on:
${MKDIR} ${STAGEDIR}${RUBY_RIDIR}
${MKDIR} ${STAGEDIR}${RUBY_SITERIDIR}


## platform gems to skip in generating the plist
TRIM_GEMS_DEFAULT=dbm gdbm
## bundled gems to skip from the plist
TRIM_GEMS_BUNDLED=typeprof rbs

## ensure that all default system gemspecs other than those in TRIM_GEMS_DEFAULT will be installed.
## This provides default gemspecs for source files otherwise installed as part of the implementation
${WRKDIR}/.gems_plist:
TRIM_GEMS="${TRIM_GEMS_DEFAULT} ${TRIM_GEMS_BUNDLED}"; \
${FIND} ${STAGEDIR}${PREFIX}/lib/ruby/gems/${RUBY_VER}/specifications/default -type f -name "*.gemspec" | \
{ while read SPEC; do FN=$$(basename $${SPEC}); FN=$${FN%.gemspec}; NAME=$${FN%-[0-9]*}; \
if [ "$${TRIM_GEMS#*$${NAME}}" == "$${TRIM_GEMS}" ] && [ "$${TRIM_GEMS%$${NAME}*}" == "$${TRIM_GEMS}" ]; then \
echo $${SPEC#${STAGEDIR}${PREFIX}/}; \
GEM_LIBDIR=lib/ruby/gems/${RUBY_VER}/gems/$${FN}; \
echo "@dir $${GEM_LIBDIR}"; \
find ${STAGEDIR}${PREFIX}/$${GEM_LIBDIR} -type f | ${SED} 's@^${STAGEDIR}${PREFIX}/@@'; fi; done; } | sort > ${WRKDIR}/.gems_plist

test-gems-plist: ${WRKDIR}/.gems_plist

add-plist-system-gems: ${WRKDIR}/.gems_plist
TMPF=$$(${MKTEMP} ${WRKDIR}/.plist-tmp.XXXXXX); \
cat ${TMPPLIST} ${WRKDIR}/.gems_plist | sort | uniq > $${TMPF} && \
mv $${TMPF} ${TMPPLIST}

post-install:
${MKDIR} -p ${STAGEDIR}${PREFIX}/bin
.for FILE in ${HOST_SCRIPTS}
## Ensure that a command with versioned suffix is avaialble in the normal bindir
cd ${STAGEDIR}${PREFIX}/bin && ${LN} -fs ../${RUBY_LIBEXEC}/bin/${FILE} ${FILE}${RUBY_SUFFIX}
.endfor
${MKDIR} -p ${STAGEDIR}${PREFIX}/${RUBY_LIBEXEC}/man/man1
.for FILE in ${INSTALLED_MANUALS}
## a hack for the Ruby build not using the --mandir provided to configure.
## this is normally run before the manual pages are compressed
cd ${STAGEDIR}${PREFIX}/man/man1; test -e ${FILE}.1 && mv ${FILE}.1 ${STAGEDIR}${PREFIX}/${RUBY_LIBEXEC}/man/man1/
.endfor
.if ${RUBY_VER} == ${RUBY_DEFAULT_VER}
#
# Link just installed "ruby" to "ruby27", etc.
#
. for FILE in ${INSTALLED_SCRIPTS}
${LN} -fs ${FILE}${RUBY_SUFFIX} ${STAGEDIR}${PREFIX}/bin/${FILE}
. for FILE in ${HOST_SCRIPTS}
cd ${STAGEDIR}${PREFIX}/bin && ${LN} -fs ../${RUBY_LIBEXEC}/bin/${FILE} ${FILE}
. endfor
#
# Link "ruby.1.gz" to "ruby27.1.gz", etc.
#
. for FILE in ${INSTALLED_MANUALS}
${LN} -fs ${FILE}${RUBY_SUFFIX}.1.gz ${STAGEDIR}${MANPREFIX}/man/man1/${FILE}.1.gz
. for FILE in ${HOST_MANUALS}
${LN} -fs ${PREFIX}/${RUBY_LIBEXEC}/man/man1/${FILE}.1.gz ${STAGEDIR}${MANPREFIX}/man/man1/${FILE}.1.gz
. endfor
.endif

Expand All @@ -181,7 +226,7 @@ post-install-DEBUG-off:
# bogus to hack.
#
.if defined(STRIP) && ${STRIP} == -s
${STRIP_CMD} ${STAGEDIR}${PREFIX}/bin/ruby${RUBY_SUFFIX}
${STRIP_CMD} ${STAGEDIR}${PREFIX}/${RUBY_LIBEXEC}/bin/ruby
${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/libruby${RUBY_SHLIBVER}.so.${RUBY_SHLIBVER}
${FIND} ${STAGEDIR}${RUBY_ARCHLIBDIR} -type f -name '*\.so' -exec ${STRIP_CMD} {} \;
.endif
Expand Down
167 changes: 0 additions & 167 deletions lang/ruby30/files/patch-tool_rbinstall.rb

This file was deleted.

15 changes: 14 additions & 1 deletion lang/ruby30/pkg-plist
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
%%IF_DEFAULT%%bin/ruby
bin/ruby%%RUBY_SUFFIX%%
%%RUBY_LIBEXEC%%/bin/bundle
%%RUBY_LIBEXEC%%/bin/bundler
%%RUBY_LIBEXEC%%/bin/erb
%%RUBY_LIBEXEC%%/bin/gem
%%RUBY_LIBEXEC%%/bin/irb
%%RUBY_LIBEXEC%%/bin/racc
%%RUBY_LIBEXEC%%/bin/rake
%%RUBY_LIBEXEC%%/bin/rdoc
%%RUBY_LIBEXEC%%/bin/ri
%%RUBY_LIBEXEC%%/bin/ruby
include/ruby-%%RUBY_VER%%/%%RUBY_ARCH%%/rb_mjit_min_header-%%RUBY_VERSION%%.h
include/ruby-%%RUBY_VER%%/%%RUBY_ARCH%%/ruby/config.h
include/ruby-%%RUBY_VER%%/ruby.h
Expand Down Expand Up @@ -985,7 +995,10 @@ lib/libruby%%RUBY_SHLIBVER%%.so.%%RUBY_SHLIBVER%%
%%RUBY_LIBDIR%%/yaml/store.rb
libdata/pkgconfig/ruby-%%RUBY_VER%%.pc
%%IF_DEFAULT%%man/man1/ruby.1.gz
man/man1/ruby%%RUBY_SUFFIX%%.1.gz
%%RUBY_LIBEXEC%%/man/man1/erb.1.gz
%%RUBY_LIBEXEC%%/man/man1/irb.1.gz
%%RUBY_LIBEXEC%%/man/man1/ri.1.gz
%%RUBY_LIBEXEC%%/man/man1/ruby.1.gz
%%DOCS%%%%RUBY_DOCDIR%%/COPYING
%%DOCS%%%%RUBY_DOCDIR%%/COPYING.ja
%%DOCS%%%%RUBY_DOCDIR%%/ChangeLog
Expand Down

0 comments on commit 297b7b7

Please sign in to comment.