From 801d1fc493a29092b7cd7b8779a83d2b8e0b6d49 Mon Sep 17 00:00:00 2001 From: Dela Date: Sat, 2 Jul 2016 13:43:32 -0400 Subject: [PATCH] Add unmerged changes. --- .python-version | 1 + a8f18bb0-3d1d-4ebb-b47c-5438cd203719.o | Bin 0 -> 4480 bytes kbuilder/cli/bootstrap.py | 11 ++ kbuilder/cli/controllers/base.py | 19 +++ kbuilder/cli/hooks/kernel.py | 10 ++ kbuilder/cli/main.py | 9 ++ kbuilder/core/kbuild_image.py | 16 +++ kbuilder/core/kernel.py | 15 ++- kbuilder/core/kernel_android.py | 157 +++++++++++++++++++++++++ 9 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 .python-version create mode 100644 a8f18bb0-3d1d-4ebb-b47c-5438cd203719.o create mode 100644 kbuilder/cli/hooks/kernel.py create mode 100644 kbuilder/core/kbuild_image.py create mode 100644 kbuilder/core/kernel_android.py diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..d5c0c99 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.5.1 diff --git a/a8f18bb0-3d1d-4ebb-b47c-5438cd203719.o b/a8f18bb0-3d1d-4ebb-b47c-5438cd203719.o new file mode 100644 index 0000000000000000000000000000000000000000..8692c05bab9f970e6911a193b84d3f39274b83fb GIT binary patch literal 4480 zcmbVPO>9(E6h3ce3PTIEKcFROoCO#Ny!oGLixvuXESN?OO(QC#yqS6JjLsi#-qb=g z8k-m!Hn1@+NYsTUCN5mKz?CF5{w>|e%9R=xUC7c%g6G_KPPx4dfpD64?>XQ7&OP^@ z`!l!i6=q%tSr&*`a0KpJf&xr#*L0;$!Y&wsxf82@omg2P_^EK4+%6Svum1QwwO^y+ zCKZVNvZnDu0ro&%_(8l`3_PMjtgflb;_Aj~Vf|8J{hkPFOea=;7XomG+5h+(B0#A_UP3-GGIM+e~)cA zTZ%Ct9%^XTF1`O_Gr0@C1%?FZA^tK?o<$ zDrPAXw~p=(M-TTs+t=tnIZWiqk&ln>wuUi$7J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_u)O zpVU{7Bf4_nBKY4_M*`jCeu*$)oURQA@&9B42^5*Xz@MYiEq_VQ-#I2y{s!<9f6410 wV&>T+m&@$`4H=r4 Tuple[Path, str]: + """Build multiple kbuild images the kernel. + + Return the path of the absolute path of kbuild image if the build is + successful. + Keyword arguments: + toolchains -- the toolchain to use in building the kernel + build_log_dir -- the directory of the build log file + """ + for toolchain in toolchains: + yield self.build(toolchain, build_log_dir) diff --git a/kbuilder/core/kernel_android.py b/kbuilder/core/kernel_android.py new file mode 100644 index 0000000..3c0e454 --- /dev/null +++ b/kbuilder/core/kernel_android.py @@ -0,0 +1,157 @@ +# Copyright (C) 2016 Dela Anthonio +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +"""Provide an interface for android kernels.""" + +import os +from typing import Iterable, Tuple +import shutil +from subprocess import check_call + +from cached_property import cached_property +from unipath import Path + +from kbuilder.core.arch import Arch, UnsupportedArch +from kbuilder.core.gcc import Toolchain +from kbuilder.core.kernel import Kernel +import kbuilder.core.make as mk + + +class AndroidKernel(Kernel): + """Provide an interface for android kernels""" + + def __init__(self, root: str, arch: Arch, *, + defconfig: str='defconfig') -> None: + """Initialze a new Kernel. + + Keyword arguments: + root -- the root directory of the kernel + defconfig -- the defconfig file to use in building the kernel. + """ + Kernel.__init__(root) + self.version = self._find_kernel_version() + self.version_numbers = self.version[-5:] + self._defconfig = defconfig + self._arch = arch + self._kbuild_image = "TODO" + + @property + def defconfig(self): + """The default configuration file of the kernel.""" + return self._defconfig + + @cached_property + def version(self): + return self._find_kernel_version() + + @cached_property + def version_numbers(self): + """The kernel version in MAJOR.MINOR.PATCH format.""" + return self._find_kernel_version()[:-5] + + @cached_property + def kbuild_image(self): + """The path to the compressed kernel image.""" + return self.kbuild_image_abs_path(self.arch, self.kbuild_image) + + def _find_kernel_version(self) -> str: + """Return what the version of the kernel is.""" + with self: + output = mk.make_output('kernelrelease').rstrip() + lines = output.split('\n') + kernelrelease = lines[-1] + return kernelrelease[8:] + + def _find_kbuild_image_name(self): + if self.arch == Arch.arm: + return 'zImage' + elif self.arch == Arch.arm64: + return 'Image.gz-dtb' + elif self.arch == Arch.x86: + return 'bzImage' + else: + raise UnsupportedArch + + def release_version(self, extra_version: str=None) -> str: + """Get the kernel version with the toolchain name appended. + + Arguments: + extension -- the extension to add to this. + """ + if extra_version: + return '{0.version}-{1}'.format(self, extra_version) + else: + return self.version + + def make_defconfig(self) -> None: + """Make the default configuration file.""" + mk.make(self.defconfig) + + def build_kbuild_image(self, *, toolchain: Toolchain, + build_log_dir: str=None) -> Tuple[Path, str]: + """Build the kernel kbuild. + + Return the path of the absolute path of kbuild image if the build is + successful. + Keyword arguments: + toolchain -- the toolchain to use in building the kernel + defconfig -- the default configuration file (default '') + build_log_dir -- the directory of the build log file + """ + kernel_release_version = self.release_version(toolchain.name) + Path(build_log_dir).mkdir() + build_log = Path(build_log_dir, kernel_release_version + '-log.txt') + + print('compiling {0.version} with {1.name}'.format(self, toolchain)) + output = mk.make_output('all') + build_log.write_file(output) + return self.kbuild_image, kernel_release_version + + def build_kbuild_images(self, toolchains: Iterable[Toolchain], + build_log_dir: str=None) -> Tuple[Path, str]: + """Build multiple kbuild images the kernel. + + Return the path of the absolute path of kbuild image if the build is + successful. + Keyword arguments: + toolchain -- the toolchain to use in building the kernel + defconfig -- the default configuration file (default '') + build_log_dir -- the directory of the build log file + """ + for toolchain in toolchains: + yield self.build(toolchain, build_log_dir) + + def make_boot_img(self, name: str, ramdisk: str='ramdisk.img'): + """Create a boot.img file that can be install via fastboot. + + Keyword arguments: + name -- the name of the output file + kbuild_image -- the kernel image to include in the boot.img file + ramdisk -- the ramdisk image to include in the boot.img file + """ + args = '--output {} --kernel {} --ramdisk {}'.format(name, + self.kbuild_image, + ramdisk) + check_call('mkbootimg ' + args, shell=True) + + def zip_ota_package(self, name: str, base_dir: str=os.getcwd()) -> str: + """Create a zip package that can be installed via recovery. + + Return the path to the zip file created + Keyword arguments: + name -- the name of the zip file to create + base_dir -- the directory whose contents should be zipped (default cwd) + """ + return shutil.make_archive(name, 'zip', base_dir)