Skip to content

Commit

Permalink
Enable the verbose mode in the mkmf.rb.
Browse files Browse the repository at this point in the history
Enable the verbose option in mkmf.rb to print the compiling commands in the
process of the `rake compile`. Because it's helpful to see what compiler
warnings are checked.

The script only runs in Linux and macOS. Not Windows. Because the sh script
doesn't work in Windows. For the syntax, see the reference.[1]

Right now there is a way to configure Ruby with `--enable-mkmf-verbose` in this
purpose. But there is no formal way to enable the verbose mode in runtime of
Ruby. My intention is that this commit is a workaround for this purpose.

[1] https://docs.github.com/en/actions/learn-github-actions/variables
  * Default environment variables - RUNNER_OS
  * Detecting the operating system
  • Loading branch information
junaruga committed May 22, 2023
1 parent 08b0ed7 commit 915d05f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ jobs:
- name: depends
run: bundle install

# Enable the verbose option in mkmf.rb to print the compiling commands.
- name: enable mkmf verbose
run: tool/enable-mkmf-verbose
if: runner.os == 'Linux' || runner.os == 'macOS'

- name: compile
run: rake compile -- --enable-debug

Expand Down Expand Up @@ -129,6 +134,10 @@ jobs:
- name: depends
run: bundle install

- name: enable mkmf verbose
run: tool/enable-mkmf-verbose
if: runner.os == 'Linux' || runner.os == 'macOS'

- name: compile
run: rake compile -- --enable-debug --with-openssl-dir=$HOME/.openssl/${{ matrix.openssl }}

Expand Down
17 changes: 17 additions & 0 deletions tool/enable-mkmf-verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh -eu

set -x

gem_home="$(gem environment home)"
mkmf_rb_path="$(find "${gem_home}"/../.. -name mkmf.rb)"

# Backup the original file.
cp -p "${mkmf_rb_path}" "${mkmf_rb_path}.orig"

# Replace the target line to set the verbose option.
sed -i -e 's/^V = .*/V = 1/' "${mkmf_rb_path}"
# Check if the sed command above replaced the expected line properly.
grep -q '^V = ' "${mkmf_rb_path}"

# Print the difference between the original file and modified file.
diff "${mkmf_rb_path}.orig" "${mkmf_rb_path}" || :

0 comments on commit 915d05f

Please sign in to comment.