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

RakeBuilder: avoid frozen string issue #1819

Merged
merged 4 commits into from
Jan 16, 2017
Merged

Conversation

olleolleolle
Copy link
Member

@olleolleolle olleolleolle commented Jan 16, 2017

Description:

This PR adds a missing #dup ("convert frozen string literal to a mutable String object instance") in the same way that 45966be did.

The problem only appears when there're args to .build. To trigger this behavior, I duplicated a test and added a variable with a non-empty array of an empty string (to have benign test data).

What it looks like without the fix

Without this change, the user's failure will look like this:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
can't modify frozen String, created at
/home/travis/.rvm/rubies/jruby-9.1.7.0/lib/ruby/stdlib/rubygems/ext/rake_builder.rb:11

Reproduce

To reproduce the issue, write a mkrf_conf.rb which calls build. Here is an example ext/mkrf_conf.rb with a failing build: https://github.com/sickill/rainbow/blob/master/ext/mkrf_conf.rb

Tasks:

  • Describe the problem / feature
  • Write tests
  • Write code to solve the problem
  • Get code review from coworkers / friends

I will abide by the code of conduct.

  - See 45966be which had this fix most everywhere else
@olleolleolle
Copy link
Member Author

The failure to build was one 1.8.7 with the text:

rake aborted!
Installing gems 'bundler:1.12.0' 'builder:2.1.2' 'artifice:~> 0.6.0' 'sinatra:~> 1.4.7' 'rake:10.0.2' 'compact_index:~> 0.11.0' 'rack:< 2' for the tests to use failed!
./spec/support/rubygems_ext.rb:56:in `install_gems'
./spec/support/rubygems_ext.rb:40:in `setup'
/home/travis/build/rubygems/rubygems/bundler/Rakefile:58
/home/travis/build/rubygems/rubygems/bundler/Rakefile:29:in `invoke'
/home/travis/build/rubygems/rubygems/bundler/Rakefile:28:in `invoke'
/home/travis/build/rubygems/rubygems/bundler/Rakefile:80
/home/travis/build/rubygems/rubygems/bundler/Rakefile:29:in `invoke'
/home/travis/build/rubygems/rubygems/bundler/Rakefile:28:in `invoke'
/home/travis/.rvm/gems/ruby-1.8.7-p371/bin/ruby_executable_hooks:15
Tasks: TOP => spec:deps
(See full trace by running task with --trace)

#
# It should not fail with a non-empty args list either
def test_class_build_with_args
File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf|

Choose a reason for hiding this comment

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

There's a fair amount of duplication between this test-case and the one above. A meaningful one would be to extract would be this file creation. Especially since the two files are identical.

@olleolleolle
Copy link
Member Author

@teoljungberg There! It worked.

@@ -12,16 +12,9 @@ def setup
FileUtils.mkdir_p @ext
FileUtils.mkdir_p @dest_path
end

Choose a reason for hiding this comment

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

This should probably not be included.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for careful reading, T.

  - this avoids the reek warning Prima Donna Method; avoids confusing the reader
@segiddins
Copy link
Member

Good catch!
@homu r+

@homu
Copy link
Contributor

homu commented Jan 16, 2017

📌 Commit cffb000 has been approved by segiddins

@homu
Copy link
Contributor

homu commented Jan 16, 2017

⌛ Testing commit cffb000 with merge e0dd862...

homu added a commit that referenced this pull request Jan 16, 2017
RakeBuilder: avoid frozen string issue

# Description:

This PR adds a missing `#dup` ("convert frozen string literal to a mutable String object instance") in the same way that 45966be did.

The problem only appears when there're `args` to `.build`. To trigger this behavior, I duplicated a test and added a variable with a non-empty array of an empty string (to have benign test data).

**What it looks like without the fix**

Without this change, the user's failure will look like this:

```
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
can't modify frozen String, created at
/home/travis/.rvm/rubies/jruby-9.1.7.0/lib/ruby/stdlib/rubygems/ext/rake_builder.rb:11
```

**Reproduce**

To reproduce the issue, write a `mkrf_conf.rb` which calls `build`. Here is an example `ext/mkrf_conf.rb` with a failing build: https://github.com/sickill/rainbow/blob/master/ext/mkrf_conf.rb

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] Write code to solve the problem
- [x] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
@homu
Copy link
Contributor

homu commented Jan 16, 2017

💔 Test failed - status

@olleolleolle
Copy link
Member Author

@segiddins The 1.8.7 picks wrong deps now and then. Don't know why. It works half the time.

@@ -9,7 +9,7 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder

def self.build(extension, directory, dest_path, results, args=[], lib_dir=nil)
if File.basename(extension) =~ /mkrf_conf/i then
cmd = "#{Gem.ruby} #{File.basename extension}"
cmd = "#{Gem.ruby} #{File.basename extension}".dup
cmd << " #{args.join " "}" unless args.empty?
Copy link

Choose a reason for hiding this comment

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

Rewriting " #{args.join " "}" as " #{args.join(" ")}" is clearer to reader there's a string param passed into join and it's not " #{args.join " + "}". Maybe use single quotes to be more obvious.

Copy link
Member Author

Choose a reason for hiding this comment

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

@hmistry These are good ideas. Would you accept a PR from me about it?

Copy link

Choose a reason for hiding this comment

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

I don't have authority to accept PR's, sorry. Ask @segiddins or other RG core team members. I'm sure they won't mind since it's a low risk fix.

@segiddins
Copy link
Member

@homu retry

homu added a commit that referenced this pull request Jan 16, 2017
RakeBuilder: avoid frozen string issue

# Description:

This PR adds a missing `#dup` ("convert frozen string literal to a mutable String object instance") in the same way that 45966be did.

The problem only appears when there're `args` to `.build`. To trigger this behavior, I duplicated a test and added a variable with a non-empty array of an empty string (to have benign test data).

**What it looks like without the fix**

Without this change, the user's failure will look like this:

```
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
can't modify frozen String, created at
/home/travis/.rvm/rubies/jruby-9.1.7.0/lib/ruby/stdlib/rubygems/ext/rake_builder.rb:11
```

**Reproduce**

To reproduce the issue, write a `mkrf_conf.rb` which calls `build`. Here is an example `ext/mkrf_conf.rb` with a failing build: https://github.com/sickill/rainbow/blob/master/ext/mkrf_conf.rb

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] Write code to solve the problem
- [x] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
@homu
Copy link
Contributor

homu commented Jan 16, 2017

⌛ Testing commit cffb000 with merge 1c95b26...

@homu
Copy link
Contributor

homu commented Jan 16, 2017

☀️ Test successful - status

@homu homu merged commit cffb000 into rubygems:master Jan 16, 2017
@olleolleolle olleolleolle deleted the patch-1 branch January 17, 2017 07:35
segiddins pushed a commit that referenced this pull request Jan 20, 2017
RakeBuilder: avoid frozen string issue

# Description:

This PR adds a missing `#dup` ("convert frozen string literal to a mutable String object instance") in the same way that 45966be did.

The problem only appears when there're `args` to `.build`. To trigger this behavior, I duplicated a test and added a variable with a non-empty array of an empty string (to have benign test data).

**What it looks like without the fix**

Without this change, the user's failure will look like this:

```
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
can't modify frozen String, created at
/home/travis/.rvm/rubies/jruby-9.1.7.0/lib/ruby/stdlib/rubygems/ext/rake_builder.rb:11
```

**Reproduce**

To reproduce the issue, write a `mkrf_conf.rb` which calls `build`. Here is an example `ext/mkrf_conf.rb` with a failing build: https://github.com/sickill/rainbow/blob/master/ext/mkrf_conf.rb

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] Write code to solve the problem
- [x] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).

(cherry picked from commit 1c95b26)
michaelherold added a commit to michaelherold/interactor-contracts that referenced this pull request Jan 28, 2017
By enabled Danger, we enable the installation of Rubocop on the CI
environment. Rubocop depends on the "rainbow" library which has a build
error on certain versions of RubyGems. This has been fixed in newer
versions of RubyGems, so let's just update RubyGems prior to trying to
install anything.

See: ku1ik/rainbow#44
See: rubygems/rubygems#1819
michaelherold added a commit to michaelherold/interactor-contracts that referenced this pull request Jan 28, 2017
By enabled Danger, we enable the installation of Rubocop on the CI
environment. Rubocop depends on the "rainbow" library which has a build
error on certain versions of RubyGems. This has been fixed in newer
versions of RubyGems, so let's just update RubyGems prior to trying to
install anything.

See: ku1ik/rainbow#44
See: rubygems/rubygems#1819
michaelherold added a commit to michaelherold/interactor-contracts that referenced this pull request Jan 28, 2017
By enabled Danger, we enable the installation of Rubocop on the CI
environment. Rubocop depends on the "rainbow" library which has a build
error on certain versions of RubyGems. This has been fixed in newer
versions of RubyGems, so let's just update RubyGems prior to trying to
install anything.

See: ku1ik/rainbow#44
See: rubygems/rubygems#1819
dentarg added a commit to dentarg/dyno_metadata that referenced this pull request Feb 7, 2017
Related to recent build failures and rubygems/rubygems#1819
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.

6 participants