glib2 3.0.8 → 3.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -309,7 +309,18 @@ gobj_sig_connect_impl(gboolean after, int argc, VALUE *argv, VALUE self)
309
309
  if (!g_signal_parse_name(sig_name, CLASS2GTYPE(CLASS_OF(self)), &signal_id, &detail, TRUE))
310
310
  rb_raise(eNoSignalError, "no such signal: %s", sig_name);
311
311
 
312
- func = rb_block_proc();
312
+ {
313
+ ID id_create_signal_handler;
314
+ const char *normalized_signal_name;
315
+
316
+ CONST_ID(id_create_signal_handler, "create_signal_handler");
317
+ normalized_signal_name = g_signal_name(signal_id);
318
+ func = rb_funcall(self,
319
+ rb_intern("create_signal_handler"),
320
+ 2,
321
+ rb_str_new_cstr(normalized_signal_name),
322
+ rb_block_proc());
323
+ }
313
324
  rclosure = g_rclosure_new(func, rest,
314
325
  rbgobj_get_signal_func(signal_id));
315
326
  g_rclosure_attach((GClosure *)rclosure, self);
@@ -399,8 +399,9 @@ init_typemap(void)
399
399
  gtype_to_cinfo = g_hash_table_new(g_direct_hash, g_direct_equal);
400
400
  rb_global_variable(&klass_to_cinfo);
401
401
  klass_to_cinfo = rb_hash_new();
402
-
402
+ #ifndef RUBY_INTEGER_UNIFICATION
403
403
  _register_fundamental_klass_to_gtype(rb_cFixnum, G_TYPE_LONG);
404
+ #endif
404
405
  _register_fundamental_klass_to_gtype(rb_cFloat, G_TYPE_DOUBLE);
405
406
  _register_fundamental_klass_to_gtype(rb_cInteger, G_TYPE_LONG);
406
407
  _register_fundamental_klass_to_gtype(rb_cString, G_TYPE_STRING);
@@ -420,8 +421,13 @@ init_typemap(void)
420
421
  _register_fundamental_gtype_to_klass(G_TYPE_UINT64, rb_cInteger);
421
422
  _register_fundamental_gtype_to_klass(G_TYPE_INT, rb_cInteger);
422
423
  _register_fundamental_gtype_to_klass(G_TYPE_LONG, rb_cInteger);
424
+ #ifdef RUBY_INTEGER_UNIFICATION
425
+ _register_fundamental_gtype_to_klass(G_TYPE_CHAR, rb_cInteger);
426
+ _register_fundamental_gtype_to_klass(G_TYPE_UCHAR, rb_cInteger);
427
+ #else
423
428
  _register_fundamental_gtype_to_klass(G_TYPE_CHAR, rb_cFixnum);
424
429
  _register_fundamental_gtype_to_klass(G_TYPE_UCHAR, rb_cFixnum);
430
+ #endif
425
431
  _register_fundamental_gtype_to_klass(G_TYPE_STRING, rb_cString);
426
432
  _register_fundamental_gtype_to_klass(G_TYPE_ULONG, rb_cInteger);
427
433
  _register_fundamental_gtype_to_klass(G_TYPE_NONE, rb_cNilClass);
@@ -321,14 +321,8 @@ rbgobj_define_property_accessors(VALUE klass)
321
321
  g_string_append_printf(source,
322
322
  "def set_%s(val); set_property('%s', val); end\n",
323
323
  prop_name, pspec->name);
324
- #ifdef HAVE_NODE_ATTRASGN
325
324
  g_string_append_printf(source, "alias %s= set_%s\n",
326
325
  prop_name, prop_name);
327
- #else
328
- g_string_append_printf(source,
329
- "def %s=(val); set_property('%s', val); val; end\n",
330
- prop_name, pspec->name);
331
- #endif
332
326
  }
333
327
 
334
328
  g_free(buf);
@@ -27,10 +27,6 @@
27
27
  # define rb_errinfo() (ruby_errinfo)
28
28
  #endif
29
29
 
30
- #ifndef HAVE_RB_STR_NEW_CSTR
31
- # define rb_str_new_cstr(c_string) rb_str_new2(c_string)
32
- #endif
33
-
34
30
  #ifndef HAVE_RB_EXC_NEW_STR
35
31
  # define rb_exc_new_str(klass, message) rb_exc_new3(klass, message)
36
32
  #endif
@@ -116,10 +116,8 @@ rbgutil_generic_gtype(VALUE self)
116
116
  VALUE
117
117
  rbgutil_string_set_utf8_encoding(VALUE string)
118
118
  {
119
- #ifdef HAVE_RUBY_ENCODING_H
120
119
  if (!NIL_P(string))
121
120
  rb_enc_associate(string, rb_utf8_encoding());
122
- #endif
123
121
  return string;
124
122
  }
125
123
 
@@ -24,9 +24,7 @@
24
24
 
25
25
  #include <glib-object.h>
26
26
  #include "ruby.h"
27
- #ifdef HAVE_RUBY_ENCODING_H
28
- # include <ruby/encoding.h>
29
- #endif
27
+ #include <ruby/encoding.h>
30
28
  #include "rbglib.h"
31
29
  #include "rbgutil_list.h"
32
30
  #include "rbgutildeprecated.h"
@@ -126,6 +126,13 @@ module GLib
126
126
  end
127
127
  end
128
128
 
129
+ class Instantiatable
130
+ private
131
+ def create_signal_handler(signal_name, callback)
132
+ callback
133
+ end
134
+ end
135
+
129
136
  class Type
130
137
 
131
138
  def decendants
@@ -16,6 +16,8 @@
16
16
  # License along with this library; if not, write to the Free Software
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
+ require "open-uri"
20
+
19
21
  module GNOME2
20
22
  module Rake
21
23
  class ExternalPackage < Struct.new(:name,
@@ -97,13 +99,32 @@ module GNOME2
97
99
  super || []
98
100
  end
99
101
 
102
+ def latest_version
103
+ case download_site
104
+ when :gnome
105
+ latest_version_gnome
106
+ when :freedesktop
107
+ latest_version_freedesktop
108
+ when :freedesktop_gstreamer
109
+ latest_version_freedesktop_gstreamer
110
+ else
111
+ nil
112
+ end
113
+ end
114
+
100
115
  private
101
116
  def download_site_base_url
102
117
  case download_site
103
118
  when :gnome
104
- base_url = "http://ftp.gnome.org/pub/gnome/sources"
119
+ base_url = gnome_base_url
105
120
  release_series = version.gsub(/\A(\d+\.\d+)(?:[^\d].*)?\z/, '\1')
106
121
  base_url << "/#{name}/#{release_series}"
122
+ when :freedesktop
123
+ base_url = freedesktop_base_url
124
+ base_url << "/#{name}/release"
125
+ when :freedesktop_gstreamer
126
+ base_url = freedesktop_gstreamer_base_url
127
+ base_url << "/#{name}"
107
128
  when :gnu
108
129
  base_url = "http://ftp.gnu.org/pub/gnu/#{name}"
109
130
  else
@@ -112,6 +133,96 @@ module GNOME2
112
133
  base_url
113
134
  end
114
135
 
136
+ def gnome_base_url
137
+ "http://ftp.gnome.org/pub/gnome/sources"
138
+ end
139
+
140
+ def freedesktop_base_url
141
+ "https://www.freedesktop.org/software"
142
+ end
143
+
144
+ def freedesktop_gstreamer_base_url
145
+ "https://gstreamer.freedesktop.org/src"
146
+ end
147
+
148
+ def sort_versions(versions)
149
+ versions.sort_by do |version|
150
+ version.split(".").collect(&:to_i)
151
+ end
152
+ end
153
+
154
+ def latest_version_gnome
155
+ base_url = "#{gnome_base_url}/#{name}"
156
+ minor_versions = []
157
+ open(base_url) do |index|
158
+ index.read.scan(/<a (.+?)>/) do |content,|
159
+ case content
160
+ when /href="(\d+(?:\.\d+)*)\/?"/
161
+ minor_version = $1
162
+ next if development_minor_version_gnome?(minor_version)
163
+ minor_versions << minor_version
164
+ end
165
+ end
166
+ end
167
+ return nil if minor_versions.empty?
168
+
169
+ latest_minor_version = sort_versions(minor_versions).last
170
+ versions = []
171
+ open("#{base_url}/#{latest_minor_version}") do |index|
172
+ index.read.scan(/<a (.+?)>/) do |content,|
173
+ case content
174
+ when /href="#{Regexp.escape(name)}-
175
+ (\d+(?:\.\d+)*)
176
+ \.tar\.#{Regexp.escape(compression_method)}"/x
177
+ versions << $1
178
+ end
179
+ end
180
+ end
181
+ sort_versions(versions).last
182
+ end
183
+
184
+ def development_minor_version_gnome?(minor_version)
185
+ minor_version.split(".").last.to_i.odd?
186
+ end
187
+
188
+ def latest_version_freedesktop
189
+ base_url = "#{freedesktop_base_url}/#{name}/release"
190
+ versions = []
191
+ open(base_url) do |index|
192
+ index.read.scan(/<a (.+?)>/) do |content,|
193
+ case content
194
+ when /href="#{Regexp.escape(name)}-
195
+ (\d+(?:\.\d+)*)
196
+ \.tar\.#{Regexp.escape(compression_method)}"/x
197
+ versions << $1
198
+ end
199
+ end
200
+ end
201
+ sort_versions(versions).last
202
+ end
203
+
204
+ def latest_version_freedesktop_gstreamer
205
+ base_url = "#{freedesktop_gstreamer_base_url}/#{name}"
206
+ versions = []
207
+ open(base_url) do |index|
208
+ index.read.scan(/<a (.+?)>/) do |content,|
209
+ case content
210
+ when /href="#{Regexp.escape(name)}-
211
+ (\d+(?:\.\d+)*)
212
+ \.tar\.#{Regexp.escape(compression_method)}"/x
213
+ version = $1
214
+ next if development_version_freedesktop_gstreamer?(version)
215
+ versions << version
216
+ end
217
+ end
218
+ end
219
+ sort_versions(versions).last
220
+ end
221
+
222
+ def development_version_freedesktop_gstreamer?(version)
223
+ version.split(".")[1].to_i.odd?
224
+ end
225
+
115
226
  class WindowsConfiguration < Struct.new(:build,
116
227
  :include_paths,
117
228
  :library_paths,
@@ -124,7 +235,8 @@ module GNOME2
124
235
  :need_autoreconf,
125
236
  :build_concurrently,
126
237
  :use_cc_environment_variable,
127
- :gobject_introspection_compiler_split_args)
238
+ :gobject_introspection_compiler_split_args,
239
+ :use_gobject_introspection)
128
240
  def initialize(properties)
129
241
  super()
130
242
  properties.each do |key, value|
@@ -183,6 +295,10 @@ module GNOME2
183
295
  def gobject_introspection_compiler_split_args?
184
296
  gobject_introspection_compiler_split_args
185
297
  end
298
+
299
+ def use_gobject_introspection?
300
+ use_gobject_introspection.nil? ? true : use_gobject_introspection
301
+ end
186
302
  end
187
303
 
188
304
  class NativeConfiguration < Struct.new(:build,
@@ -93,6 +93,10 @@ module GNOME2
93
93
  @package.external_packages = packages
94
94
  end
95
95
 
96
+ def windows_binary_build_task
97
+ @windows_binary_build_task ||= WindowsBinaryBuildTask.new(@package)
98
+ end
99
+
96
100
  private
97
101
  def initialize_variables
98
102
  @summary = ""
@@ -133,7 +137,7 @@ module GNOME2
133
137
  "{sample,test}/**/*"]
134
138
  files.existing!
135
139
  s.files = files
136
- s.required_ruby_version = @required_ruby_version || ">= 1.9.3"
140
+ s.required_ruby_version = @required_ruby_version || ">= 2.1.0"
137
141
  s.post_install_message = @post_install_message
138
142
  @dependency_configuration.apply(s)
139
143
  end
@@ -161,6 +165,7 @@ module GNOME2
161
165
  define_windows_extension_task
162
166
  define_windows_download_task
163
167
  define_windows_build_task
168
+ define_windows_version_update_task
164
169
  end
165
170
 
166
171
  def so_base_name
@@ -214,11 +219,66 @@ module GNOME2
214
219
  end
215
220
 
216
221
  def define_windows_download_task
217
- GNOME2WindowsBinaryDownloadTask.new(@package)
222
+ task = WindowsBinaryDownloadTask.new(@package)
223
+ task.define
218
224
  end
219
225
 
220
226
  def define_windows_build_task
221
- GNOME2WindowsBinaryBuildTask.new(@package)
227
+ windows_binary_build_task.define
228
+ end
229
+
230
+ def define_windows_version_update_task
231
+ namespace :windows do
232
+ namespace :version do
233
+ task_names = []
234
+ namespace :update do
235
+ @package.external_packages.each do |package|
236
+ task_names << package.name
237
+ task package.name do
238
+ latest_version = package.latest_version || package.version
239
+ if package.version != latest_version
240
+ update_package_version(package, latest_version)
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ full_task_names = task_names.collect do |name|
247
+ "windows:version:update:#{name}"
248
+ end
249
+ desc "Update Windows package versions"
250
+ task :update => full_task_names
251
+ end
252
+ end
253
+ end
254
+
255
+ def update_package_version(package, latest_version)
256
+ rakefile_path = ::Rake.application.rakefile
257
+ rakefile_content = File.read(rakefile_path)
258
+ updated_rakefile_content = ""
259
+ in_package = false
260
+ escaped_name = Regexp.escape(package.name)
261
+ escaped_version = Regexp.escape(package.version)
262
+ rakefile_content.each_line do |line|
263
+ case line
264
+ when /:name => "#{escaped_name}",/
265
+ in_package = true
266
+ updated_rakefile_content << line
267
+ when /:version => "#{escaped_version}",/
268
+ if in_package
269
+ updated_rakefile_content << line.gsub(/#{escaped_version}/,
270
+ latest_version)
271
+ in_package = false
272
+ else
273
+ updated_rakefile_content << line
274
+ end
275
+ else
276
+ updated_rakefile_content << line
277
+ end
278
+ end
279
+ File.open(rakefile_path, "w") do |rakefile|
280
+ rakefile.write(updated_rakefile_content)
281
+ end
222
282
  end
223
283
 
224
284
  def define_package_tasks
@@ -5,340 +5,346 @@
5
5
  require "open-uri"
6
6
  require "pathname"
7
7
 
8
- class GNOME2WindowsBinaryBuildTask
9
- include Rake::DSL
10
-
11
- def initialize(package)
12
- @package = package
13
- define
14
- end
15
-
16
- private
17
- def define
18
- namespace :windows do
19
- namespace :builder do
20
- task :before
21
- define_build_tasks
22
- build_tasks = build_packages.collect do |package|
23
- "windows:builder:build:#{package.name}"
24
- end
25
- task :build => build_tasks
26
- task :after
27
- end
28
- desc "Build Windows binaries"
29
- task :build => ["windows:builder:before",
30
- "windows:builder:build",
31
- "windows:builder:after"]
32
- end
33
- end
34
-
35
- def define_build_tasks
36
- namespace :build do
37
- prepare_task_names = []
38
- namespace :prepare do
39
- prepare_task_names << "pkg_config"
40
- task :pkg_config do
41
- depended_packages = @package.windows.build_dependencies
42
- use_packages = [@package.name] + depended_packages
43
- pkg_config_path = use_packages.collect do |package|
44
- "../#{package}/#{@package.windows.relative_binary_dir}/lib/pkgconfig"
45
- end
46
- ENV["PKG_CONFIG_PATH"] = pkg_config_path.collect do |path|
47
- File.expand_path(path)
48
- end.join(":")
49
- ENV["PKG_CONFIG_LIBDIR"] = rcairo_windows_pkgconfig_path
50
- end
51
-
52
- prepare_task_names << "pkg_config_for_build"
53
- task :pkg_config_for_build do
54
- # XXX: Is it needless?
55
- # ENV["PKG_CONFIG_FOR_BUILD"] = "env - pkg-config"
56
- end
57
- end
58
-
59
- full_prepare_task_names = prepare_task_names.collect do |name|
60
- "windows:builder:build:prepare:#{name}"
61
- end
62
- task :prepare => full_prepare_task_names
63
-
64
- build_packages.each do |package|
65
- namespace package.name do
66
- task :before
67
- download_task = "source:downloader:download:#{package.name}"
68
- built_file = package.windows.built_file
69
- if built_file
70
- built_file = dist_dir + built_file
71
- file built_file.to_s do
72
- Rake::Task["windows:builder:build:prepare"].invoke
73
- Rake::Task[download_task].invoke
74
- build_package_task_body(package)
75
- end
76
- task :build => built_file.to_s
77
- else
78
- task :build => [:prepare, download_task] do
79
- build_package_task_body(package)
80
- end
81
- end
82
- task :after
83
- end
84
-
85
- prefix = "windows:builder:build:#{package.name}"
86
- desc "Build #{package.label} and install it into #{dist_dir}."
87
- task package.name => [
88
- "#{prefix}:before",
89
- "#{prefix}:build",
90
- "#{prefix}:after",
91
- ]
92
- end
93
- end
94
- end
95
-
96
- def build_package_task_body(package)
97
- package_tmp_dir = @package.tmp_dir + "windows" + package.name
98
- rm_rf(package_tmp_dir)
99
- mkdir_p(package_tmp_dir)
100
-
101
- tar_full_path = @package.download_dir + package.archive_base_name
102
- Dir.chdir(package_tmp_dir.to_s) do
103
- sh("tar", "xf", tar_full_path.to_s)
104
- end
105
-
106
- package_dir_path =
107
- package_tmp_dir + package.base_name + package.base_dir_in_package
108
- Dir.chdir(package_dir_path.to_s) do
109
- package.windows.patches.each do |patch|
110
- sh("patch -p1 < #{@package.patches_dir}/#{patch}")
111
- end
112
- if File.exist?("configure")
113
- configure(package)
114
- else
115
- cmake(package)
116
- end
117
- common_make_args = []
118
- common_make_args << "MAKE=make"
119
- common_make_args << "GLIB_COMPILE_SCHEMAS=glib-compile-schemas"
120
- if package.windows.use_cc_environment_variable?
121
- common_make_args << cc_env(package)
122
- end
123
- add_gobject_introspection_make_args(package, common_make_args)
124
- build_make_args = common_make_args.dup
125
- install_make_args = common_make_args.dup
126
- if package.windows.build_concurrently?
127
- make_n_jobs = ENV["MAKE_N_JOBS"]
128
- build_make_args << "-j#{make_n_jobs}" if make_n_jobs
129
- end
130
- ENV["GREP_OPTIONS"] = "--text"
131
- # ENV["GI_SCANNER_DEBUG"] = "save-temps"
132
- # build_make_args << "--debug"
133
- # build_make_args << "V=1"
134
- sh("nice", "make", *build_make_args) or exit(false)
135
- sh("make", "install", *install_make_args) or exit(false)
136
-
137
- package_license_dir = license_dir + package.name
138
- mkdir_p(package_license_dir)
139
- package_license_files = ["AUTHORS", "COPYING", "COPYING.LIB"]
140
- package_license_files = package_license_files.reject do |file|
141
- not File.exist?(file)
142
- end
143
- cp(package_license_files, package_license_dir)
144
- bundled_packages = package.bundled_packages
145
- bundled_packages.each do |bundled_package|
146
- bundled_package_license_dir = license_dir + bundled_package[:name]
147
- mkdir_p(bundled_package_license_dir)
148
- license_files = bundled_package[:license_files].collect do |file|
149
- File.join(bundled_package[:path], file)
150
- end
151
- cp(license_files, bundled_package_license_dir)
152
- end
153
- end
154
- end
155
-
156
- def configure(package)
157
- sh("./autogen.sh") if package.windows.need_autogen?
158
- sh("autoreconf", "--install", "--force") if package.windows.need_autoreconf?
159
- sh("./configure",
160
- cc_env(package),
161
- dlltool_env,
162
- "CPPFLAGS=#{cppflags(package)}",
163
- "LDFLAGS=#{ldflags(package)}",
164
- "--prefix=#{dist_dir}",
165
- "--host=#{@package.windows.build_host}",
166
- *package.windows.configure_args) or exit(false)
167
- end
168
-
169
- def cmake(package)
170
- sh("cmake",
171
- ".",
172
- "-DCMAKE_INSTALL_PREFIX=#{dist_dir}",
173
- "-DCMAKE_SYSTEM_NAME=Windows",
174
- "-DCMAKE_SYSTEM_PROCESSOR=#{@package.windows.build_architecture}",
175
- "-DCMAKE_C_COMPILER=#{cc(package)}",
176
- "-DCMAKE_CXX_COMPILER=#{cxx(package)}",
177
- *package.windows.cmake_args) or exit(false)
178
- end
179
-
180
- def cc_env(package)
181
- "CC=#{cc(package)}"
182
- end
183
-
184
- def dlltool_env
185
- "DLLTOOL=#{dlltool}"
186
- end
187
-
188
- def build_packages
189
- packages = @package.external_packages.select do |package|
190
- package.windows.build?
191
- end
192
- # For backward compatibility
193
- packages + @package.windows.build_packages
194
- end
195
-
196
- def dist_dir
197
- @package.windows.absolute_binary_dir
198
- end
199
-
200
- def license_dir
201
- dist_dir + "share" + "license"
202
- end
203
-
204
- def glib2_binary_base_dir
205
- @package.glib2_root_dir + "vendor" + "local"
206
- end
207
-
208
- def glib2_include_path
209
- "#{glib2_binary_base_dir}/include"
210
- end
211
-
212
- def glib2_lib_path
213
- "#{glib2_binary_base_dir}/lib"
214
- end
215
-
216
- def rcairo_windows_dir
217
- suffix = @package.windows.build_architecture_suffix
218
- @package.project_root_dir.parent + "rcairo.#{suffix}"
219
- end
220
-
221
- def rcairo_windows_binary_base_dir
222
- rcairo_windows_dir + "vendor" + "local"
223
- end
224
-
225
- def rcairo_windows_pkgconfig_path
226
- "#{rcairo_windows_binary_base_dir}/lib/pkgconfig"
227
- end
228
-
229
- def rcairo_windows_include_path
230
- "#{rcairo_windows_binary_base_dir}/include"
231
- end
232
-
233
- def rcairo_windows_lib_path
234
- "#{rcairo_windows_binary_base_dir}/lib"
235
- end
236
-
237
- def cc(package)
238
- cc_command_line = [
239
- "#{@package.windows.build_host}-gcc",
240
- *package.windows.cc_args,
241
- ]
242
- cc_command_line.compact.join(" ")
243
- end
244
-
245
- def cxx(package)
246
- cxx_command_line = [
247
- "#{@package.windows.build_host}-g++",
248
- ]
249
- cxx_command_line.compact.join(" ")
250
- end
251
-
252
- def dlltool
253
- "#{@package.windows.build_host}-dlltool"
254
- end
255
-
256
- def cppflags(package)
257
- include_paths = package.windows.include_paths
258
- if @package.windows.build_dependencies.include?("glib2")
259
- include_paths += [glib2_include_path]
260
- end
261
- include_paths += [
262
- rcairo_windows_include_path,
263
- dist_dir + 'include',
264
- ]
265
- cppflags = include_paths.collect do |path|
266
- "-I#{path}"
267
- end
268
- cppflags.join(" ")
269
- end
270
-
271
- def ldflags(package)
272
- library_paths = package.windows.library_paths
273
- if @package.windows.build_dependencies.include?("glib2")
274
- library_paths += [glib2_lib_path]
275
- end
276
- library_paths += [
277
- rcairo_windows_lib_path,
278
- dist_dir + 'lib',
279
- ]
280
- ldflags = library_paths.collect do |path|
281
- "-L#{path}"
282
- end
283
- ldflags.join(" ")
284
- end
285
-
286
- def cmake_root_paths
287
- paths = [
288
- "/usr/#{@package.windows.build_host}",
289
- rcairo_windows_binary_base_dir.to_path,
290
- ]
291
- @package.windows.build_dependencies.each do |package|
292
- paths << "#{@package.project_root_dir}/#{package}/vendor/local"
293
- end
294
- paths
295
- end
296
-
297
- def add_gobject_introspection_make_args(package, common_make_args)
298
- unless @package.windows.build_dependencies.include?("gobject-introspection")
299
- return
300
- end
301
-
302
- g_ir_scanner = "#{@package.project_root_dir}/gobject-introspection/"
303
- g_ir_scanner << "#{@package.native.relative_binary_dir}/bin/g-ir-scanner"
304
- introspection_scanner = "INTROSPECTION_SCANNER=#{g_ir_scanner}"
305
- common_make_args << introspection_scanner
306
-
307
-
308
- dependencies = [
309
- "gobject-introspection",
310
- @package.name,
311
- ]
312
- dependencies += @package.windows.gobject_introspection_dependencies
313
-
314
- compute_base_dir = lambda do |dependent_package|
315
- "#{@package.project_root_dir}/#{dependent_package}/vendor/local"
316
- end
317
-
318
- gi_base_dir = compute_base_dir.call("gobject-introspection")
319
- introspection_compiler = "INTROSPECTION_COMPILER="
320
- introspection_compiler << "#{gi_base_dir}/bin/g-ir-compiler.exe"
321
- introspection_compiler_args = ""
322
- dependencies.each do |dependent_package|
323
- gir_dir = "#{compute_base_dir.call(dependent_package)}/share/gir-1.0"
324
- introspection_compiler_args << " --includedir=#{gir_dir}"
325
- end
326
- if package.windows.gobject_introspection_compiler_split_args?
327
- common_make_args << introspection_compiler
328
- common_make_args <<
329
- "INTROSPECTION_COMPILER_ARGS=#{introspection_compiler_args}"
330
- common_make_args <<
331
- "INTROSPECTION_COMPILER_OPTS=#{introspection_compiler_args}"
332
- else
333
- introspection_compiler << " #{introspection_compiler_args}"
334
- common_make_args << introspection_compiler
335
- end
336
-
337
- common_make_args << dlltool_env
338
-
339
- data_dirs = dependencies.collect do |dependent_package|
340
- "#{compute_base_dir.call(dependent_package)}/share"
341
- end
342
- common_make_args << "XDG_DATA_DIRS=#{data_dirs.join(File::PATH_SEPARATOR)}"
343
- end
344
- end
8
+ module GNOME2
9
+ module Rake
10
+ class WindowsBinaryBuildTask
11
+ include ::Rake::DSL
12
+
13
+ def initialize(package)
14
+ @package = package
15
+ end
16
+
17
+ def define
18
+ namespace :windows do
19
+ namespace :builder do
20
+ task :before
21
+ define_build_tasks
22
+ build_tasks = build_packages.collect do |package|
23
+ "windows:builder:build:#{package.name}"
24
+ end
25
+ task :build => build_tasks
26
+ task :after
27
+ end
28
+ desc "Build Windows binaries"
29
+ task :build => ["windows:builder:before",
30
+ "windows:builder:build",
31
+ "windows:builder:after"]
32
+ end
33
+ end
34
+
35
+ def rcairo_windows_binary_base_dir
36
+ rcairo_windows_dir + "vendor" + "local"
37
+ end
38
+
39
+ private
40
+ def define_build_tasks
41
+ namespace :build do
42
+ prepare_task_names = []
43
+ namespace :prepare do
44
+ prepare_task_names << "pkg_config"
45
+ task :pkg_config do
46
+ depended_packages = @package.windows.build_dependencies
47
+ use_packages = [@package.name] + depended_packages
48
+ pkg_config_path = use_packages.collect do |package|
49
+ "../#{package}/#{@package.windows.relative_binary_dir}/lib/pkgconfig"
50
+ end
51
+ ENV["PKG_CONFIG_PATH"] = pkg_config_path.collect do |path|
52
+ File.expand_path(path)
53
+ end.join(":")
54
+ ENV["PKG_CONFIG_LIBDIR"] = rcairo_windows_pkgconfig_path
55
+ end
56
+
57
+ prepare_task_names << "pkg_config_for_build"
58
+ task :pkg_config_for_build do
59
+ # XXX: Is it needless?
60
+ # ENV["PKG_CONFIG_FOR_BUILD"] = "env - pkg-config"
61
+ end
62
+ end
63
+
64
+ full_prepare_task_names = prepare_task_names.collect do |name|
65
+ "windows:builder:build:prepare:#{name}"
66
+ end
67
+ task :prepare => full_prepare_task_names
68
+
69
+ build_packages.each do |package|
70
+ namespace package.name do
71
+ task :before
72
+ download_task = "source:downloader:download:#{package.name}"
73
+ built_file = package.windows.built_file
74
+ if built_file
75
+ built_file = dist_dir + built_file
76
+ file built_file.to_s do
77
+ ::Rake::Task["windows:builder:build:prepare"].invoke
78
+ ::Rake::Task[download_task].invoke
79
+ build_package_task_body(package)
80
+ end
81
+ task :build => built_file.to_s
82
+ else
83
+ task :build => [:prepare, download_task] do
84
+ build_package_task_body(package)
85
+ end
86
+ end
87
+ task :after
88
+ end
89
+
90
+ prefix = "windows:builder:build:#{package.name}"
91
+ desc "Build #{package.label} and install it into #{dist_dir}."
92
+ task package.name => [
93
+ "#{prefix}:before",
94
+ "#{prefix}:build",
95
+ "#{prefix}:after",
96
+ ]
97
+ end
98
+ end
99
+ end
100
+
101
+ def build_package_task_body(package)
102
+ package_tmp_dir = @package.tmp_dir + "windows" + package.name
103
+ rm_rf(package_tmp_dir)
104
+ mkdir_p(package_tmp_dir)
105
+
106
+ tar_full_path = @package.download_dir + package.archive_base_name
107
+ Dir.chdir(package_tmp_dir.to_s) do
108
+ sh("tar", "xf", tar_full_path.to_s)
109
+ end
110
+
111
+ package_dir_path =
112
+ package_tmp_dir + package.base_name + package.base_dir_in_package
113
+ Dir.chdir(package_dir_path.to_s) do
114
+ package.windows.patches.each do |patch|
115
+ sh("patch -p1 < #{@package.patches_dir}/#{patch}")
116
+ end
117
+ if File.exist?("configure")
118
+ configure(package)
119
+ else
120
+ cmake(package)
121
+ end
122
+ common_make_args = []
123
+ common_make_args << "MAKE=make"
124
+ common_make_args << "GLIB_COMPILE_SCHEMAS=glib-compile-schemas"
125
+ if package.windows.use_cc_environment_variable?
126
+ common_make_args << cc_env(package)
127
+ end
128
+ add_gobject_introspection_make_args(package, common_make_args)
129
+ build_make_args = common_make_args.dup
130
+ install_make_args = common_make_args.dup
131
+ if package.windows.build_concurrently?
132
+ make_n_jobs = ENV["MAKE_N_JOBS"]
133
+ build_make_args << "-j#{make_n_jobs}" if make_n_jobs
134
+ end
135
+ ENV["GREP_OPTIONS"] = "--text"
136
+ # ENV["GI_SCANNER_DEBUG"] = "save-temps"
137
+ # build_make_args << "--debug"
138
+ # build_make_args << "V=1"
139
+ sh("nice", "make", *build_make_args) or exit(false)
140
+ sh("make", "install", *install_make_args) or exit(false)
141
+
142
+ package_license_dir = license_dir + package.name
143
+ mkdir_p(package_license_dir)
144
+ package_license_files = ["AUTHORS", "COPYING", "COPYING.LIB"]
145
+ package_license_files = package_license_files.reject do |file|
146
+ not File.exist?(file)
147
+ end
148
+ cp(package_license_files, package_license_dir)
149
+ bundled_packages = package.bundled_packages
150
+ bundled_packages.each do |bundled_package|
151
+ bundled_package_license_dir = license_dir + bundled_package[:name]
152
+ mkdir_p(bundled_package_license_dir)
153
+ license_files = bundled_package[:license_files].collect do |file|
154
+ File.join(bundled_package[:path], file)
155
+ end
156
+ cp(license_files, bundled_package_license_dir)
157
+ end
158
+ end
159
+ end
160
+
161
+ def configure(package)
162
+ sh("./autogen.sh") if package.windows.need_autogen?
163
+ sh("autoreconf", "--install", "--force") if package.windows.need_autoreconf?
164
+ sh("./configure",
165
+ cc_env(package),
166
+ dlltool_env,
167
+ "CPPFLAGS=#{cppflags(package)}",
168
+ "LDFLAGS=#{ldflags(package)}",
169
+ "--prefix=#{dist_dir}",
170
+ "--host=#{@package.windows.build_host}",
171
+ *package.windows.configure_args) or exit(false)
172
+ end
173
+
174
+ def cmake(package)
175
+ sh("cmake",
176
+ ".",
177
+ "-DCMAKE_INSTALL_PREFIX=#{dist_dir}",
178
+ "-DCMAKE_SYSTEM_NAME=Windows",
179
+ "-DCMAKE_SYSTEM_PROCESSOR=#{@package.windows.build_architecture}",
180
+ "-DCMAKE_C_COMPILER=#{cc(package)}",
181
+ "-DCMAKE_CXX_COMPILER=#{cxx(package)}",
182
+ *package.windows.cmake_args) or exit(false)
183
+ end
184
+
185
+ def cc_env(package)
186
+ "CC=#{cc(package)}"
187
+ end
188
+
189
+ def dlltool_env
190
+ "DLLTOOL=#{dlltool}"
191
+ end
192
+
193
+ def build_packages
194
+ packages = @package.external_packages.select do |package|
195
+ package.windows.build?
196
+ end
197
+ # For backward compatibility
198
+ packages + @package.windows.build_packages
199
+ end
200
+
201
+ def dist_dir
202
+ @package.windows.absolute_binary_dir
203
+ end
204
+
205
+ def license_dir
206
+ dist_dir + "share" + "license"
207
+ end
208
+
209
+ def glib2_binary_base_dir
210
+ @package.glib2_root_dir + "vendor" + "local"
211
+ end
212
+
213
+ def glib2_include_path
214
+ "#{glib2_binary_base_dir}/include"
215
+ end
216
+
217
+ def glib2_lib_path
218
+ "#{glib2_binary_base_dir}/lib"
219
+ end
220
+
221
+ def rcairo_windows_dir
222
+ suffix = @package.windows.build_architecture_suffix
223
+ @package.project_root_dir.parent + "rcairo.#{suffix}"
224
+ end
225
+
226
+ def rcairo_windows_pkgconfig_path
227
+ "#{rcairo_windows_binary_base_dir}/lib/pkgconfig"
228
+ end
229
+
230
+ def rcairo_windows_include_path
231
+ "#{rcairo_windows_binary_base_dir}/include"
232
+ end
233
+
234
+ def rcairo_windows_lib_path
235
+ "#{rcairo_windows_binary_base_dir}/lib"
236
+ end
237
+
238
+ def cc(package)
239
+ cc_command_line = [
240
+ "#{@package.windows.build_host}-gcc",
241
+ *package.windows.cc_args,
242
+ ]
243
+ cc_command_line.compact.join(" ")
244
+ end
245
+
246
+ def cxx(package)
247
+ cxx_command_line = [
248
+ "#{@package.windows.build_host}-g++",
249
+ ]
250
+ cxx_command_line.compact.join(" ")
251
+ end
252
+
253
+ def dlltool
254
+ "#{@package.windows.build_host}-dlltool"
255
+ end
256
+
257
+ def cppflags(package)
258
+ include_paths = package.windows.include_paths
259
+ if @package.windows.build_dependencies.include?("glib2")
260
+ include_paths += [glib2_include_path]
261
+ end
262
+ include_paths += [
263
+ rcairo_windows_include_path,
264
+ dist_dir + 'include',
265
+ ]
266
+ cppflags = include_paths.collect do |path|
267
+ "-I#{path}"
268
+ end
269
+ cppflags.join(" ")
270
+ end
271
+
272
+ def ldflags(package)
273
+ library_paths = package.windows.library_paths
274
+ if @package.windows.build_dependencies.include?("glib2")
275
+ library_paths += [glib2_lib_path]
276
+ end
277
+ library_paths += [
278
+ rcairo_windows_lib_path,
279
+ dist_dir + 'lib',
280
+ ]
281
+ ldflags = library_paths.collect do |path|
282
+ "-L#{path}"
283
+ end
284
+ ldflags.join(" ")
285
+ end
286
+
287
+ def cmake_root_paths
288
+ paths = [
289
+ "/usr/#{@package.windows.build_host}",
290
+ rcairo_windows_binary_base_dir.to_path,
291
+ ]
292
+ @package.windows.build_dependencies.each do |package|
293
+ paths << "#{@package.project_root_dir}/#{package}/vendor/local"
294
+ end
295
+ paths
296
+ end
297
+
298
+ def add_gobject_introspection_make_args(package, common_make_args)
299
+ return unless use_gobject_introspection?(package)
300
+
301
+ g_ir_scanner = "#{@package.project_root_dir}/gobject-introspection/"
302
+ g_ir_scanner << "#{@package.native.relative_binary_dir}/bin/g-ir-scanner"
303
+ introspection_scanner = "INTROSPECTION_SCANNER=#{g_ir_scanner}"
304
+ common_make_args << introspection_scanner
305
+
306
+
307
+ dependencies = [
308
+ "gobject-introspection",
309
+ @package.name,
310
+ ]
311
+ dependencies += @package.windows.gobject_introspection_dependencies
312
+
313
+ compute_base_dir = lambda do |dependent_package|
314
+ "#{@package.project_root_dir}/#{dependent_package}/vendor/local"
315
+ end
316
+
317
+ gi_base_dir = compute_base_dir.call("gobject-introspection")
318
+ introspection_compiler = "INTROSPECTION_COMPILER="
319
+ introspection_compiler << "#{gi_base_dir}/bin/g-ir-compiler.exe"
320
+ introspection_compiler_args = ""
321
+ dependencies.each do |dependent_package|
322
+ gir_dir = "#{compute_base_dir.call(dependent_package)}/share/gir-1.0"
323
+ introspection_compiler_args << " --includedir=#{gir_dir}"
324
+ end
325
+ if package.windows.gobject_introspection_compiler_split_args?
326
+ common_make_args << introspection_compiler
327
+ common_make_args <<
328
+ "INTROSPECTION_COMPILER_ARGS=#{introspection_compiler_args}"
329
+ common_make_args <<
330
+ "INTROSPECTION_COMPILER_OPTS=#{introspection_compiler_args}"
331
+ else
332
+ introspection_compiler << " #{introspection_compiler_args}"
333
+ common_make_args << introspection_compiler
334
+ end
335
+
336
+ common_make_args << dlltool_env
337
+
338
+ data_dirs = dependencies.collect do |dependent_package|
339
+ "#{compute_base_dir.call(dependent_package)}/share"
340
+ end
341
+ common_make_args << "XDG_DATA_DIRS=#{data_dirs.join(File::PATH_SEPARATOR)}"
342
+ end
343
+
344
+ def use_gobject_introspection?(package)
345
+ return false unless package.windows.use_gobject_introspection?
346
+ @package.windows.build_dependencies.include?("gobject-introspection")
347
+ end
348
+ end
349
+ end
350
+ end