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