From 4ccd9782386b646b99007c1472ab28a61b52bb5d Mon Sep 17 00:00:00 2001
From: Jussi Pakkanen <jpakkane@gmail.com>
Date: Mon, 25 Mar 2019 20:33:55 +0200
Subject: [PATCH 2/2] Revert "gnome.compile_resources: Add ld binary method"
This reverts commit 59791fc56966901038aaaac23942bc8ac6e11494, reversing
changes made to e26b5a119e0b3f76cc93f65ecf4251dc6d52ecfe.
---
mesonbuild/modules/__init__.py | 4 -
mesonbuild/modules/gnome.py | 158 +++------------------------------
2 files changed, 14 insertions(+), 148 deletions(-)
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py
index 2df4d7c3..6b6aa8ba 100644
--- a/mesonbuild/modules/__init__.py
+++ b/mesonbuild/modules/__init__.py
@@ -58,10 +58,6 @@ class GResourceHeaderTarget(build.CustomTarget):
def __init__(self, name, subdir, subproject, kwargs):
super().__init__(name, subdir, subproject, kwargs)
-class GResourceObjectTarget(build.CustomTarget):
- def __init__(self, name, subdir, subproject, kwargs):
- super().__init__(name, subdir, subproject, kwargs)
-
class GirTarget(build.CustomTarget):
def __init__(self, name, subdir, subproject, kwargs):
super().__init__(name, subdir, subproject, kwargs)
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index 8833a214..2d169560 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -16,8 +16,6 @@
functionality such as gobject-introspection, gresources and gtk-doc'''
import os
-import re
-import sys
import copy
import shlex
import subprocess
@@ -27,7 +25,7 @@ from .. import mlog
from .. import mesonlib
from .. import compilers
from .. import interpreter
-from . import GResourceTarget, GResourceHeaderTarget, GResourceObjectTarget, GirTarget, TypelibTarget, VapiTarget
+from . import GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget
from . import get_include_args
from . import ExtensionModule
from . import ModuleReturnValue
@@ -44,8 +42,6 @@ from ..interpreterbase import noKwargs, permittedKwargs, FeatureNew, FeatureNewK
# https://bugzilla.gnome.org/show_bug.cgi?id=774368
gresource_dep_needed_version = '>= 2.51.1'
-gresource_ld_binary_needed_version = '>= 2.60'
-
native_glib_version = None
girwarning_printed = False
gdbuswarning_printed = False
@@ -170,10 +166,7 @@ class GnomeModule(ExtensionModule):
cmd += ['--sourcedir', source_dir]
if 'c_name' in kwargs:
- c_name = kwargs.pop('c_name')
- cmd += ['--c-name', c_name]
- else:
- c_name = None
+ cmd += ['--c-name', kwargs.pop('c_name')]
export = kwargs.pop('export', False)
if not export:
cmd += ['--internal']
@@ -182,23 +175,13 @@ class GnomeModule(ExtensionModule):
cmd += mesonlib.stringlistify(kwargs.pop('extra_args', []))
- gresource_ld_binary = False
- if mesonlib.is_linux() and mesonlib.version_compare(glib_version, gresource_ld_binary_needed_version) and not state.environment.is_cross_build():
- ld_obj = self.interpreter.find_program_impl('ld', required=False)
- if ld_obj.found():
- gresource_ld_binary = True
-
gresource = kwargs.pop('gresource_bundle', False)
-
if gresource:
- g_output = args[0] + '.gresource'
- g_name = args[0] + '_gresource'
- elif gresource_ld_binary:
- g_output = args[0] + '_ld_binary.gresource'
- g_name = args[0] + '_ld_binary_gresource'
-
- output = args[0] + '.c'
- name = args[0] + '_c'
+ output = args[0] + '.gresource'
+ name = args[0] + '_gresource'
+ else:
+ output = args[0] + '.c'
+ name = args[0] + '_c'
if kwargs.get('install', False) and not gresource:
raise MesonException('The install kwarg only applies to gresource bundles, see install_header')
@@ -212,42 +195,19 @@ class GnomeModule(ExtensionModule):
kwargs['input'] = args[1]
kwargs['output'] = output
kwargs['depends'] = depends
- if gresource or gresource_ld_binary:
- g_kwargs = copy.deepcopy(kwargs)
- g_kwargs['input'] = args[1]
- g_kwargs['output'] = g_output
- g_kwargs['depends'] = depends
if not mesonlib.version_compare(glib_version, gresource_dep_needed_version):
# This will eventually go out of sync if dependencies are added
kwargs['depend_files'] = depend_files
- if gresource_ld_binary:
- kwargs['command'] = copy.copy(cmd) + ['--external-data']
- else:
- kwargs['command'] = cmd
- if gresource or gresource_ld_binary:
- # This will eventually go out of sync if dependencies are added
- g_kwargs['depend_files'] = depend_files
- g_kwargs['command'] = cmd
+ kwargs['command'] = cmd
else:
depfile = kwargs['output'] + '.d'
- if gresource_ld_binary:
- depfile2 = kwargs['output'] + '.2.d'
- kwargs['depfile'] = depfile2
- kwargs['command'] = copy.copy(cmd) + ['--external-data', '--dependency-file', '@DEPFILE@']
- else:
- kwargs['depfile'] = depfile
- kwargs['command'] = copy.copy(cmd) + ['--dependency-file', '@DEPFILE@']
- if gresource or gresource_ld_binary:
- g_kwargs['depfile'] = depfile
- g_kwargs['command'] = copy.copy(cmd) + ['--dependency-file', '@DEPFILE@']
-
- if gresource or gresource_ld_binary:
- target_g = GResourceTarget(g_name, state.subdir, state.subproject, g_kwargs)
- if gresource: # Only one target for .gresource files
- return ModuleReturnValue(target_g, [target_g])
-
+ kwargs['depfile'] = depfile
+ kwargs['command'] = copy.copy(cmd) + ['--dependency-file', '@DEPFILE@']
target_c = GResourceTarget(name, state.subdir, state.subproject, kwargs)
+ if gresource: # Only one target for .gresource files
+ return ModuleReturnValue(target_c, [target_c])
+
h_kwargs = {
'command': cmd,
'input': args[1],
@@ -262,99 +222,9 @@ class GnomeModule(ExtensionModule):
h_kwargs['install_dir'] = kwargs.get('install_dir',
state.environment.coredata.get_builtin_option('includedir'))
target_h = GResourceHeaderTarget(args[0] + '_h', state.subdir, state.subproject, h_kwargs)
-
- if gresource_ld_binary:
- return self._create_gresource_ld_binary_targets(args, state, ifile, ld_obj, c_name, target_g, g_output, target_c, target_h)
- else:
- rv = [target_c, target_h]
-
+ rv = [target_c, target_h]
return ModuleReturnValue(rv, rv)
- def _create_gresource_ld_binary_targets(self, args, state, ifile, ld_obj, c_name, target_g, g_output, target_c, target_h):
- if c_name is None:
- # Create proper c identifier from filename in the way glib-compile-resources does
- c_name = os.path.basename(ifile).partition('.')[0]
- c_name = c_name.replace('-', '_')
- c_name = re.sub(r'^([^(_a-zA-Z)])+', '', c_name)
- c_name = re.sub(r'([^(_a-zA-Z0-9)])', '', c_name)
-
- c_name_no_underscores = re.sub(r'^_+', '', c_name)
-
- ld = ld_obj.get_command()
- objcopy_object = self.interpreter.find_program_impl('objcopy', required=False)
- if objcopy_object.found():
- objcopy = objcopy_object.get_command()
- else:
- objcopy = None
-
- o_kwargs = {
- 'command': [ld, '-r', '-b', 'binary', '@INPUT@', '-o', '@OUTPUT@'],
- 'input': target_g,
- 'output': args[0] + '1.o'
- }
-
- target_o = GResourceObjectTarget(args[0] + '1_o', state.subdir, state.subproject, o_kwargs)
-
- builddir = os.path.join(state.environment.get_build_dir(), state.subdir)
- linkerscript_name = args[0] + '_map.ld'
- linkerscript_path = os.path.join(builddir, linkerscript_name)
- linkerscript_file = open(linkerscript_path, 'w')
-
- # Create symbol name the way bfd does
- binary_name = os.path.join(state.subdir, g_output)
- encoding = sys.getfilesystemencoding()
- symbol_name = re.sub(rb'([^(_a-zA-Z0-9)])', b'_', binary_name.encode(encoding)).decode(encoding)
-
- linkerscript_string = '''SECTIONS
-{{
- .gresource.{} : ALIGN(8)
- {{
- {}_resource_data = _binary_{}_start;
- }}
- .data :
- {{
- *(.data)
- }}
-}}'''.format(c_name_no_underscores, c_name, symbol_name)
-
- linkerscript_file.write(linkerscript_string)
-
- o2_kwargs = {
- 'command': [ld, '-r', '-T', os.path.join(state.subdir, linkerscript_name), '@INPUT@', '-o', '@OUTPUT@'],
- 'input': target_o,
- 'output': args[0] + '2.o',
- }
- target_o2 = GResourceObjectTarget(args[0] + '2_o', state.subdir, state.subproject, o2_kwargs)
-
- if objcopy is not None:
- objcopy_cmd = [objcopy, '--set-section-flags', '.gresource.' + c_name + '=readonly,alloc,load,data']
- objcopy_cmd += ['-N', '_binary_' + symbol_name + '_start']
- objcopy_cmd += ['-N', '_binary_' + symbol_name + '_end']
- objcopy_cmd += ['-N', '_binary_' + symbol_name + '_size']
- objcopy_cmd += ['@INPUT@', '@OUTPUT@']
-
- o3_kwargs = {
- 'command': objcopy_cmd,
- 'input': target_o2,
- 'output': args[0] + '3.o'
- }
-
- target_o3 = GResourceObjectTarget(args[0] + '3_o', state.subdir, state.subproject, o3_kwargs)
-
- rv1 = [target_c, target_h, target_o3]
- if target_g.get_id() not in self.interpreter.build.targets:
- rv2 = rv1 + [target_g, target_o, target_o2]
- else:
- rv2 = rv1 + [target_o, target_o2]
- else:
- rv1 = [target_c, target_h, target_o2]
- if target_g.get_id() not in self.interpreter.build.targets:
- rv2 = rv1 + [target_g, target_o]
- else:
- rv2 = rv1 + [target_o]
-
- return ModuleReturnValue(rv1, rv2)
-
def _get_gresource_dependencies(self, state, input_file, source_dirs, dependencies):
cmd = ['glib-compile-resources',
--
2.21.0