From 5d5723095915d1fff2efda4c4195e4c804c1a351 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 4 Jul 2013 15:25:46 +0000 Subject: [PATCH] mkmf.rb: header in framework * lib/mkmf.rb (have_framework): allow header file to check. [ruby-core:55745] [Bug #8593] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/mkmf.rb | 8 ++++++-- test/mkmf/test_framework.rb | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe84379fe8..1b31b334b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Jul 5 00:25:39 2013 Nobuyoshi Nakada + + * lib/mkmf.rb (have_framework): allow header file to check. + [ruby-core:55745] [Bug #8593] + Thu Jul 4 22:31:00 2013 Charlie Somerville * object.c (rb_obj_equal): Fixed an rb_obj_equal documentation typo diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 7f472f42eb..a35be75142 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -1081,9 +1081,13 @@ SRC # the +HAVE_FRAMEWORK_RUBY+ preprocessor macro would be passed to the # compiler. # - def have_framework(fw, &b) + # If +fw+ is a pair of the framework name and its header file name + # that header file is checked, instead of the normally used header + # file which is named same as the framework. + def have_framework((fw, header), &b) + header ||= "#{fw}.h" checking_for fw do - src = cpp_include("#{fw}/#{fw}.h") << "\n" "int main(void){return 0;}" + src = cpp_include("#{fw}/#{header}") << "\n" "int main(void){return 0;}" opt = " -framework #{fw}" if try_link(src, "-ObjC#{opt}", &b) $defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp)) diff --git a/test/mkmf/test_framework.rb b/test/mkmf/test_framework.rb index 39171a0bb6..1b595aab7a 100644 --- a/test/mkmf/test_framework.rb +++ b/test/mkmf/test_framework.rb @@ -2,6 +2,24 @@ require_relative 'base' class TestMkmf class TestHaveFramework < TestMkmf + def create_framework(fw, hdrname = "#{fw}.h") + Dir.mktmpdir("frameworks") do |dir| + fwdir = "#{dir}/#{fw}.framework" + hdrdir = "#{fwdir}/Headers" + FileUtils.mkdir_p(hdrdir) + File.write("#{hdrdir}/#{hdrname}", "") + src = "#{fwdir}/main.c" + File.write(src, "void #{fw}(void) {}") + cmd = LINK_SO.dup + RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src)) + cmd.sub!("$@", "#{fwdir}/#{fw}") + cmd.sub!(/ -bundle /, ' -dynamiclib ') + assert(xsystem(cmd), MKMFLOG) + $INCFLAGS << " " << "-F#{dir}".quote + yield fw, hdrname + end + end + def test_core_foundation_framework assert(have_framework("CoreFoundation"), mkmflog("try as Objective-C")) end @@ -10,5 +28,19 @@ class TestMkmf assert(have_framework("CoreFoundation"), mkmflog("try as Objective-C")) assert(have_framework("Cocoa"), mkmflog("try as Objective-C")) end + + def test_empty_framework + create_framework("MkmfTest") do |fw| + assert(have_framework(fw), MKMFLOG) + end + end + + def test_different_name_header + bug8593 = '[ruby-core:55745] [Bug #8593]' + create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname| + assert(!have_framework(fw), MKMFLOG) + assert(have_framework([fw, hdrname]), MKMFLOG) + end + end end end if /darwin/ =~ RUBY_PLATFORM