Skip to content

Commit

Permalink
Do not pollute the source directory
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Feb 26, 2015
1 parent 46b89e6 commit d9e3e4d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
14 changes: 4 additions & 10 deletions .gitignore
Expand Up @@ -16,13 +16,7 @@ jruby.1.9.mspec
rubyspec_temp
Gemfile.lock

# We have to generate this file because it was removed in 1.9.
optional/capi/ext/rubyspec_version.h

# Do not exclude files needed by the specs.
# This explicitly unmasks files that may be
# masked by a parent dirs .gitignore file.
!*.bundle
!*.dylib
!*.so
!*.dll
*.bundle
*.dylib
*.so
*.dll
2 changes: 1 addition & 1 deletion optional/capi/class_spec.rb
Expand Up @@ -3,7 +3,7 @@

load_extension("class")

autoload :ClassUnderAutoload, "#{extension_path}/class_under_autoload_spec"
autoload :ClassUnderAutoload, "#{object_path}/class_under_autoload_spec"

describe :rb_path_to_class, :shared => true do
it "returns a class or module from a scoped String" do
Expand Down
17 changes: 14 additions & 3 deletions optional/capi/ext/rubyspec.h
Expand Up @@ -5,18 +5,29 @@
* with version incompatibilities.
*/

#include "rubyspec_version.h"
#include <ruby.h>
#ifdef HAVE_RUBY_VERSION_H
# include <ruby/version.h>
#else
# include <version.h>
#endif

#ifndef RUBY_VERSION_MAJOR
#define RUBY_VERSION_MAJOR RUBY_API_VERSION_MAJOR
#define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY RUBY_API_VERSION_TEENY
#endif

#define RUBY_VERSION_BEFORE(major,minor,teeny) \
((RUBY_VERSION_MAJOR < (major)) || \
(RUBY_VERSION_MAJOR == (major) && RUBY_VERSION_MINOR < (minor)) || \
(RUBY_VERSION_MAJOR == (major) && RUBY_VERSION_MINOR == (minor) && RUBY_VERSION_TEENY < (teeny)))

#if RUBY_VERSION_MAJOR >= 2 && RUBY_VERSION_MINOR >= 2
#if RUBY_VERSION_MAJOR > 2 || (RUBY_VERSION_MAJOR == 2 && RUBY_VERSION_MINOR >= 2)
#define RUBY_VERSION_IS_2_2
#endif

#if RUBY_VERSION_MAJOR >= 2 && RUBY_VERSION_MINOR >= 1
#if RUBY_VERSION_MAJOR > 2 || (RUBY_VERSION_MAJOR == 2 && RUBY_VERSION_MINOR >= 1)
#define RUBY_VERSION_IS_2_1
#endif

Expand Down
2 changes: 1 addition & 1 deletion optional/capi/fixtures/module.rb
Expand Up @@ -25,7 +25,7 @@ module M
class Super
end

autoload :ModuleUnderAutoload, "#{extension_path}/module_under_autoload_spec"
autoload :ModuleUnderAutoload, "#{object_path}/module_under_autoload_spec"
autoload :RubyUnderAutoload, File.expand_path('../module_autoload', __FILE__)

end
26 changes: 12 additions & 14 deletions optional/capi/spec_helper.rb
Expand Up @@ -3,20 +3,16 @@

require 'rbconfig'

# Generate a version.h file for specs to use
File.open File.expand_path("../ext/rubyspec_version.h", __FILE__), "w" do |f|
# Yes, I know CONFIG variables exist for these, but
# who knows when those could be removed without warning.
major, minor, teeny = RUBY_VERSION.split(".")
f.puts "#define RUBY_VERSION_MAJOR #{major}"
f.puts "#define RUBY_VERSION_MINOR #{minor}"
f.puts "#define RUBY_VERSION_TEENY #{teeny}"
end
objdir = File.expand_path("spec/rubyspec/optional/capi/ext")

define_method(:object_path) {objdir}
FileUtils.makedirs(objdir)

CAPI_RUBY_SIGNATURE = "#{RUBY_NAME}-#{RUBY_VERSION}"

def compile_extension(name)
path = extension_path
objdir = object_path

# TODO use rakelib/ext_helper.rb?
arch_hdrdir = nil
Expand All @@ -42,11 +38,11 @@ def compile_extension(name)
raise "Don't know how to build C extensions with #{RUBY_NAME}"
end

ext = File.join(path, "#{name}_spec")
source = "#{ext}.c"
obj = "#{ext}.o"
lib = "#{ext}.#{RbConfig::CONFIG['DLEXT']}"
signature = "#{ext}.sig"
ext = "#{name}_spec"
source = File.join(path, "#{ext}.c")
obj = File.join(objdir, "#{ext}.#{RbConfig::CONFIG['OBJEXT']}")
lib = File.join(objdir, "#{ext}.#{RbConfig::CONFIG['DLEXT']}")
signature = File.join(objdir, "#{ext}.sig")

ruby_header = File.join(hdrdir, "ruby.h")
rubyspec_header = File.join(path, "rubyspec.h")
Expand Down Expand Up @@ -74,6 +70,8 @@ def compile_extension(name)

unless $?.success? and File.exist?(obj)
puts "ERROR:\n#{output}"
puts "incflags=#{incflags}"
puts "cflags=#{cflags}"

This comment has been minimized.

Copy link
@eregon

eregon Feb 26, 2015

Member

@nobu What do you think about showing the full command so the user can copy/paste and try for himself?

raise "Unable to compile \"#{source}\""
end

Expand Down

0 comments on commit d9e3e4d

Please sign in to comment.