Created
August 12, 2020 08:48
-
-
Save sailfish009/8470dced2621ae8633f8d5ba30563728 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://forums.gentoo.org/viewtopic-t-1108872-start-0.html | |
# Python3+ instead of python2.7 | |
# by Pavel Kabikov aka bitMan | |
--- chromium-81.0.4044.26/build/toolchain/gcc_solink_wrapper.py 2020-02-20 03:32:08.000000000 +0300 | |
+++ /tmp/gcc_solink_wrapper.py 2020-02-27 00:45:25.526917216 +0300 | |
@@ -11,6 +11,7 @@ | |
""" | |
import argparse | |
+import io | |
import os | |
import subprocess | |
import sys | |
@@ -18,12 +19,19 @@ | |
import wrapper_utils | |
+def read_as_utf8(fileno): | |
+ fp = io.open(fileno, mode="r", encoding="utf-8", closefd=False) | |
+ content = fp.read() | |
+ fp.close() | |
+ return content | |
+ | |
def CollectSONAME(args): | |
"""Replaces: readelf -d $sofile | grep SONAME""" | |
toc = '' | |
readelf = subprocess.Popen(wrapper_utils.CommandToRun( | |
[args.readelf, '-d', args.sofile]), stdout=subprocess.PIPE, bufsize=-1) | |
- for line in readelf.stdout: | |
+ # print(readelf.stdout) | |
+ for line in read_as_utf8(readelf.stdout.fileno()): | |
if 'SONAME' in line: | |
toc += line | |
return readelf.wait(), toc | |
@@ -35,7 +43,7 @@ | |
nm = subprocess.Popen(wrapper_utils.CommandToRun([ | |
args.nm, '--format=posix', '-g', '-D', args.sofile]), | |
stdout=subprocess.PIPE, bufsize=-1) | |
- for line in nm.stdout: | |
+ for line in read_as_utf8(nm.stdout.fileno()): | |
toc += ' '.join(line.split(' ', 2)[:2]) + '\n' | |
return nm.wait(), toc |
Author
sailfish009
commented
Aug 12, 2020
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Writes C++ header/cc source files for embedding resources into C++."""
import datetime
import os
import sys
def WriteSource(base_name,
dir_from_src,
output_dir,
global_string_map):
"""Writes C++ header/cc source files for the given map of string variables.
Args:
base_name: The basename of the file, without the extension.
dir_from_src: Path from src to the directory that will contain the file,
using forward slashes.
output_dir: Directory to output the sources to.
global_string_map: Map of variable names to their string values. These
variables will be available as globals.
"""
copyright_header_template = (
'// Copyright 2018 The Chromium Authors. All rights reserved.\n'
'// Use of this source code is governed by a BSD-style license '
'that can be\n'
'// found in the LICENSE file.\n\n'
'// This file was generated by running:\n'
'// %s')
copyright_header = copyright_header_template % (' '.join(sys.argv))
# Write header file.
externs = []
for name in global_string_map.keys():
externs += ['extern const char %s[];' % name]
temp = '_'.join(dir_from_src.split('/') + [base_name])
define = temp.upper() + '_H_'
header = '\n'.join([
copyright_header,
'',
'#ifndef ' + define,
'#define ' + define,
'',
'\n'.join(externs),
'',
'#endif // ' + define])
header += '\n'
with open(os.path.join(output_dir, base_name + '.h'), 'w') as f:
f.write(header)
# Write cc file.
def EscapeLine(line):
return line.replace('\\', '\\\\').replace('"', '\\"')
definitions = []
for name, contents in global_string_map.items():
lines = []
if '\n' not in contents:
lines = [' "%s"' % EscapeLine(contents)]
else:
for line in contents.split('\n'):
lines += [' "%s\\n"' % EscapeLine(line)]
definitions += ['const char %s[] =\n%s;' % (name, '\n'.join(lines))]
cc = '\n'.join([
copyright_header,
'',
'#include "%s"' % (dir_from_src + '/' + base_name + '.h'),
'',
'\n'.join(definitions)])
cc += '\n'
with open(os.path.join(output_dir, base_name + '.cc'), 'w') as f:
f.write(cc)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment