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

Remove FFI as a dependency #1796

Merged
merged 5 commits into from
Jun 19, 2021
Merged

Remove FFI as a dependency #1796

merged 5 commits into from
Jun 19, 2021

Conversation

jordansissel
Copy link
Owner

@jordansissel jordansissel commented Jun 18, 2021

In this PR, the following changes shall occur:

  • Replace ChildProcess library with Ruby standard Process.spawn
  • Replace FFI providing mknod syscall with Ruby standard methods, where possible.
  • Replace FreeBSD package support xz library with external xz program.

Acceptance criteria: fpm can be installed without any ffi gem dependency.

Expected outcomes, all of the following:

  • Ruby 2.0-2.2 shall be supported again? (Needs more research)
  • New Apple M1 Macs shall be able to use fpm successfully.
  • Newer Arch systems which ship only Ruby FFI 1.15 shall be able to use fpm successfully

This PR aims to address issues listed in #1795

The childprocess library uses `ffi`. Historically, installing ffi has
brought challenges for fpm users. This change is an attempt to use
ruby standard methods to replace ChildProcess.

For #1795
This removes fpm's direct use of FFI and removes `ffi` as a direct
dependency. For #1795

Cases:
* A unix socket.
* A named pipe
* A charDev should now fail (like /dev/tty)
* A blockDev should now fail (like /dev/sda1)

NOTE: In this change, chardev and blockdev support have been removed.
These "copies" previously were just calling `mknod` with identical
mode, basically copying the `mode` from stat(2) to mknod(2).
Exceptions are now thrown for chardev and blockdev.

Test cases:

    # Try to package a named pipe.
    % mkfifo /tmp/z.pipe
    % bundle exec bin/fpm -s dir -t rpm -n example /tmp/z.pipe
    Created package {:path=>"example-1.0-1.x86_64.rpm"}

    % rpm -qlvp example-1.0-1.x86_64.rpm
    prw-rw-r--    1 root     root                        0 Jun 17 22:40 /tmp/z.pipe

    # Create the unix socket
    % nc -lU /tmp/z.sock

    # Package it into an rpm
    % bin/fpm -s dir -t rpm -n example /tmp/z.sock |& less
    {:timestamp=>"2021-06-17T22:33:27.780347-0700", :message=>"Created package", :path=>"example-1.0-1.x86_64.rpm"}

    # Verify the file is of socket type ('s' at beginning of file mode
    % rpm -qlvp example-1.0-1.x86_64.rpm
    srwxrwxr-x    1 root     root                        0 Jun 17 22:33 /tmp/z.sock
For #1795

This replaces another library which uses ffi with an implementation
that doesn't need ffi.

I am not certain this is an exact replacement, but for my casual tests,
comparing .txz files generated before/after this commit, things seem ok.
This would benefit from real freebsd testing, though.
The previous method using :if actually hides the test entirely from the run.
Now an rspec run will correctly(I hope?) show any skipped tests. The
goal is to remind me that sometimes my dev environment is missing
important tooling needed to fully test fpm.

Also: Skip pacman tests if bsdtar and zstd programs are missing.
@jordansissel
Copy link
Owner Author

rspec is working as well as can be expected. Notable failures are things that have failed for a while, unrelated to this change (like cpan issues due to fpm test suite invoking cpan... wrongly?)

Test 1: FFI is not installed, confirmed below:

% grep -c ffi fpm.gemspec Gemfile Gemfile.lock
fpm.gemspec:0
Gemfile:0
Gemfile.lock:0

I spot-checked a few manual tests (ffi -s gem -t rpm, etc) as well as watching successful runs of the test suite. 👍👍

  • I believe the childprocess replacement was successful.
  • mknod is replaced by appropriate alternate implementations where possible.
  • However, character device (like /dev/tty) and block devices are no longer supported in copies. It is unclear what negative impact this will have.
  • freebsd's package generation using ruby-xz is replaced with a tar -Jc ... equivalent that I hope is correct. There's no test suite for this package support, so I'll rely on users to report any issues.

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