|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright 2022 Samsung Electronics Co., Ltd. All rights reserved. |
| 3 | +# Use of this source code is governed by a BSD-style license that can be |
| 4 | +# found in the LICENSE file. |
| 5 | + |
| 6 | +import argparse |
| 7 | +import os |
| 8 | +import re |
| 9 | +import shutil |
| 10 | +import subprocess |
| 11 | +import sys |
| 12 | +import urllib.parse |
| 13 | +import urllib.request |
| 14 | +from pathlib import Path |
| 15 | + |
| 16 | + |
| 17 | +base_packages = [ |
| 18 | + 'gcc', |
| 19 | + 'glibc', |
| 20 | + 'glibc-devel', |
| 21 | + 'libgcc', |
| 22 | + 'libstdc++', |
| 23 | + 'libstdc++-devel', |
| 24 | + 'linux-glibc-devel', |
| 25 | +] |
| 26 | + |
| 27 | +unified_packages = [ |
| 28 | + 'atk-devel', |
| 29 | + 'at-spi2-atk-devel', |
| 30 | + 'capi-appfw-application', |
| 31 | + 'capi-appfw-application-devel', |
| 32 | + 'capi-appfw-app-common', |
| 33 | + 'capi-appfw-app-common-devel', |
| 34 | + 'capi-appfw-app-control', |
| 35 | + 'capi-appfw-app-control-devel', |
| 36 | + 'capi-base-common', |
| 37 | + 'capi-base-common-devel', |
| 38 | + 'capi-base-utils', |
| 39 | + 'capi-base-utils-devel', |
| 40 | + 'capi-system-info', |
| 41 | + 'capi-system-info-devel', |
| 42 | + 'capi-system-system-settings', |
| 43 | + 'capi-system-system-settings-devel', |
| 44 | + 'capi-ui-efl-util', |
| 45 | + 'capi-ui-efl-util-devel', |
| 46 | + 'cbhm', |
| 47 | + 'cbhm-devel', |
| 48 | + 'coregl', |
| 49 | + 'coregl-devel', |
| 50 | + 'ecore-con-devel', |
| 51 | + 'ecore-core', |
| 52 | + 'ecore-core-devel', |
| 53 | + 'ecore-evas', |
| 54 | + 'ecore-evas-devel', |
| 55 | + 'ecore-file-devel', |
| 56 | + 'ecore-imf', |
| 57 | + 'ecore-imf-devel', |
| 58 | + 'ecore-imf-evas', |
| 59 | + 'ecore-imf-evas-devel', |
| 60 | + 'ecore-input', |
| 61 | + 'ecore-input-devel', |
| 62 | + 'ecore-wayland', |
| 63 | + 'ecore-wayland-devel', |
| 64 | + 'ecore-wl2', |
| 65 | + 'ecore-wl2-devel', |
| 66 | + 'edje-devel', |
| 67 | + 'eet', |
| 68 | + 'eet-devel', |
| 69 | + 'efl-devel', |
| 70 | + 'efl-extension', |
| 71 | + 'efl-extension-devel', |
| 72 | + 'efreet-devel', |
| 73 | + 'eina', |
| 74 | + 'eina-devel', |
| 75 | + 'eina-tools', |
| 76 | + 'elementary', |
| 77 | + 'elementary-devel', |
| 78 | + 'emile-devel', |
| 79 | + 'eo-devel', |
| 80 | + 'ethumb-devel', |
| 81 | + 'evas', |
| 82 | + 'evas-devel', |
| 83 | + 'glib2-devel', |
| 84 | + 'jsoncpp', |
| 85 | + 'jsoncpp-devel', |
| 86 | + 'libatk', |
| 87 | + 'libatk-bridge-2_0-0', |
| 88 | + 'libfeedback', |
| 89 | + 'libfeedback-devel', |
| 90 | + 'libdlog', |
| 91 | + 'libdlog-devel', |
| 92 | + 'libglib', |
| 93 | + 'libgobject', |
| 94 | + 'libtbm', |
| 95 | + 'libtbm-devel', |
| 96 | + 'libtdm-client', |
| 97 | + 'libtdm-client-devel', |
| 98 | + 'libtdm-devel', |
| 99 | + 'libwayland-client', |
| 100 | + 'libwayland-cursor', |
| 101 | + 'libwayland-egl', |
| 102 | + 'libwayland-extension-client', |
| 103 | + 'libxkbcommon', |
| 104 | + 'libxkbcommon-devel', |
| 105 | + 'tzsh', |
| 106 | + 'tzsh-devel', |
| 107 | + 'vulkan-headers', |
| 108 | + 'vulkan-loader', |
| 109 | + 'vulkan-loader-devel', |
| 110 | + 'wayland-extension-client-devel', |
| 111 | + 'wayland-devel', |
| 112 | +] |
| 113 | + |
| 114 | +# Only available for Tizen 6.5 and above. |
| 115 | +dali_packages = [ |
| 116 | + 'dali2', |
| 117 | + 'dali2-adaptor', |
| 118 | + 'dali2-adaptor-devel', |
| 119 | + 'dali2-devel', |
| 120 | + 'dali2-toolkit', |
| 121 | + 'dali2-toolkit-devel', |
| 122 | +] |
| 123 | + |
| 124 | + |
| 125 | +def generate_sysroot(sysroot: Path, api_version: float, arch: str, quiet=False): |
| 126 | + if arch == 'arm': |
| 127 | + tizen_arch = 'armv7l' |
| 128 | + elif arch == 'arm64': |
| 129 | + tizen_arch = 'aarch64' |
| 130 | + elif arch == 'x86': |
| 131 | + tizen_arch = 'i686' |
| 132 | + else: |
| 133 | + sys.exit('Unknown arch: ' + arch) |
| 134 | + |
| 135 | + base_repo = 'http://download.tizen.org/snapshots/tizen/{}-base/latest/repos/standard/packages'.format( |
| 136 | + api_version) |
| 137 | + unified_repo = 'http://download.tizen.org/snapshots/tizen/{}-unified/latest/repos/standard/packages'.format( |
| 138 | + api_version) |
| 139 | + |
| 140 | + # Retrieve html documents. |
| 141 | + documents = {} |
| 142 | + for url in ['{}/{}'.format(base_repo, tizen_arch), |
| 143 | + '{}/{}'.format(base_repo, 'noarch'), |
| 144 | + '{}/{}'.format(unified_repo, tizen_arch), |
| 145 | + '{}/{}'.format(unified_repo, 'noarch')]: |
| 146 | + request = urllib.request.Request(url) |
| 147 | + with urllib.request.urlopen(request) as response: |
| 148 | + documents[url] = response.read().decode('utf-8') |
| 149 | + |
| 150 | + # Download packages. |
| 151 | + download_path = sysroot / '.rpms' |
| 152 | + download_path.mkdir(exist_ok=True) |
| 153 | + existing_rpms = [f for f in download_path.iterdir() if f.suffix == '.rpm'] |
| 154 | + |
| 155 | + packages = base_packages + unified_packages |
| 156 | + if api_version >= 6.5: |
| 157 | + packages += dali_packages |
| 158 | + |
| 159 | + for package in packages: |
| 160 | + quoted = urllib.parse.quote(package) |
| 161 | + pattern = re.escape(quoted) + '-\\d+\\.[\\d_\\.]+-[\\d\\.]+\\..+\\.rpm' |
| 162 | + |
| 163 | + if any([re.match(pattern, rpm.name) for rpm in existing_rpms]): |
| 164 | + continue |
| 165 | + |
| 166 | + for parent, doc in documents.items(): |
| 167 | + match = re.search('<a href="({})">.+?</a>'.format(pattern), doc) |
| 168 | + if match: |
| 169 | + rpm_url = '{}/{}'.format(parent, match.group(1)) |
| 170 | + break |
| 171 | + |
| 172 | + if match: |
| 173 | + if not quiet: |
| 174 | + print('Downloading ' + rpm_url) |
| 175 | + urllib.request.urlretrieve(rpm_url, download_path / match.group(1)) |
| 176 | + else: |
| 177 | + sys.exit('Could not find a package named ' + package) |
| 178 | + |
| 179 | + # Extract files. |
| 180 | + for rpm in [f for f in download_path.iterdir() if f.suffix == '.rpm']: |
| 181 | + command = 'rpm2cpio {} | cpio -idum --quiet'.format(rpm) |
| 182 | + subprocess.run(command, shell=True, cwd=sysroot, check=True) |
| 183 | + |
| 184 | + # Create symbolic links. |
| 185 | + asm = sysroot / 'usr' / 'include' / 'asm' |
| 186 | + if not asm.exists(): |
| 187 | + os.symlink('asm-' + arch, asm) |
| 188 | + pkgconfig = sysroot / 'usr' / 'lib' / 'pkgconfig' |
| 189 | + if arch == 'arm64' and not pkgconfig.exists(): |
| 190 | + os.symlink('../lib64/pkgconfig', pkgconfig) |
| 191 | + |
| 192 | + # Copy objects required by the linker, such as crtbeginS.o and libgcc.a. |
| 193 | + if arch == 'arm64': |
| 194 | + libpath = sysroot / 'usr' / 'lib64' |
| 195 | + else: |
| 196 | + libpath = sysroot / 'usr' / 'lib' |
| 197 | + subprocess.run('cp gcc/*/*/*.o gcc/*/*/*.a .', |
| 198 | + shell=True, cwd=libpath, check=True) |
| 199 | + |
| 200 | + |
| 201 | +def main(): |
| 202 | + # Check dependencies. |
| 203 | + for dep in ['rpm2cpio', 'cpio', 'git']: |
| 204 | + if not shutil.which(dep): |
| 205 | + sys.exit('{} is not installed. To install, run:\n' |
| 206 | + ' sudo apt install {}'.format(dep, dep)) |
| 207 | + |
| 208 | + # Parse arguments. |
| 209 | + parser = argparse.ArgumentParser(description='Tizen sysroot generator') |
| 210 | + parser.add_argument('-o', '--out', metavar='PATH', type=str, |
| 211 | + help='Path to the output directory') |
| 212 | + parser.add_argument('-f', '--force', action='store_true', |
| 213 | + help='Force re-downloading of packages') |
| 214 | + parser.add_argument('-q', '--quiet', action='store_true', |
| 215 | + help='Suppress log output') |
| 216 | + parser.add_argument('--api-version', metavar='VER', default=5.5, type=float, |
| 217 | + help='Target API version (defaults to 5.5)') |
| 218 | + args = parser.parse_args() |
| 219 | + |
| 220 | + if args.out: |
| 221 | + outpath = Path(args.out) |
| 222 | + else: |
| 223 | + outpath = Path(__file__).parent.parent / 'sysroot' |
| 224 | + outpath.mkdir(exist_ok=True) |
| 225 | + |
| 226 | + for arch in ['arm', 'arm64', 'x86']: |
| 227 | + sysroot = outpath / arch |
| 228 | + if args.force and sysroot.is_dir(): |
| 229 | + shutil.rmtree(sysroot) |
| 230 | + sysroot.mkdir(exist_ok=True) |
| 231 | + |
| 232 | + if not args.quiet: |
| 233 | + print('Generating sysroot for {}...'.format(arch)) |
| 234 | + generate_sysroot(sysroot.resolve(), args.api_version, arch, args.quiet) |
| 235 | + |
| 236 | + |
| 237 | +# Execute only if run as a script. |
| 238 | +if __name__ == '__main__': |
| 239 | + main() |
0 commit comments