• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2022 Institute of Software, CAS
5# Author: xiaofan@iscas.ac.cn
6
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23# SOFTWARE.
24import sys
25import os
26import os.path
27import subprocess
28import multiprocessing
29import glob
30import shutil
31from meson_cross_process import prepare_environment
32
33# input /path/to/openharmony/out/rk3568
34
35nproc = multiprocessing.cpu_count()
36out_dir = sys.argv[1]
37mesa3d_install_dir = os.path.join(out_dir, 'packages', 'phone', 'mesa3d')
38product = os.path.basename(out_dir)
39project_dir = os.path.dirname(os.path.dirname(out_dir))
40project_dir = os.path.abspath(project_dir)
41mesa3d_dir = os.path.dirname(os.path.dirname(__file__))
42mesa3d_dir = os.path.abspath(mesa3d_dir)
43pkgconf_dir = os.path.join(mesa3d_dir, './pkgconfig')
44os.environ['PKG_CONFIG_PATH'] = pkgconf_dir
45
46# workaround: using system python instead of prebuilt python
47path_old = os.environ['PATH'].split(':')
48path_filter = lambda p: not p.endswith('/prebuilts/python/linux-x86/3.8.5/bin')
49path_new = ':'.join(filter(path_filter, path_old))
50os.environ['PATH'] = path_new
51
52os.chdir(mesa3d_dir)
53prepare_environment(project_dir, product)
54
55meson_cmd = [
56    'meson',
57    'setup',
58    mesa3d_dir,
59    'build-ohos',
60    '-Dplatforms=ohos',
61    '-Degl-native-platform=ohos',
62    '-Ddri-drivers=',
63    '-Dgallium-drivers=panfrost',
64    '-Dvulkan-drivers=',
65    '-Dgbm=enabled',
66    '-Degl=enabled',
67    '-Dcpp_rtti=false',
68    '-Dglx=disabled',
69    '-Dtools=panfrost',
70    '-Ddri-search-path=/system/lib',
71    '--cross-file=cross_file',
72    F'--prefix={mesa3d_dir}/build-ohos/install',
73]
74
75subprocess.run(meson_cmd, check=True)
76subprocess.run(F'ninja -C build-ohos -j{nproc}', shell=True, check=True)
77subprocess.run(F'ninja -C build-ohos install', shell=True, check=True)
78
79build_lib = os.path.join(mesa3d_dir, 'build-ohos', 'install', 'lib')
80build_lib_dri = os.path.join(build_lib, 'dri')
81
82# install to out/rk3568/packages/phone/mesa3d
83shutil.rmtree(mesa3d_install_dir, ignore_errors=True)
84os.makedirs(mesa3d_install_dir, exist_ok=True)
85for item in glob.glob(os.path.join(build_lib, 'lib*.so.*.*.*')):
86    shutil.copy(item, mesa3d_install_dir)
87for item in glob.glob(os.path.join(build_lib_dri, '*_dri.so')):
88    # all *_dir.so are same file, we need only copy one and rename it to libgallium_dri.so
89    shutil.copy(item, os.path.join(mesa3d_install_dir, 'libgallium_dri.so')) # consider create symlink or hardlink
90    break
91