From 2a5af64d0e6a75f698d1c2a9c10645a1cb379fed Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Thu, 5 Dec 2013 00:06:29 +0200 Subject: [PATCH] Revamp patching functionality and add clang patches This commit fixes #94 and closes #105 --- ext/libv8/builder.rb | 16 ++---- ext/libv8/compiler/clang.rb | 2 +- ext/libv8/compiler/gcc.rb | 2 +- ext/libv8/patcher.rb | 54 +++++++++++++++++++ .../do-not-imply-vfp3-and-armv7.patch | 0 patches/clang/no-unused-private-field.patch | 28 ++++++++++ ...n-types-and-unused-function-warnings.patch | 28 ++++++++++ .../gcc48-wno-unused-local-typedefs.patch | 0 8 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 ext/libv8/patcher.rb rename patches/{ => arm}/do-not-imply-vfp3-and-armv7.patch (100%) create mode 100644 patches/clang/no-unused-private-field.patch create mode 100644 patches/clang33/silence-nested-anon-types-and-unused-function-warnings.patch rename patches/{ => gcc48}/gcc48-wno-unused-local-typedefs.patch (100%) diff --git a/ext/libv8/builder.rb b/ext/libv8/builder.rb index 17ba3b5..e78caff 100755 --- a/ext/libv8/builder.rb +++ b/ext/libv8/builder.rb @@ -3,12 +3,14 @@ require File.expand_path '../compiler', __FILE__ require File.expand_path '../arch', __FILE__ require File.expand_path '../make', __FILE__ require File.expand_path '../checkout', __FILE__ +require File.expand_path '../patcher', __FILE__ module Libv8 class Builder include Libv8::Arch include Libv8::Make include Libv8::Checkout + include Libv8::Patcher def initialize @compiler = choose_compiler @@ -45,7 +47,7 @@ module Libv8 checkout! setup_python! setup_build_deps! - apply_patches! + patch! *patch_directories_for(@compiler) print_build_info puts `env CXX=#{@compiler} LINK=#{@compiler} #{make} #{make_flags}` end @@ -73,18 +75,6 @@ module Libv8 `ln -fs #{GYP_Source} build/gyp` end - def apply_patches! - File.open(".applied_patches", File::RDWR|File::CREAT) do |f| - available_patches = Dir.glob(File.expand_path '../../../patches/*.patch', __FILE__).sort - applied_patches = f.readlines.map(&:chomp) - - (available_patches - applied_patches).each do |patch| - `patch -p1 -N < #{patch}` - f.puts patch - end - end - end - private def choose_compiler diff --git a/ext/libv8/compiler/clang.rb b/ext/libv8/compiler/clang.rb index 4764d6d..da84878 100644 --- a/ext/libv8/compiler/clang.rb +++ b/ext/libv8/compiler/clang.rb @@ -8,7 +8,7 @@ module Libv8 end def compatible? - version > '3.1' + version >= '3.1' end end end diff --git a/ext/libv8/compiler/gcc.rb b/ext/libv8/compiler/gcc.rb index b8ff94f..e2cb041 100644 --- a/ext/libv8/compiler/gcc.rb +++ b/ext/libv8/compiler/gcc.rb @@ -8,7 +8,7 @@ module Libv8 end def compatible? - version > '4.2' and version < '4.9' + version > '4.3' and version < '4.9' end end end diff --git a/ext/libv8/patcher.rb b/ext/libv8/patcher.rb new file mode 100644 index 0000000..1c5d0bf --- /dev/null +++ b/ext/libv8/patcher.rb @@ -0,0 +1,54 @@ +module Libv8 + module Patcher + PATCH_DIRECTORY = File.expand_path '../../../patches', __FILE__ + + module_function + + def patch_directories_for(compiler) + patch_directories = [] + + case + when compiler.target =~ /arm/ + patch_directories += 'arm' + end + + case compiler + when Compiler::GCC + patch_directories << 'gcc48' if compiler.version >= '4.8' + when Compiler::Clang + patch_directories << 'clang' + patch_directories << 'clang33' if compiler.version >= '3.3' + end + + patch_directories + end + + def patch_directories(*additional_directories) + absolute_paths = [PATCH_DIRECTORY] + + additional_directories.each do |directory| + absolute_paths << File.join(PATCH_DIRECTORY, directory) + end + + absolute_paths.uniq + end + + def patches(*additional_directories) + patch_directories(*additional_directories).map do |directory| + Dir.glob(File.join directory, '*.patch') + end.flatten.sort + end + + def patch!(*additional_directories) + File.open(".applied_patches", File::RDWR|File::CREAT) do |f| + available_patches = patches *additional_directories + applied_patches = f.readlines.map(&:chomp) + + (available_patches - applied_patches).each do |patch| + `patch -p1 -N < #{patch}` + f.puts patch + end + end + end + end +end diff --git a/patches/do-not-imply-vfp3-and-armv7.patch b/patches/arm/do-not-imply-vfp3-and-armv7.patch similarity index 100% rename from patches/do-not-imply-vfp3-and-armv7.patch rename to patches/arm/do-not-imply-vfp3-and-armv7.patch diff --git a/patches/clang/no-unused-private-field.patch b/patches/clang/no-unused-private-field.patch new file mode 100644 index 0000000..cf84432 --- /dev/null +++ b/patches/clang/no-unused-private-field.patch @@ -0,0 +1,28 @@ +diff --git a/build/common.gypi b/build/common.gypi +index 3a59639..14bf0f9 100644 +--- a/build/common.gypi ++++ b/build/common.gypi +@@ -376,7 +376,8 @@ + }], + ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="netbsd"', { + 'cflags': [ '-Wall', '<(werror)', '-W', '-Wno-unused-parameter', +- '-Wnon-virtual-dtor', '-Woverloaded-virtual' ], ++ '-Wnon-virtual-dtor', '-Woverloaded-virtual', ++ '-Wno-unused-private-field' ], + }], + ['OS=="linux" and v8_enable_backtrace==1', { + # Support for backtrace_symbols. +diff --git a/build/standalone.gypi b/build/standalone.gypi +index 125c5bf..c8d9b4f 100644 +--- a/build/standalone.gypi ++++ b/build/standalone.gypi +@@ -98,7 +98,8 @@ + 'target_defaults': { + 'cflags': [ '-Wall', '<(werror)', '-W', '-Wno-unused-parameter', + '-Wnon-virtual-dtor', '-pthread', '-fno-rtti', +- '-fno-exceptions', '-pedantic' ], ++ '-fno-exceptions', '-pedantic', ++ '-Wno-unused-private-field' ], + 'ldflags': [ '-pthread', ], + 'conditions': [ + [ 'OS=="linux"', { diff --git a/patches/clang33/silence-nested-anon-types-and-unused-function-warnings.patch b/patches/clang33/silence-nested-anon-types-and-unused-function-warnings.patch new file mode 100644 index 0000000..b395751 --- /dev/null +++ b/patches/clang33/silence-nested-anon-types-and-unused-function-warnings.patch @@ -0,0 +1,28 @@ +diff --git a/build/common.gypi b/build/common.gypi +index 14bf0f9..301109a 100644 +--- a/build/common.gypi ++++ b/build/common.gypi +@@ -377,7 +377,8 @@ + ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="netbsd"', { + 'cflags': [ '-Wall', '<(werror)', '-W', '-Wno-unused-parameter', + '-Wnon-virtual-dtor', '-Woverloaded-virtual', +- '-Wno-unused-private-field' ], ++ '-Wno-unused-private-field', '-Wno-nested-anon-types', ++ '-Wno-unused-function' ], + }], + ['OS=="linux" and v8_enable_backtrace==1', { + # Support for backtrace_symbols. +diff --git a/build/standalone.gypi b/build/standalone.gypi +index c8d9b4f..ddd1693 100644 +--- a/build/standalone.gypi ++++ b/build/standalone.gypi +@@ -99,7 +99,8 @@ + 'cflags': [ '-Wall', '<(werror)', '-W', '-Wno-unused-parameter', + '-Wnon-virtual-dtor', '-pthread', '-fno-rtti', + '-fno-exceptions', '-pedantic', +- '-Wno-unused-private-field' ], ++ '-Wno-unused-private-field', '-Wno-nested-anon-types', ++ '-Wno-unused-function' ], + 'ldflags': [ '-pthread', ], + 'conditions': [ + [ 'OS=="linux"', { diff --git a/patches/gcc48-wno-unused-local-typedefs.patch b/patches/gcc48/gcc48-wno-unused-local-typedefs.patch similarity index 100% rename from patches/gcc48-wno-unused-local-typedefs.patch rename to patches/gcc48/gcc48-wno-unused-local-typedefs.patch