| 1 |
#!/usr/bin/python3 |
| 2 |
import sys |
| 3 |
import os |
| 4 |
import tarfile |
| 5 |
import tempfile |
| 6 |
|
| 7 |
UPSTREAM_VERSION = sys.argv[2] |
| 8 |
EXCLUDE_LIST = [ |
| 9 |
"libffi", |
| 10 |
"libgomp", |
| 11 |
"libquadmath", |
| 12 |
"libssp", |
| 13 |
"libada", |
| 14 |
"libgfortran", |
| 15 |
"libcilkrts", |
| 16 |
"libgo", |
| 17 |
"libjava", |
| 18 |
"zlib", |
| 19 |
"gcc/testsuite/ada", |
| 20 |
"gcc/testsuite/gfortran", |
| 21 |
"gcc/testsuite/gnat", |
| 22 |
"gcc/testsuite/go.dg", |
| 23 |
"gcc/testsuite/go.go-torture", |
| 24 |
"gcc/testsuite/go.test", |
| 25 |
"gcc/testsuite/objc", |
| 26 |
"gcc/testsuite/obj-c++.dg", |
| 27 |
"gcc/testsuite/objc.dg", |
| 28 |
"gcc/testsuite/objc-obj-c++-shared", |
| 29 |
"gcc/ada/doc", |
| 30 |
] |
| 31 |
GCC_TMP_DIR = None |
| 32 |
|
| 33 |
|
| 34 |
def get_orig_file_name(): |
| 35 |
file_names_list = os.listdir('..') |
| 36 |
orig_files = [] |
| 37 |
search_expresion = UPSTREAM_VERSION + '.orig' |
| 38 |
|
| 39 |
for file_name in file_names_list: |
| 40 |
if search_expresion in file_name: |
| 41 |
orig_files.append(file_name) |
| 42 |
|
| 43 |
if len(orig_files) != 1: |
| 44 |
raise ValueError('More than one file matched expresion {}.'.format(search_expresion)) |
| 45 |
|
| 46 |
return '../' + orig_files[0] |
| 47 |
|
| 48 |
|
| 49 |
def filter_function(tarinfo): |
| 50 |
for exclude in EXCLUDE_LIST: |
| 51 |
|
| 52 |
if exclude in tarinfo.name: |
| 53 |
return None |
| 54 |
tarinfo.name = os.path.relpath('/' + tarinfo.name, GCC_TMP_DIR) |
| 55 |
return tarinfo |
| 56 |
|
| 57 |
|
| 58 |
def get_gcc_file(dir): |
| 59 |
for root, dirs, files in os.walk(tmpdir, topdown=False): |
| 60 |
for filename in files: |
| 61 |
if filename.startswith('gcc.tar'): |
| 62 |
return os.path.join(root, filename) |
| 63 |
raise Exception('gcc tarball not found') |
| 64 |
|
| 65 |
|
| 66 |
def replace_all_texi_files(dir): |
| 67 |
for root, dirs, files in os.walk(dir, topdown=False): |
| 68 |
for filename in files: |
| 69 |
if filename.endswith('.texi'): |
| 70 |
path = os.path.join(root, filename) |
| 71 |
with open(path, 'w') as fh: |
| 72 |
fh.write("Please refer to the gcc package documentation") |
| 73 |
|
| 74 |
|
| 75 |
tarball_path = get_orig_file_name() |
| 76 |
|
| 77 |
with tempfile.TemporaryDirectory() as tmpdir: |
| 78 |
with tarfile.open(tarball_path) as tar: |
| 79 |
tar.extractall(tmpdir) |
| 80 |
gcc_path = get_gcc_file(tmpdir) |
| 81 |
os.remove(tarball_path) |
| 82 |
|
| 83 |
with tempfile.TemporaryDirectory() as gcc_tmp_dir: |
| 84 |
with tarfile.open(gcc_path) as tar: |
| 85 |
tar.extractall(gcc_tmp_dir) |
| 86 |
|
| 87 |
replace_all_texi_files(gcc_tmp_dir) |
| 88 |
GCC_TMP_DIR = gcc_tmp_dir |
| 89 |
with tarfile.open(tarball_path, 'w:xz') as tarwriter: |
| 90 |
tarwriter.add(gcc_tmp_dir, filter=filter_function) |