Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON, REXML, and ruby 1.9.3 works again! #1950

Merged
merged 3 commits into from
Nov 3, 2022

Conversation

jordansissel
Copy link
Owner

@jordansissel jordansissel commented Nov 3, 2022

This change allows at least some of fpm to work under Ruby 1.9.3. I can produce rpms and debs using Ruby 1.9.3 and this patch!

The osxpkg format doesn't seem to work for me on Ruby 1.9.3 because REXML seems to crash with an error.

This is accomplished by:

  • removing the json dependency which has been included in Ruby by default since Ruby 1.9.1
  • delaying rexml loading so that only uses that require xml parsing will load that library, such as osxpkg parsing.
  • working around a frozen string modification error in rubygems under Ruby 1.9.3

You, reader, may be asking, "Why?"

In #1949, we discuss raising the minimum version of ruby required by fpm. At time of writing, the minimum version is set to '>= 1.9.3', and I'm somewhat slow to raise it without good cause.

Historically, there's been a race for some Ruby libraries to abandon older versions of ruby. However, as a sysadmin, I'm keenly aware that many folks may not have the authority to upgrade Ruby on their systems, so it feels natural to continue keep fpm compatible with older versions of Ruby.

I've tried to be consistent in this strategy:

Related issues:

@jordansissel
Copy link
Owner Author

@edolnx I'm not sure if this patch helps your journey on #1949, but maybe it does?

I was able to produce deb and rpm packages with fpm 1.14.2 (plus this PR's patch) using Ruby 1.9.3 from the docker ruby:1.9.3 container image.

⓿ snickerdoodle(~/projects/fpm) issue/1949/support-old-rubies
% podman run -v $PWD:/fpm -it docker.io/ruby:1.9.3 bash

root@d46235e10f4d:/fpm# gem build fpm.gemspec
  Successfully built RubyGem
  Name: fpm
  Version: 1.14.2
  File: fpm-1.14.2.gem

root@d46235e10f4d:/fpm# gem install ./fpm-1.14.2.gem
Fetching: cabin-0.9.0.gem (100%)
Fetching: backports-3.23.0.gem (100%)
Fetching: arr-pm-0.0.12.gem (100%)
Fetching: clamp-1.0.1.gem (100%)
Fetching: stud-0.0.23.gem (100%)
Fetching: mustache-0.99.8.gem (100%)
Fetching: insist-1.0.0.gem (100%)
Fetching: dotenv-2.8.1.gem (100%)
Fetching: pleaserun-0.0.32.gem (100%)
Fetching: rexml-3.2.5.gem (100%)
Successfully installed cabin-0.9.0
Successfully installed backports-3.23.0
Successfully installed arr-pm-0.0.12
Successfully installed clamp-1.0.1
Successfully installed stud-0.0.23
Successfully installed mustache-0.99.8
Successfully installed insist-1.0.0
Successfully installed dotenv-2.8.1
Successfully installed pleaserun-0.0.32
Successfully installed rexml-3.2.5
Successfully installed fpm-1.14.2
11 gems installed

root@d46235e10f4d:/fpm# fpm -s empty -t deb -n example
Ractor not backported to Ruby 1.x
Created package {:path=>"example_1.0_all.deb"}

root@d46235e10f4d:/fpm# dpkg -i example_1.0_all.deb
Selecting previously unselected package example.
(Reading database ... 27896 files and directories currently installed.)
Preparing to unpack example_1.0_all.deb ...
Unpacking example (1.0) ...
Setting up example (1.0) ...

@jordansissel
Copy link
Owner Author

I did a bit of digging tonight and found a few open issues related to json and rexml and this should resolve all of those. Nice!

@jordansissel
Copy link
Owner Author

356 examples, 0 failures, 14 pending

The 14 pending tests are because I don't have virtualenv setup on my workstation.

The original `json` gem dependency was added in the original fpm.gemspec
because, at the time, Ruby 1.8.7 was common and required an external
`json` dependency for parsing JSON.

Later, Ruby releases since 1.9.1 have bundled `json`[1].

Therefore, it feels safe to remove this dependency. As a bonus, the
rubygems `json` gem places requirements on the minimum version of Ruby.
At this time, the latest `json` gem requires Ruby >= 2.3.

If the `json` gem dependency is removed, fpm will still retain the
ability to process JSON while lowering the minimum required Ruby version
to Ruby 1.9.x -- It's not perfect, but it's a start! :)

[1] https://docs.ruby-lang.org/en/2.3.0/NEWS-1_9_1.html

The idea for this change change came originally from a discussion
with @edolnx in #1949

Fixes #1741, #1264, #1949
On older versions of rubygems, `Gem::Version.new(...)` calls
`String#strip!` on the argument in the constructor. This causes a
problem on Ruby 1.9.3 where the RUBY_VERSION constant is a frozen
string.

The workaround is to make a copy of this string that is unfrozen, and
`String#dup` seems to work :)
This helps avoid a startup crash on Ruby 1.9.3 where the `rexml` gem
crashes when loaded due to syntax errors.

Fixes #1798, #1800, #1784
@jordansissel
Copy link
Owner Author

fpm 1.15.0 is released and contains this improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant