• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2023 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import tarfile
17import argparse
18import os
19import subprocess
20import sys
21import shutil
22
23
24def untar_file(tar_file_path, extract_path):
25    try:
26        tar_cmd = ['tar', '-xvf', tar_file_path, '-C', extract_path, '--strip-components=1']
27        subprocess.run(tar_cmd, check=True)
28    except Exception as e:
29        print("tar error!")
30        return
31
32
33def move_file(src_path, dst_path):
34    files = [
35        "backport-freetype-2.2.1-enable-valid.patch",
36        "backport-freetype-2.3.0-enable-spr.patch",
37        "backport-freetype-2.6.5-libtool.patch",
38        "backport-freetype-2.8-multilib.patch",
39        "backport-freetype-2.10.0-internal-outline.patch",
40        "backport-freetype-2.10.1-debughook.patch",
41        "backport-freetype-2.12.1-enable-funcs.patch",
42        "ftconfig.h"
43    ]
44    for file in files:
45        src_file = os.path.join(src_path, file)
46        dst_file = os.path.join(dst_path, file)
47        shutil.copy(src_file, dst_file)
48
49def move_include(src_path, dst_path):
50    try:
51        cp_cmd = ['cp', '-rf', dst_path, src_path]
52        subprocess.run(cp_cmd, check=True)
53    except Exception as e:
54        print("cp -rf error!")
55        return
56
57
58def apply_patch(patch_file, target_dir):
59    try:
60        if not os.path.exists(target_dir):
61            return
62        patch_cmd = ['patch', '-p1', "--fuzz=0", "--no-backup-if-mismatch", '-i', patch_file, '-d', target_dir]
63        subprocess.run(patch_cmd, check=True)
64    except Exception as e:
65        print("apply_patch error!")
66        return
67
68
69def do_patch(target_dir):
70    patch_file = [
71        "backport-freetype-2.2.1-enable-valid.patch",
72        "backport-freetype-2.3.0-enable-spr.patch",
73        "backport-freetype-2.6.5-libtool.patch",
74        "backport-freetype-2.8-multilib.patch",
75        "backport-freetype-2.10.0-internal-outline.patch",
76        "backport-freetype-2.10.1-debughook.patch",
77        "backport-freetype-2.12.1-enable-funcs.patch"
78    ]
79
80    for patch in patch_file:
81        apply_patch(patch, target_dir)
82
83
84def main():
85    freetype_path = argparse.ArgumentParser()
86    freetype_path.add_argument('--gen-dir', help='generate path of log', required=True)
87    freetype_path.add_argument('--source-dir', help='generate path of log', required=True)
88    args = freetype_path.parse_args()
89    tar_file_path = os.path.join(args.source_dir, "freetype-2.13.3.tar.xz")
90    target_dir = os.path.join(args.gen_dir, "freetype")
91    target_include_dir = os.path.join(target_dir, "include")
92
93    untar_file(tar_file_path, target_dir)
94    move_file(args.source_dir, target_dir)
95    move_include(args.source_dir, target_include_dir)
96    do_patch(target_dir)
97    return 0
98
99if __name__ == '__main__':
100    sys.exit(main())
101