From a832f5cb98ee952a3e7ceeddf59065b9c1f430b4 Mon Sep 17 00:00:00 2001 From: Jun Aruga Date: Mon, 22 May 2023 20:21:57 +0200 Subject: [PATCH] CI: Enable the verbose mode in the mkmf.rb. 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 --- .github/workflows/test.yml | 9 +++++++++ tool/enable-mkmf-verbose | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 tool/enable-mkmf-verbose diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 374447f87..cb33a8d24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 }} diff --git a/tool/enable-mkmf-verbose b/tool/enable-mkmf-verbose new file mode 100755 index 000000000..be039077c --- /dev/null +++ b/tool/enable-mkmf-verbose @@ -0,0 +1,24 @@ +#!/bin/sh + +set -eux + +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}" + +# Print the difference between the original and modified file. This is useful +# to debug when the `mkmf.rb` may change in the future. And check if the +#`mkmf.rb` was modified. Because the `sed` command returns the exit status 0 no +# matter it replaces successfully or not. +if diff "${mkmf_rb_path}.orig" "${mkmf_rb_path}"; then + echo "error: ${mkmf_rb_path} was not modified." 1>&2 + exit 1 +elif [ "${?}" != 1 ]; then + echo "error: diff was failed." 1>&2 + exit 1 +fi