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

mkmf: Add the extra option --with-verbose to enable verbose mode. #7863

Merged
merged 1 commit into from
May 29, 2023

Conversation

junaruga
Copy link
Member

@junaruga junaruga commented May 25, 2023

The Ruby ticket is https://bugs.ruby-lang.org/issues/19695.

This PR is to add the new extra argument --with-verbose to the mkmf.rb, and the PR has 3 commits.

  1. mkmf: Add the extra option --with-verbose to enable verbose mode.
  2. mkmf: Add tests for MakeMakefile#with_config.
  3. mkmf: Add tests to test the verbose mode in MakeMakefile#configuration.

mkmf: Add the extra option --with-verbose to enable verbose mode.

The first commit is the main one of the feature.

This commit is to add an extra option to enable verbose mode (V=1) in the generated Makefile at runtime of the Ruby to print compiler command lines by the commands below when building native extensions. It's possible to enable the verbose mode by setting the environment variable MAKEFLAGS="V=1"[1] implemented in GNU make. However, I wanted to make a consistent user-interface not depending on the specific make's implementation.

$ ruby /path/to/extconf.rb -- --with-verbose

You can also add the extra option via rake-compiler gem.

$ rake compiler -- --with-verbose

If the extra option is not given, the value of the RbConfig::CONFIG["MKMF_VERBOSE"] enabled by the configure option below is used.

$ ./configure --enable-mkmf-verbose

[1] https://www.gnu.org/software/make/manual/html_node/Variables_002fRecursion.html

Co-authored-by: Nobuyoshi Nakada nobu@ruby-lang.org

mkmf: Add tests for MakeMakefile#with_config.

This second commit is to test the MakeMakefile#with_config that is used in the main commit. As I couldn't find the test of the with_config, I created it.

mkmf: Add tests to test the verbose mode in MakeMakefile#configuration.

The third commit is the tests to test the use cases of the first commit.

test/mkmf/base.rb Outdated Show resolved Hide resolved
This commit is to add an extra option to enable verbose mode (V=1) in the
generated `Makefile` at runtime of the Ruby to print compiler command lines by
the commands below when building native extensions. It's possible to enable the
verbose mode by setting the environment variable `MAKEFLAGS="V=1"`[1]
implemented in GNU make. However, I wanted to make a consistent user-interface
not depending on the specific make's implementation.

```
$ ruby /path/to/extconf.rb -- --with-verbose
```

You can also add the extra option via rake-compiler gem.

```
$ rake compiler -- --with-verbose
```

If the extra option is not given, the value of the
`RbConfig::CONFIG["MKMF_VERBOSE"]` enabled by the configure option below is
used.

```
$ ./configure --enable-mkmf-verbose
```

For the unit tests, updated the following files.

* The `test/mkmf/test_configuration.rb` was created to test the cases with the
  `configuration` method and this implementation.
* Updated the `TestMkmf#assert_separately` to set the extra
  arguments in `test/mkmf/base.rb`. Updated tests using the `assert_separately`.
* Added tests for `MakeMakefile#with_config` in the `test/mkmf/test_config.rb`.

[1] https://www.gnu.org/software/make/manual/html_node/Variables_002fRecursion.html

Fixes [Bug #19695]

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
def assert_separately(args, src, *rest, **options)
super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\nEND{teardown}\n#{src}", *rest, **options)
def assert_separately(args, extra_args, src, *rest, **options)
super(args + ["-r#{__FILE__}"] + %w[- --] + extra_args,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this part, I wanted to write args + %w[-r#{__FILE__} - --] + extra_args. However, I saw the #{__FILE__} was not converted to the value. So, the ["-r#{__FILE__}"] + %w[- --] is a bit compromised way.

$ ruby -v
ruby 3.3.0dev (2023-05-25T12:45:21Z wip/mkmf-verbose-r.. cbeba2ed16) [x86_64-linux]

$ which irb
~/.local/ruby-cbeba2ed16/bin/irb

$ irb
irb(main):001:0> %w[-r#{__FILE__} - --]
=> ["-r\#{__FILE__}", "-", "--"]

irb(main):002:0> %[-r#{__FILE__} - --]
=> "-r(irb) - --"

@junaruga
Copy link
Member Author

I rebased, fixing the review items. Thanks for that. I squashed the 3 commits to 1 commit.

@junaruga junaruga merged commit 57459b8 into ruby:master May 29, 2023
94 checks passed
@junaruga junaruga deleted the wip/mkmf-verbose-runtime branch May 29, 2023 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants