├── .concourse ├── scripts │ └── generate-pipelines.sh ├── tasks │ ├── build-docker-gcc.yml │ ├── build-docker-kraft.yml │ ├── build-docker-pkg-deb.yml │ ├── build-docker-qemu.yml │ ├── build-pkg-deb.yml │ ├── build-pkg-pypi.yaml │ ├── test-kraft.yml │ └── test-pkg-deb.yml └── templates │ ├── mixins.lib.yml │ ├── pr.yml │ ├── stable.yml │ └── staging.yml ├── .dockerignore ├── .editorconfig ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .pre-commit-config.yaml ├── CONTRIBUTING.md ├── COPYING.md ├── MAINTAINERS.md ├── MANIFEST.in ├── Makefile ├── README.md ├── kraft ├── .kraftrc ├── __init__.py ├── app │ ├── __init__.py │ └── app.py ├── arch │ ├── __init__.py │ └── arch.py ├── cache.py ├── cmd │ ├── __init__.py │ ├── build.py │ ├── clean.py │ ├── configure.py │ ├── fetch.py │ ├── init.py │ ├── lib │ │ ├── __init__.py │ │ ├── add.py │ │ ├── bump.py │ │ ├── init.py │ │ └── remove.py │ ├── list │ │ ├── __init__.py │ │ ├── add.py │ │ ├── list.py │ │ ├── provider │ │ │ ├── __init__.py │ │ │ ├── git.py │ │ │ ├── github.py │ │ │ ├── provider.py │ │ │ ├── tarball.py │ │ │ └── types.py │ │ ├── pull.py │ │ ├── remove.py │ │ ├── show.py │ │ └── update.py │ ├── menuconfig.py │ ├── prepare.py │ ├── run.py │ └── up.py ├── component.py ├── config │ ├── __init__.py │ ├── config.py │ ├── environment.py │ ├── interpolation.py │ ├── kconfig.py │ ├── serialize.py │ ├── specification_v0.4.json │ ├── specification_v0.5.json │ ├── types.py │ ├── validation.py │ └── version.py ├── const.py ├── context.py ├── error.py ├── kraft.py ├── lib │ ├── __init__.py │ ├── lib.py │ └── provider │ │ ├── __init__.py │ │ ├── git.py │ │ ├── github.py │ │ ├── provider.py │ │ ├── sourceforge.py │ │ ├── tarball.py │ │ └── types.py ├── logger.py ├── manifest │ ├── __init__.py │ └── manifest.py ├── plat │ ├── __init__.py │ ├── network │ │ ├── __init__.py │ │ ├── driver │ │ │ ├── __init__.py │ │ │ ├── brctl.py │ │ │ ├── driver.py │ │ │ └── types.py │ │ └── network.py │ ├── plat.py │ ├── runner │ │ ├── __init__.py │ │ ├── kvm.py │ │ ├── linuxu.py │ │ ├── runner.py │ │ ├── types.py │ │ └── xen.py │ └── volume │ │ ├── __init__.py │ │ ├── types.py │ │ └── volume.py ├── settings.py ├── target │ ├── __init__.py │ └── target.py ├── template │ ├── __init__.py │ └── lib │ │ ├── cookiecutter.json │ │ └── {{cookiecutter.project_name}} │ │ ├── CODING_STYLE.md │ │ ├── CONTRIBUTING.md │ │ ├── COPYING.md │ │ ├── Config.uk │ │ ├── MAINTAINERS.md │ │ ├── Makefile.uk │ │ ├── README.md │ │ ├── main.c │ │ └── manifest.yaml ├── types.py ├── unikraft.py └── util │ ├── __init__.py │ ├── cli.py │ ├── dir.py │ ├── make.py │ ├── op.py │ ├── text.py │ └── threading.py ├── package ├── debian │ ├── changelog │ ├── compat │ ├── control │ ├── copyright │ ├── rules │ ├── source │ │ ├── format │ │ └── options │ ├── unikraft-tools.links │ ├── unikraft-tools.lintian-overrides │ └── unikraft-tools.triggers └── docker │ ├── Dockerfile.gcc │ ├── Dockerfile.kraft │ ├── Dockerfile.linuxk │ ├── Dockerfile.pkg-deb │ ├── Dockerfile.pkg-deb-test │ ├── Dockerfile.qemu │ ├── Makefile │ ├── keys.asc │ └── linuxu │ ├── Dockerfile │ ├── Makefile.in │ ├── config-arm │ ├── config-x86_64 │ ├── linuxk-5.4.x-arm64 │ └── linuxk-5.4.x-x86_64 ├── requirements-dev.txt ├── requirements-pkg-deb.txt ├── requirements.txt ├── scripts ├── kraft-net ├── qemu-guest └── xen-guest ├── setup.py ├── tests ├── __init__.py ├── helpers.py └── unit │ ├── __init__.py │ └── cli_test.py └── tox.ini /.concourse/tasks/build-docker-gcc.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: vito/oci-build-task 8 | 9 | params: 10 | DOCKERFILE: package/docker/Dockerfile.gcc 11 | CONTEXT: . 12 | BUILD_ARG_HTTP_PROXY: ((http_proxy)) 13 | BUILD_ARG_HTTPS_PROXY: ((https_proxy)) 14 | # BUILD_ARG_UK_ARCH: x86_64 15 | # BUILD_ARG_GCC_VERSION: 9.2.0 16 | # BUILD_ARG_BINUTILS_VERSION: 2.31.1 17 | # BUILD_ARG_GLIB_VERSION: 2.11 18 | 19 | inputs: 20 | - name: kraft 21 | path: . 22 | 23 | outputs: 24 | - name: image 25 | 26 | caches: 27 | - path: cache 28 | 29 | run: 30 | path: build 31 | -------------------------------------------------------------------------------- /.concourse/tasks/build-docker-kraft.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: vito/oci-build-task 8 | 9 | inputs: 10 | - name: kraft 11 | path: . 12 | 13 | params: 14 | DOCKERFILE: package/docker/Dockerfile.kraft 15 | CONTEXT: . 16 | BUILD_ARG_HTTP_PROXY: ((http_proxy)) 17 | BUILD_ARG_HTTPS_PROXY: ((https_proxy)) 18 | # BUILD_ARG_GCC_VERSION: ((kraft_gcc_version)) 19 | # BUILD_ARG_UK_ARCH: ((kraft_uk_arch)) 20 | # BUILD_ARG_GCC_PREFIX: ((kraft_gcc_prefix)) 21 | # BUILD_ARG_YTT_VERSION: ((kraft_ytt_version)) 22 | # BUILD_ARG_YQ_VERSION: ((kraft_yq_version)) 23 | 24 | outputs: 25 | - name: image 26 | 27 | caches: 28 | - path: cache 29 | 30 | run: 31 | path: build 32 | -------------------------------------------------------------------------------- /.concourse/tasks/build-docker-pkg-deb.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: vito/oci-build-task 8 | 9 | params: 10 | DOCKERFILE: package/docker/Dockerfile.pkg-deb 11 | CONTEXT: . 12 | BUILD_ARG_HTTP_PROXY: ((http_proxy)) 13 | BUILD_ARG_HTTPS_PROXY: ((https_proxy)) 14 | # BUILD_ARG_PKG_VENDOR: debian 15 | # BUILD_ARG_PKG_DISTRIBUTION: stretch 16 | 17 | inputs: 18 | - name: kraft 19 | path: . 20 | 21 | outputs: 22 | - name: image 23 | 24 | caches: 25 | - path: cache 26 | 27 | run: 28 | path: build 29 | -------------------------------------------------------------------------------- /.concourse/tasks/build-docker-qemu.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: vito/oci-build-task 8 | 9 | params: 10 | DOCKERFILE: package/docker/Dockerfile.qemu 11 | CONTEXT: . 12 | BUILD_ARG_HTTP_PROXY: ((http_proxy)) 13 | BUILD_ARG_HTTPS_PROXY: ((https_proxy)) 14 | # BUILD_ARG_QEMU_VERSION: ((kraft_qemu_version)) 15 | 16 | inputs: 17 | - name: kraft 18 | path: . 19 | 20 | outputs: 21 | - name: image 22 | 23 | caches: 24 | - path: cache 25 | 26 | run: 27 | path: build 28 | -------------------------------------------------------------------------------- /.concourse/tasks/build-pkg-deb.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: unikraft/pkg-deb 8 | tag: ((tag)) 9 | 10 | params: 11 | DIRTY: 12 | 13 | inputs: 14 | - name: kraft 15 | path: . 16 | 17 | outputs: 18 | - name: dist 19 | 20 | run: 21 | path: bash 22 | args: 23 | - -cex 24 | - | 25 | PKG_VENDOR=((vendor)) \ 26 | PKG_DISTRIBUTION=((distribution)) \ 27 | DIRTY=$DIRTY \ 28 | DOCKER= \ 29 | make get-version > dist/version 30 | 31 | PKG_VENDOR=((vendor)) \ 32 | PKG_DISTRIBUTION=((distribution)) \ 33 | APP_VERSION=$(cat dist/version) \ 34 | DOCKER= \ 35 | make pkg-deb 36 | -------------------------------------------------------------------------------- /.concourse/tasks/build-pkg-pypi.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: unikraft/kraft 8 | tag: ((tag)) 9 | 10 | params: 11 | DIRTY: 12 | 13 | inputs: 14 | - name: kraft 15 | path: . 16 | 17 | outputs: 18 | - name: dist 19 | 20 | run: 21 | path: bash 22 | args: 23 | - -cex 24 | - | 25 | DIRTY=$DIRTY \ 26 | DOCKER= \ 27 | make get-version | sed "s/+.*//" > dist/version 28 | 29 | APP_VERSION=$(cat dist/version) \ 30 | DOCKER= \ 31 | make sdist 32 | -------------------------------------------------------------------------------- /.concourse/tasks/test-kraft.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: docker-image 6 | source: 7 | repository: unikraft/kraft 8 | tag: latest-dev 9 | 10 | inputs: 11 | - name: kraft 12 | path: . 13 | 14 | params: 15 | HTTP_PROXY: ((http_proxy)) 16 | HTTPS_PROXY: ((https_proxy)) 17 | 18 | run: 19 | path: bash 20 | args: 21 | - -cex 22 | - ((target_cmd)) 23 | -------------------------------------------------------------------------------- /.concourse/tasks/test-pkg-deb.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: docker-image 6 | source: 7 | repository: ((vendor)) 8 | tag: ((distribution)) 9 | 10 | run: 11 | path: bash 12 | args: 13 | - -cex 14 | - | 15 | export LANG=C.UTF-8; 16 | export LC_ALL=C.UTF-8; 17 | export DEBIAN_FRONTEND=noninteractive; 18 | apt-get update; 19 | apt-get install -y wget; 20 | wget -O unikraft-tools.deb http://releases.unikraft.org/linux/((vendor))/pool/((branch))/u/unikraft-tools/((basename)) 21 | dpkg -i ./unikraft-tools.deb || true 22 | apt-get install -y -f 23 | basename="((basename))" 24 | kraft --version 25 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | *.egg-info 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.py] 2 | indent_style = space 3 | indent_size = 4 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: gaulthiergain 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. Linux] 28 | - Version [e.g. 0.0.1] 29 | 30 | **Additional context** 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | tools 3 | *.patch 4 | *.diff 5 | __pycache__ 6 | *.egg-info 7 | dist/ 8 | .tox/ 9 | *.pyc 10 | .concourse/pipelines/ 11 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | sha: 'v0.9.1' 4 | hooks: 5 | - id: check-added-large-files 6 | - id: check-docstring-first 7 | - id: check-merge-conflict 8 | - id: check-yaml 9 | exclude: 'kraft/template/' 10 | - id: check-json 11 | - id: debug-statements 12 | - id: end-of-file-fixer 13 | - id: flake8 14 | - id: name-tests-test 15 | exclude: 'tests/(integration/testcases\.py|helpers\.py)' 16 | - id: requirements-txt-fixer 17 | - id: trailing-whitespace 18 | - repo: https://github.com/asottile/reorder_python_imports 19 | sha: 'v1.3.4' 20 | hooks: 21 | - id: reorder-python-imports 22 | args: 23 | - --add-import 24 | - from __future__ import absolute_import 25 | - --add-import 26 | - from __future__ import unicode_literals 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to Unikraft 2 | ======================= 3 | 4 | Please refer to the `CONTRIBUTING.md` file in the main Unikraft repository. 5 | -------------------------------------------------------------------------------- /COPYING.md: -------------------------------------------------------------------------------- 1 | License 2 | ======= 3 | 4 | Unikraft Tools 5 | ------------------------ 6 | 7 | This repository contains tools related to the Unikraft project. The code 8 | is published as a mixture of BSD and MIT licences; each C code file in 9 | this repository should declare who is the copyright owner and under which terms 10 | and conditions the code is licensed. If such a licence note is missing, the 11 | following copyright notice will apply: 12 | 13 | Copyright (c) 2019, NEC Europe Ltd., NEC Corporation. All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions 17 | are met: 18 | 19 | 1. Redistributions of source code must retain the above copyright 20 | notice, this list of conditions and the following disclaimer. 21 | 2. Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in the 23 | documentation and/or other materials provided with the distribution. 24 | 3. Neither the name of the copyright holder nor the names of its 25 | contributors may be used to endorse or promote products derived from 26 | this software without specific prior written permission. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 29 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 32 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | POSSIBILITY OF SUCH DAMAGE. 39 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | Maintainers List 2 | ================ 3 | 4 | For notes on how to read this information, please refer to `MAINTAINERS.md` in 5 | the main Unikraft repository. 6 | 7 | KRAFT-UNIKRAFT 8 | M: Felipe Huici 9 | M: Alexander Jung 10 | M: Gaulthier Gain 11 | M: Mujahid Ali 12 | L: minios-devel@lists.xen.org 13 | F: * 14 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | # Manifest syntax https://docs.python.org/2/distutils/sourcedist.html 2 | graft kraft 3 | 4 | recursive-exclude __pycache__ *.pyc *.pyo *.orig *.un~ 5 | 6 | exclude *.js* 7 | exclude *.git* 8 | exclude *.coveragerc 9 | exclude *.sh 10 | exclude proc* 11 | exclude pylint* 12 | 13 | include *.md 14 | include README.md 15 | include requirements*.* 16 | exclude requirements-dev.* 17 | include *.py 18 | 19 | include kraft/config/*.json 20 | include kraft/.kraftrc 21 | 22 | prune .git 23 | prune venv 24 | prune test* 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Project no longer maintained 2 | 3 | | :warning: | To begin using [Unikraft](https://unikraft.org) please refer to [KraftKit](https://github.com/unikraft/kraftkit) which is the companion tool used for defining, configuring, building, and running Unikraft applications. | 4 | |-|:-| 5 | | | This project will be renamed to https://github.com/unikraft/pykraft.git on February 1st 2023. | 6 | 7 | ## pykraft: Python3 Bindings for Unikraft 8 | 9 | The `pykraft` python library aids in building unikernels systematically. It requires the following dependencies (for Debian-based systems): 10 | 11 | apt-get install -y --no-install-recommends build-essential libncurses-dev libyaml-dev flex git wget socat bison unzip uuid-runtime; 12 | 13 | Note: Ubuntu 20.04 users may suffer from issue [#29](https://github.com/unikraft/kraft/issues/29) due to this [bug](https://bugs.launchpad.net/ubuntu/+source/socat/+bug/1883957) of `socat-1.7.3.3`. If you are using Ubuntu 20.04, please make sure to compile and install the latest version of `socat` retrieved from [this page](http://www.dest-unreach.org/socat/download/). 14 | 15 | To install simply run: 16 | 17 | pip3 install git+https://github.com/unikraft/kraft.git@staging 18 | 19 | ## Building an Application 20 | 21 | The simplest way to build a unikernel is to pass in an application directory to [`Application.from_workdir`](https://github.com/unikraft/kraft/blob/staging/kraft/app/app.py#L156): 22 | 23 | ```python 24 | from kraft.app import Application 25 | 26 | app = Application.from_workdir(workdir) 27 | 28 | if not app.is_configured(): 29 | app.configure() 30 | 31 | app.fetch() 32 | app.prepare() 33 | app.build() 34 | ```` 35 | 36 | ## License 37 | 38 | Pykraft is part of the [Unikraft OSS Project](https://unikraft.org) and licensed under BSD-3-Clause. 39 | -------------------------------------------------------------------------------- /kraft/.kraftrc: -------------------------------------------------------------------------------- 1 | [fetch] 2 | prioritize_origin = false 3 | mirrors = [ 4 | "https://releases.unikraft.org/mirrors", 5 | ] 6 | 7 | [configure] 8 | platform = "kvm" 9 | architecture = "x86_64" 10 | 11 | [list] 12 | origins = [ 13 | "https://github.com/unikraft/unikraft.git", 14 | "https://github.com/unikraft/plat-*", 15 | "https://github.com/unikraft/app-*", 16 | "https://github.com/unikraft/lib-*", 17 | ] 18 | -------------------------------------------------------------------------------- /kraft/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Laboraties Europe GmbH.,NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from pkg_resources import DistributionNotFound 36 | from pkg_resources import get_distribution 37 | 38 | 39 | __package__ = 'unikraft-tools' 40 | __program__ = 'kraft' 41 | __version__ = 'unset' 42 | __description__ = ''' 43 | Define, configure, build and run unikernel applications. 44 | ''' 45 | __all__ = [ 46 | 'kraft' 47 | ] 48 | 49 | try: 50 | __version__ = get_distribution(__package__).version 51 | except DistributionNotFound: 52 | pass # package is not installed 53 | -------------------------------------------------------------------------------- /kraft/app/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # flake8: noqa 33 | from __future__ import absolute_import 34 | from __future__ import unicode_literals 35 | 36 | from .app import Application 37 | -------------------------------------------------------------------------------- /kraft/arch/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .arch import Architecture # noqa: F401 36 | from .arch import ArchitectureManager # noqa: F401 37 | from .arch import InternalArchitecture # noqa: F401 38 | -------------------------------------------------------------------------------- /kraft/cache.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import threading 36 | 37 | import six 38 | from fcache.cache import FileCache 39 | 40 | from kraft import __program__ 41 | from kraft.logger import logger 42 | from kraft.manifest import Manifest 43 | 44 | 45 | class Cache(object): 46 | _cache = {} 47 | _cachedir = None 48 | _cache_lock = None 49 | @property 50 | def cache_lock(self): return self._cache_lock 51 | 52 | def __init__(self, environment): 53 | """ 54 | Initializes the cache so that kraft does not have to constantly 55 | retrieve informational lists about unikraft, its available 56 | architectures, platforms, libraries and supported applications. 57 | """ 58 | 59 | self._cachedir = environment.get('UK_CACHEDIR') 60 | 61 | # Initiaize a cache instance 62 | self._cache = FileCache( 63 | app_cache_dir=self._cachedir, 64 | appname=__program__, 65 | flag='cs' 66 | ) 67 | 68 | self._cache_lock = threading.Lock() 69 | 70 | @property 71 | def cache(self): 72 | ret = None 73 | with self._cache_lock: 74 | ret = self._cache 75 | return ret 76 | 77 | def get(self, origin=None): 78 | ret = None 79 | if isinstance(origin, six.string_types) and origin in self._cache: 80 | logger.debug("Retrieving %s from cache..." % origin) 81 | with self._cache_lock: 82 | ret = self._cache[origin] 83 | 84 | return ret 85 | 86 | def find_item_by_name(self, type=None, name=None): 87 | for origin in self._cache: 88 | for item in self._cache[origin].items(): 89 | if ((type is not None and item[1].type.shortname == type) 90 | or type is None) and item[1].name == name: 91 | return item[1] 92 | 93 | return None 94 | 95 | def all(self): 96 | return self.cache 97 | 98 | def save(self, origin, manifest): 99 | if not isinstance(origin, six.string_types): 100 | raise TypeError("origin is not string") 101 | if not isinstance(manifest, Manifest): 102 | raise TypeError("Invalid manifest") 103 | 104 | with self._cache_lock: 105 | logger.debug("Saving %s into cache..." % manifest) 106 | self._cache[origin] = manifest 107 | 108 | def sync(self): 109 | logger.debug("Synchronizing cache with filesystem...") 110 | 111 | with self._cache_lock: 112 | self._cache.sync() 113 | 114 | def purge(self): 115 | logger.debug("Purging cache...") 116 | 117 | with self._cache_lock: 118 | self._cache.clear() 119 | 120 | def is_stale(self): 121 | """ 122 | Determine if the list of remote repositories is stale. Return a boolean 123 | value if at least one repository is marked as stale. 124 | """ 125 | 126 | logger.debug("Checking cache for staleness...") 127 | return True if len(self.all()) == 0 else False 128 | -------------------------------------------------------------------------------- /kraft/cmd/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # flake8: noqa 33 | from __future__ import absolute_import 34 | from __future__ import unicode_literals 35 | 36 | from .build import cmd_build 37 | from .clean import cmd_clean 38 | from .configure import cmd_configure 39 | from .fetch import cmd_fetch 40 | from .init import cmd_init 41 | from .lib import cmd_lib_bump 42 | from .lib import cmd_lib_init 43 | from .lib import grp_lib 44 | from .list import cmd_list 45 | from .list import cmd_list_add 46 | from .list import cmd_list_pull 47 | from .list import cmd_list_remove 48 | from .list import cmd_list_update 49 | from .menuconfig import cmd_menuconfig 50 | from .prepare import cmd_prepare 51 | from .run import cmd_run 52 | from .up import cmd_up 53 | -------------------------------------------------------------------------------- /kraft/cmd/clean.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | import sys 37 | 38 | import click 39 | 40 | from kraft.app import Application 41 | from kraft.logger import logger 42 | from kraft.util import make_progressbar 43 | 44 | 45 | @click.command('clean', short_help='Clean the application.') 46 | @click.option( 47 | '--workdir', '-w', 'workdir', 48 | help='Specify an alternative working directory for the application', 49 | metavar="PATH" 50 | ) 51 | @click.option( 52 | '--proper', '-p', 'proper', 53 | help='Delete the build directory.', 54 | is_flag=True, 55 | ) 56 | @click.option( 57 | '--dist', '-d', 'dist', 58 | help='Delete the build directory and configuration files.', 59 | is_flag=True, 60 | ) 61 | @click.option( 62 | '--progress/--no-progress', 'progress', 63 | help='Show progress of build.', 64 | default=True 65 | ) 66 | @click.argument('libs', nargs=-1) 67 | @click.pass_context 68 | def cmd_clean(ctx, workdir=None, proper=False, dist=False, progress=True, 69 | libs=None): 70 | """ 71 | Clean the build artifacts of a Unikraft unikernel application. 72 | """ 73 | 74 | if workdir is None: 75 | workdir = ctx.obj.workdir 76 | 77 | try: 78 | kraft_clean( 79 | workdir=workdir, 80 | proper=proper, 81 | dist=dist, 82 | progress=progress, 83 | libs=libs, 84 | ) 85 | 86 | except Exception as e: 87 | logger.critical(str(e)) 88 | 89 | if ctx.obj.verbose: 90 | import traceback 91 | logger.critical(traceback.format_exc()) 92 | 93 | sys.exit(1) 94 | 95 | 96 | @click.pass_context 97 | def kraft_clean(ctx, workdir=None, proper=False, dist=False, progress=True, 98 | libs=None): 99 | """ 100 | Cleans the build artifacts of a Unikraft unikernel. 101 | """ 102 | 103 | if workdir is None or os.path.exists(workdir) is False: 104 | raise ValueError("working directory is empty: %s" % workdir) 105 | 106 | logger.debug("Cleaning %s..." % workdir) 107 | 108 | app = Application.from_workdir(workdir) 109 | 110 | if progress: 111 | if proper: 112 | make_progressbar(app.make_raw( 113 | extra="properclean" 114 | )) 115 | 116 | elif dist: 117 | make_progressbar(app.make_raw( 118 | extra="distclean" 119 | )) 120 | 121 | else: 122 | if len(libs) is not None and len(libs) > 0: 123 | for lib in list(libs): 124 | make_progressbar(app.make_raw( 125 | extra="clean-lib%s" % lib 126 | )) 127 | 128 | else: 129 | make_progressbar(app.make_raw( 130 | extra="clean" 131 | )) 132 | 133 | else: 134 | app.clean( 135 | proper=proper, 136 | dist=dist 137 | ) 138 | -------------------------------------------------------------------------------- /kraft/cmd/fetch.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | import sys 37 | 38 | import click 39 | 40 | from kraft.app import Application 41 | from kraft.cmd.list import kraft_list_preflight 42 | from kraft.logger import logger 43 | 44 | 45 | @click.pass_context 46 | def kraft_fetch(ctx, workdir=None): 47 | """ 48 | """ 49 | if workdir is None or os.path.exists(workdir) is False: 50 | raise ValueError("working directory is empty: %s" % workdir) 51 | 52 | logger.debug("Fetching for %s..." % workdir) 53 | 54 | app = Application.from_workdir(workdir) 55 | 56 | if not app.is_configured(): 57 | if click.confirm('It appears you have not configured your application. Would you like to do this now?', default=True): # noqa: E501 58 | app.configure() 59 | 60 | app.fetch() 61 | 62 | 63 | @click.command('fetch', short_help='Fetch library dependencies.') 64 | @click.pass_context 65 | def cmd_fetch(ctx): 66 | """ 67 | Fetches 68 | """ 69 | 70 | kraft_list_preflight() 71 | 72 | try: 73 | kraft_fetch( 74 | workdir=ctx.obj.workdir 75 | ) 76 | 77 | except Exception as e: 78 | logger.critical(str(e)) 79 | 80 | if ctx.obj.verbose: 81 | import traceback 82 | logger.critical(traceback.format_exc()) 83 | 84 | sys.exit(1) 85 | -------------------------------------------------------------------------------- /kraft/cmd/lib/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import click 36 | 37 | from .add import cmd_lib_add 38 | from .bump import cmd_lib_bump 39 | from .init import cmd_lib_init 40 | from .remove import cmd_lib_remove 41 | 42 | 43 | @click.group(name='lib', short_help='Unikraft library commands.') 44 | @click.pass_context 45 | def grp_lib(ctx): 46 | """ 47 | Unikraft library sub-commands are useful for maintaining and working 48 | directly with Unikraft libraries. 49 | """ 50 | pass 51 | 52 | 53 | grp_lib.add_command(cmd_lib_bump) 54 | grp_lib.add_command(cmd_lib_init) 55 | grp_lib.add_command(cmd_lib_add) 56 | grp_lib.add_command(cmd_lib_remove) 57 | -------------------------------------------------------------------------------- /kraft/cmd/lib/add.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | import sys 37 | 38 | import click 39 | 40 | from kraft.app import Application 41 | from kraft.cmd.list import kraft_list_pull 42 | from kraft.logger import logger 43 | 44 | 45 | @click.pass_context 46 | def kraft_lib_add(ctx, workdir=None, lib=None): 47 | if workdir is None or os.path.exists(workdir) is False: 48 | raise ValueError("working directory is empty: %s" % workdir) 49 | 50 | if isinstance(lib, tuple): 51 | lib = list(lib) 52 | 53 | if isinstance(lib, list): 54 | for l in lib: # noqa: E741 55 | if not kraft_lib_add(workdir, l): 56 | return False 57 | return True 58 | 59 | app = Application.from_workdir( 60 | workdir, 61 | force_init=True, 62 | use_versions=[lib] # override version if already present 63 | ) 64 | return app.add_lib(lib) 65 | 66 | 67 | @click.command('add', short_help='Add a library to the project.') 68 | @click.option( 69 | '--workdir', '-w', 'workdir', 70 | help='Specify an alternative directory for the application [default is cwd].', 71 | metavar="PATH" 72 | ) 73 | @click.option( 74 | '--pull/--no-pull', 'pull', 75 | help='Save libraries into project directory.', 76 | default=True, 77 | ) 78 | @click.argument('lib', required=False, nargs=-1) 79 | @click.pass_context 80 | def cmd_lib_add(ctx, workdir=None, lib=None, pull=False): 81 | """ 82 | Add a library to the unikraft application project. 83 | """ 84 | 85 | if workdir is None: 86 | workdir = os.getcwd() 87 | 88 | try: 89 | if pull: 90 | kraft_list_pull( 91 | name=lib 92 | ) 93 | 94 | if not kraft_lib_add(workdir=workdir, lib=lib): 95 | sys.exit(1) 96 | 97 | except Exception as e: 98 | if ctx.obj.verbose: 99 | import traceback 100 | logger.critical(traceback.format_exc()) 101 | else: 102 | logger.critical(str(e)) 103 | 104 | sys.exit(1) 105 | -------------------------------------------------------------------------------- /kraft/cmd/lib/remove.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2021, Lancaster University. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | from __future__ import absolute_import 32 | from __future__ import unicode_literals 33 | 34 | import os 35 | import sys 36 | 37 | import click 38 | 39 | from kraft.app import Application 40 | from kraft.logger import logger 41 | 42 | 43 | @click.pass_context 44 | def kraft_lib_remove(ctx, workdir=None, lib=None, purge=False): 45 | if workdir is None or os.path.exists(workdir) is False: 46 | raise ValueError("working directory is empty: %s" % workdir) 47 | 48 | if isinstance(lib, tuple): 49 | lib = list(lib) 50 | 51 | if isinstance(lib, list): 52 | for l in lib: # noqa: E741 53 | if not kraft_lib_remove(workdir, l, purge): 54 | return False 55 | return True 56 | 57 | app = Application.from_workdir( 58 | workdir, 59 | force_init=True, 60 | use_versions=[lib] # override version if already present 61 | ) 62 | 63 | return app.remove_lib(lib, purge=purge) 64 | 65 | 66 | @click.command('remove', short_help='Remove a library from the project.') 67 | @click.option( 68 | '--workdir', '-w', 'workdir', 69 | help='Specify an alternative directory for the application [default is cwd].', 70 | metavar="PATH" 71 | ) 72 | @click.option( 73 | '--purge', '-P', 'purge', 74 | help='Removes the source files for the library.', 75 | is_flag=True, 76 | ) 77 | @click.argument('lib', required=False, nargs=-1) 78 | @click.pass_context 79 | def cmd_lib_remove(ctx, workdir=None, lib=None, purge=False): 80 | """ 81 | Remove a library from the unikraft application project. 82 | """ 83 | 84 | if workdir is None: 85 | workdir = os.getcwd() 86 | 87 | try: 88 | if not kraft_lib_remove(workdir=workdir, lib=lib, purge=purge): 89 | sys.exit(1) 90 | 91 | except Exception as e: 92 | if ctx.obj.verbose: 93 | import traceback 94 | logger.critical(traceback.format_exc()) 95 | else: 96 | logger.critical(str(e)) 97 | 98 | sys.exit(1) 99 | -------------------------------------------------------------------------------- /kraft/cmd/list/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # flake8: noqa 33 | from __future__ import absolute_import 34 | from __future__ import unicode_literals 35 | 36 | from .add import cmd_list_add 37 | from .list import cmd_list 38 | from .list import kraft_list_preflight 39 | from .pull import cmd_list_pull 40 | from .pull import kraft_download_component 41 | from .pull import kraft_list_pull 42 | from .remove import cmd_list_remove 43 | from .show import cmd_list_show 44 | from .update import cmd_list_update 45 | from kraft.manifest import Manifest 46 | from kraft.manifest import ManifestIndex 47 | from kraft.manifest import ManifestItem 48 | from kraft.manifest import ManifestItemDistribution 49 | from kraft.manifest import ManifestItemVersion 50 | 51 | 52 | cmd_list.add_command(cmd_list_add) 53 | cmd_list.add_command(cmd_list_remove) 54 | cmd_list.add_command(cmd_list_pull) 55 | cmd_list.add_command(cmd_list_update) 56 | cmd_list.add_command(cmd_list_show) 57 | -------------------------------------------------------------------------------- /kraft/cmd/list/add.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | import sys 37 | from urllib.parse import urlparse 38 | 39 | import click 40 | 41 | from kraft.cmd.list.update import kraft_update 42 | from kraft.const import KRAFTRC_LIST_ORIGINS 43 | from kraft.logger import logger 44 | 45 | 46 | @click.pass_context 47 | def kraft_list_add(ctx, origin=None, update=False): 48 | """ 49 | """ 50 | if isinstance(origin, list): 51 | for o in origin: 52 | kraft_list_add(o, update=update) 53 | return 54 | 55 | existing_origins = ctx.obj.settings.get(KRAFTRC_LIST_ORIGINS) 56 | if existing_origins is None: 57 | existing_origins = list() 58 | 59 | new_uri = urlparse(origin) 60 | 61 | if os.path.exists(origin): 62 | origin = os.path.abspath(origin) 63 | 64 | for o in existing_origins: 65 | cur_uri = urlparse(o) 66 | if (o == origin 67 | or (new_uri.netloc == cur_uri.netloc 68 | and new_uri.path == cur_uri.path)): 69 | logger.warning("Origin already saved: %s" % o) 70 | return 71 | 72 | existing_origins.append(origin) 73 | ctx.obj.settings.set(KRAFTRC_LIST_ORIGINS, existing_origins) 74 | logger.info("Saved: %s" % origin) 75 | 76 | if update: 77 | with ctx: 78 | kraft_update(origin) 79 | 80 | 81 | @click.command('add', short_help='Add a remote manifest or repository.') 82 | @click.option( 83 | '--update/--no-update', 'update', 84 | help='Update the list of known remote components.', 85 | default=False 86 | ) 87 | @click.argument('origin', nargs=-1) 88 | @click.pass_context 89 | def cmd_list_add(ctx, update=False, origin=None): 90 | """ 91 | Add a remote repository to search for components. 92 | """ 93 | 94 | try: 95 | kraft_list_add(list(origin), update=update) 96 | 97 | except Exception as e: 98 | logger.critical(str(e)) 99 | 100 | if ctx.obj.verbose: 101 | import traceback 102 | logger.critical(traceback.format_exc()) 103 | 104 | sys.exit(1) 105 | -------------------------------------------------------------------------------- /kraft/cmd/list/provider/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # flake8: noqa 33 | from __future__ import absolute_import 34 | from __future__ import unicode_literals 35 | 36 | from enum import Enum 37 | 38 | from .git import GitListProvider 39 | from .github import GitHubListProvider 40 | from .provider import ListProvider 41 | -------------------------------------------------------------------------------- /kraft/cmd/list/provider/provider.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # flake8: noqa 33 | from __future__ import absolute_import 34 | from __future__ import unicode_literals 35 | 36 | import click 37 | 38 | from kraft.logger import logger 39 | 40 | 41 | class ListProvider(object): 42 | @classmethod 43 | def is_type(cls, origin=None): 44 | logger.warning("%s did not replace is_type()" % 45 | cls.__name__) 46 | return False 47 | 48 | @click.pass_context 49 | def probe(ctx, self, origin=None, items=None, return_threads=False): 50 | logger.warning("%s did not replace probe()" % 51 | self.__class__.__name__) 52 | return None, None 53 | 54 | @click.pass_context 55 | def download(ctx, self, manifest=None, localdir=None, version=None, 56 | override_existing=False, **kwargs): 57 | logger.warning("%s did not replace download()" % 58 | self.__class__.__name__) 59 | -------------------------------------------------------------------------------- /kraft/cmd/list/provider/types.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # flake8: noqa 33 | from __future__ import absolute_import 34 | from __future__ import unicode_literals 35 | 36 | from enum import Enum 37 | 38 | from .git import GitListProvider 39 | from .github import GitHubListProvider 40 | from .tarball import TarballListProvider 41 | 42 | 43 | class ListProviderType(Enum): 44 | GITHUB = ("github" , GitHubListProvider) # noqa 45 | GIT = ("git" , GitListProvider) # noqa 46 | TARBALL = ("tarball" , TarballListProvider) # noqa 47 | 48 | @property 49 | def name(self): 50 | return self.value[0] 51 | 52 | @property 53 | def cls(self): 54 | return self.value[1] 55 | 56 | def is_type(self, origin=None): 57 | return self.value[1].is_type(origin) 58 | 59 | 60 | def provider_name_to_enum(name=None): 61 | if name is None: 62 | return None 63 | 64 | for _, p in ListProviderType.__members__.items(): 65 | if p.name == name: 66 | return p 67 | -------------------------------------------------------------------------------- /kraft/cmd/list/remove.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | import sys 37 | from urllib.parse import urlparse 38 | 39 | import click 40 | 41 | from kraft.const import KRAFTRC_LIST_ORIGINS 42 | from kraft.logger import logger 43 | 44 | 45 | @click.pass_context 46 | def kraft_list_remove(ctx, origin=None): 47 | """ 48 | """ 49 | if isinstance(origin, list): 50 | for o in origin: 51 | kraft_list_remove(o) 52 | return 53 | 54 | existing_origins = ctx.obj.settings.get(KRAFTRC_LIST_ORIGINS) 55 | if existing_origins is None: 56 | existing_origins = list() 57 | 58 | new_uri = urlparse(origin) 59 | 60 | if os.path.exists(origin): 61 | origin = os.path.abspath(origin) 62 | 63 | for i, o in enumerate(existing_origins): 64 | cur_uri = urlparse(o) 65 | if (o == origin 66 | or (new_uri.netloc == cur_uri.netloc 67 | and new_uri.path == cur_uri.path)): 68 | logger.info("Removed: %s" % origin) 69 | del existing_origins[i] 70 | break 71 | 72 | ctx.obj.settings.set(KRAFTRC_LIST_ORIGINS, existing_origins) 73 | 74 | 75 | @click.command('remove', short_help='Remove a remote manifest or repository.') 76 | @click.argument('origin', nargs=-1) 77 | @click.pass_context 78 | def cmd_list_remove(ctx, origin=None): 79 | """ 80 | Remove a remote repository to search for components. 81 | """ 82 | 83 | try: 84 | kraft_list_remove(list(origin)) 85 | 86 | except Exception as e: 87 | logger.critical(str(e)) 88 | 89 | if ctx.obj.verbose: 90 | import traceback 91 | logger.critical(traceback.format_exc()) 92 | 93 | sys.exit(1) 94 | -------------------------------------------------------------------------------- /kraft/cmd/menuconfig.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2021, Lancaster University. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | import sys 37 | 38 | import click 39 | 40 | from kraft.app import Application 41 | from kraft.logger import logger 42 | 43 | 44 | @click.command('menuconfig', short_help='Open the KConfig Menu editor') 45 | @click.option( 46 | '--workdir', '-w', 'workdir', 47 | help='Specify an alternative directory for the application [default is cwd].', 48 | metavar="PATH" 49 | ) 50 | @click.pass_context 51 | def cmd_menuconfig(ctx, workdir=None): 52 | """ 53 | Opens the KConfig Menuconfig program for the selected application. 54 | """ 55 | 56 | if not sys.stdout.isatty(): 57 | logger.critical("Cannot open menuconfig in non-TTY environment") 58 | return 59 | 60 | if workdir is None: 61 | workdir = os.getcwd() 62 | 63 | try: 64 | app = Application.from_workdir(workdir) 65 | app.open_menuconfig() 66 | return 67 | 68 | except Exception as e: 69 | logger.critical(str(e)) 70 | 71 | if ctx.obj.verbose: 72 | import traceback 73 | logger.critical(traceback.format_exc()) 74 | 75 | sys.exit(1) 76 | -------------------------------------------------------------------------------- /kraft/cmd/prepare.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | import sys 37 | 38 | import click 39 | 40 | from kraft.app import Application 41 | from kraft.cmd.list import kraft_list_preflight 42 | from kraft.logger import logger 43 | 44 | 45 | @click.pass_context 46 | def kraft_prepare(ctx, workdir=None): 47 | """ 48 | """ 49 | if workdir is None or os.path.exists(workdir) is False: 50 | raise ValueError("working directory is empty: %s" % workdir) 51 | 52 | logger.debug("Preparing %s..." % workdir) 53 | 54 | app = Application.from_workdir(workdir) 55 | 56 | if not app.is_configured(): 57 | if click.confirm('It appears you have not configured your application. Would you like to do this now?', default=True): # noqa: E501 58 | app.configure() 59 | 60 | app.prepare() 61 | 62 | 63 | @click.command('prepare', short_help='Runs preparations steps on libraries.') 64 | @click.pass_context 65 | def cmd_prepare(ctx): 66 | """ 67 | Prepares 68 | """ 69 | 70 | kraft_list_preflight() 71 | 72 | try: 73 | kraft_prepare( 74 | workdir=ctx.obj.workdir 75 | ) 76 | 77 | except Exception as e: 78 | logger.critical(str(e)) 79 | 80 | if ctx.obj.verbose: 81 | import traceback 82 | logger.critical(traceback.format_exc()) 83 | 84 | sys.exit(1) 85 | -------------------------------------------------------------------------------- /kraft/config/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # flake8: noqa 33 | from __future__ import absolute_import 34 | from __future__ import unicode_literals 35 | 36 | from .config import Config 37 | from .config import find_config 38 | from .config import load_config 39 | from .version import SpecificationVersion 40 | -------------------------------------------------------------------------------- /kraft/config/serialize.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | from __future__ import absolute_import 32 | from __future__ import unicode_literals 33 | 34 | import io 35 | 36 | import six 37 | from ruamel.yaml import YAML 38 | 39 | from kraft.config import Config 40 | from kraft.manifest import ManifestItemVersion 41 | 42 | 43 | def serialize_config_type(dumper, data): 44 | representer = dumper.represent_str if six.PY3 else dumper.represent_unicode 45 | return representer(data.repr()) 46 | 47 | 48 | def serialize_dict_type(dumper, data): 49 | return dumper.represent_dict(data.repr()) 50 | 51 | 52 | def serialize_string(dumper, data): 53 | """ Ensure boolean-like strings are quoted in the output """ 54 | representer = dumper.represent_str if six.PY3 else dumper.represent_unicode 55 | 56 | if isinstance(data, six.binary_type): 57 | data = data.decode('utf-8') 58 | 59 | if data.lower() in ('y', 'n', 'yes', 'no', 'on', 'off', 'true', 'false'): 60 | # Empirically only y/n appears to be an issue, but this might change 61 | # depending on which PyYaml version is being used. Err on safe side. 62 | return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='"') 63 | return representer(data) 64 | 65 | 66 | def serialize_string_escape_dollar(dumper, data): 67 | """ Ensure boolean-like strings are quoted in the output and escape $ characters """ 68 | data = data.replace('$', '$$') 69 | return serialize_string(dumper, data) 70 | 71 | 72 | def serialize_config(config, escape_dollar=False, original=None): 73 | yaml = YAML(typ='rt') 74 | 75 | if escape_dollar: 76 | yaml.representer.add_representer(str, serialize_string_escape_dollar) 77 | yaml.representer.add_representer(six.text_type, serialize_string_escape_dollar) 78 | else: 79 | yaml.representer.add_representer(str, serialize_string) 80 | yaml.representer.add_representer(six.text_type, serialize_string) 81 | 82 | yaml.representer.add_representer(Config, serialize_dict_type) 83 | yaml.representer.add_representer(ManifestItemVersion, serialize_dict_type) 84 | 85 | yaml.default_flow_style = False 86 | yaml.sort_keys = False 87 | yaml.preserve_quotes = True 88 | yaml.explicit_start = True 89 | yaml.sort_base_mapping_type_on_output = False 90 | yaml.indent(mapping=2, sequence=4, offset=2) 91 | 92 | ret = io.StringIO("") 93 | yaml.dump( 94 | config, 95 | ret 96 | ) 97 | return ret.getvalue() 98 | -------------------------------------------------------------------------------- /kraft/config/types.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | from __future__ import absolute_import 32 | from __future__ import unicode_literals 33 | 34 | from collections import namedtuple 35 | 36 | import six 37 | 38 | 39 | class ComponentConfigBase(namedtuple( 40 | '_ComponentConfigBase', [ 41 | 'source', 42 | 'version', 43 | 'kconfig' 44 | ])): 45 | 46 | @classmethod 47 | def parse(cls, spec): 48 | if isinstance(spec, six.string_types): 49 | return cls(spec, None, None, None, None, None) 50 | return cls( 51 | spec.get('source'), 52 | spec.get('version'), 53 | spec.get('kconfig') 54 | ) 55 | 56 | @property 57 | def merge_field(self): 58 | return self.source 59 | 60 | def repr(self): 61 | return dict( 62 | [(k, v) for k, v in zip(self._fields, self) if v is not None] 63 | ) 64 | 65 | 66 | class UnikraftConfig(ComponentConfigBase): 67 | pass 68 | 69 | 70 | class ArchitectureConfig(ComponentConfigBase): 71 | pass 72 | 73 | 74 | class PlatformConfig(ComponentConfigBase): 75 | pass 76 | 77 | 78 | class LibraryConfig(ComponentConfigBase): 79 | pass 80 | 81 | 82 | class RunnerConfig(object): 83 | pass 84 | -------------------------------------------------------------------------------- /kraft/config/version.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | from __future__ import absolute_import 32 | from __future__ import unicode_literals 33 | 34 | from distutils.version import LooseVersion 35 | 36 | 37 | class SpecificationVersion(LooseVersion): 38 | """ A hashable version object """ 39 | def __hash__(self): 40 | return hash(self.vstring) 41 | 42 | def repr(self): 43 | return str(self.vstring) 44 | -------------------------------------------------------------------------------- /kraft/kraft.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Laboratories Europe GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import click 36 | 37 | from kraft.cmd import cmd_build 38 | from kraft.cmd import cmd_clean 39 | from kraft.cmd import cmd_configure 40 | from kraft.cmd import cmd_fetch 41 | from kraft.cmd import cmd_init 42 | from kraft.cmd import cmd_list 43 | from kraft.cmd import cmd_menuconfig 44 | from kraft.cmd import cmd_prepare 45 | from kraft.cmd import cmd_run 46 | from kraft.cmd import cmd_up 47 | from kraft.cmd import grp_lib 48 | from kraft.context import KraftContext 49 | from kraft.logger import logger 50 | from kraft.util.cli import CONTEXT_SETTINGS 51 | from kraft.util.cli import KraftHelpGroup 52 | 53 | 54 | @click.option( 55 | '--verbose', '-v', 'verbose', 56 | help='Enables verbose mode.', is_flag=True 57 | ) 58 | @click.option( 59 | '--yes', '-Y', 'assume_yes', 60 | help='Assume yes to any binary prompts.', 61 | is_flag=True 62 | ) 63 | @click.option( 64 | '--timestamps', '-T', 'use_timestamps', 65 | help='Show timestamps in output logs.', 66 | is_flag=True 67 | ) 68 | @click.option( 69 | '--no-color', '-C', 'no_color', 70 | help='Do not use colour in output logs.', 71 | is_flag=True 72 | ) 73 | @click.group(cls=KraftHelpGroup, context_settings=CONTEXT_SETTINGS, epilog=""" 74 | Influential Environmental Variables: 75 | env::UK_WORKDIR The working directory for all Unikraft 76 | source code [default: ~/.unikraft] 77 | env::UK_ROOT The directory for Unikraft's core source 78 | code [default: $UK_WORKDIR/unikraft] 79 | env::UK_LIBS The directory of all the external Unikraft 80 | libraries [default: $UK_WORKDIR/libs] 81 | env::UK_APPS The directory of all the template applications 82 | [default: $UK_WORKDIR/apps] 83 | env::KRAFTRC The location of kraft's preferences file 84 | [default: ~/.kraftrc] 85 | 86 | Help: 87 | For help using this tool, please open an issue on Github: 88 | https://github.com/unikraft/kraft 89 | """) 90 | @click.version_option() 91 | @click.pass_context 92 | def kraft(ctx, verbose=False, assume_yes=False, use_timestamps=False, 93 | no_color=False): 94 | logger.use_timestamps = use_timestamps 95 | logger.use_color = not no_color 96 | 97 | ctx.obj = KraftContext( 98 | verbose=verbose, 99 | assume_yes=assume_yes 100 | ) 101 | 102 | ctx.obj.cache.sync() 103 | 104 | 105 | kraft.add_command(cmd_list) 106 | kraft.add_command(cmd_up) 107 | kraft.add_command(cmd_init) 108 | kraft.add_command(cmd_configure) 109 | kraft.add_command(cmd_menuconfig) 110 | kraft.add_command(cmd_fetch) 111 | kraft.add_command(cmd_prepare) 112 | kraft.add_command(cmd_build) 113 | kraft.add_command(cmd_run) 114 | kraft.add_command(cmd_clean) 115 | kraft.add_command(grp_lib) 116 | -------------------------------------------------------------------------------- /kraft/lib/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .lib import intrusively_determine_lib_origin_url # noqa: F401 36 | from .lib import intrusively_determine_lib_origin_version # noqa: F401 37 | from .lib import Library # noqa: F401 38 | from .lib import LibraryManager # noqa: F401 39 | -------------------------------------------------------------------------------- /kraft/lib/provider/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .types import determine_lib_provider # noqa: F401 36 | -------------------------------------------------------------------------------- /kraft/lib/provider/github.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | 37 | from .git import git_probe_remote_versions 38 | from .git import GitLibraryProvider 39 | from kraft.const import GITHUB_ORIGIN 40 | from kraft.const import REPO_VALID_URL_PREFIXES 41 | from kraft.const import TARBALL_SUPPORTED_EXTENSIONS 42 | # from git.cmd import Git as GitCmd 43 | 44 | 45 | def github_org_name(origin_url=None): 46 | for prefix in REPO_VALID_URL_PREFIXES: 47 | if origin_url.startswith(prefix): 48 | origin_url = origin_url[len(prefix):] 49 | 50 | github_parts = origin_url.split('/') 51 | 52 | return github_parts[1], github_parts[2] 53 | 54 | 55 | class GitHubLibraryProvider(GitLibraryProvider): 56 | 57 | @classmethod 58 | def is_type(cls, origin=None): 59 | if origin is None: 60 | return False 61 | 62 | if GITHUB_ORIGIN in origin: 63 | return True 64 | 65 | return False 66 | 67 | def probe_remote_versions(self, origin_url=None): 68 | if origin_url is None: 69 | origin_url = self._origin_url 70 | 71 | # Convert a archive URL to a git URL 72 | if origin_url.endswith(tuple(TARBALL_SUPPORTED_EXTENSIONS)): 73 | org, repo = github_org_name(origin_url) 74 | 75 | self._origin_url = origin_url = "https://%s/%s/%s.git" % ( 76 | GITHUB_ORIGIN, org, repo 77 | ) 78 | 79 | return git_probe_remote_versions(origin_url) 80 | 81 | def origin_url_with_varname(self, varname=None): 82 | if varname is None: 83 | return self.origin_url 84 | 85 | origin_url = self.origin_url 86 | 87 | org, repo = github_org_name(origin_url) 88 | 89 | if repo.endswith('.git'): 90 | repo = repo[:-4] 91 | 92 | return "https://github.com/%s/%s/archive/%s.zip" % (org, repo, varname) 93 | 94 | @property 95 | def origin_filename(self): 96 | return os.path.basename(self.origin_url_with_varname(self.origin_version)) 97 | -------------------------------------------------------------------------------- /kraft/lib/provider/provider.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | PROVIDER_STATUS_AVAILABLE = "available" 36 | PROVIDER_STATUS_OUTOFDATE = "outofdate" 37 | PROVIDER_STATUS_EMPTY = "empty" 38 | 39 | 40 | class LibraryProvider(object): 41 | _origin_url = None 42 | @property 43 | def origin_url(self): return self._origin_url 44 | 45 | _origin_version = None 46 | @property 47 | def origin_version(self): return self._origin_version 48 | 49 | def __init__(self, origin_url=None, origin_version=None): 50 | self._origin_url = origin_url 51 | self._origin_version = origin_version 52 | 53 | @classmethod 54 | def is_type(self): 55 | pass 56 | 57 | def probe_remote_versions(self, origin_url=None): 58 | return [] 59 | 60 | def origin_url_with_varname(self, varname=None): 61 | return self.origin_url 62 | 63 | @property 64 | def origin_filename(self): 65 | return None 66 | -------------------------------------------------------------------------------- /kraft/lib/provider/sourceforge.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import feedparser 36 | 37 | from .tarball import TarballLibraryProvider 38 | from kraft.const import SEMVER_PATTERN 39 | from kraft.const import SOURCEFORGE_DOWNLOAD 40 | from kraft.const import SOURCEFORGE_PROJECT_FEED 41 | from kraft.const import SOURCEFORGE_PROJECT_NAME 42 | from kraft.const import TARBALL_SUPPORTED_EXTENSIONS 43 | 44 | 45 | def sourceforge_probe_origin_versions(origin_url=None): 46 | """ 47 | List known versions of a project on SourceForge. 48 | 49 | Args: 50 | source: The remote source on SourceForge. 51 | 52 | Returns: 53 | Dictionary of versions and their url. 54 | 55 | """ 56 | versions = {} 57 | project_name = SOURCEFORGE_PROJECT_NAME.search(origin_url) 58 | 59 | if project_name is None: 60 | return versions 61 | 62 | project_name = project_name.group(1) 63 | feed = feedparser.parse(SOURCEFORGE_PROJECT_FEED % project_name) 64 | 65 | for entry in feed.entries: 66 | url_parts = entry.links[0].href 67 | 68 | if url_parts.endswith(SOURCEFORGE_DOWNLOAD): 69 | url_parts = url_parts[:-len(SOURCEFORGE_DOWNLOAD)] 70 | 71 | filename = url_parts.split('/')[-1] 72 | 73 | for suffix in TARBALL_SUPPORTED_EXTENSIONS: 74 | if filename.endswith(suffix): 75 | filename = filename[:-len(suffix)] 76 | 77 | semver = SEMVER_PATTERN.search(filename) 78 | if semver is not None: 79 | versions[semver.group(0)] = entry.links[0].href 80 | 81 | return versions 82 | 83 | 84 | class SourceForgeLibraryProvider(TarballLibraryProvider): 85 | 86 | @classmethod 87 | def is_type(cls, origin=None): 88 | if origin is None: 89 | return False 90 | 91 | if 'sourceforge.net' in origin: 92 | return True 93 | 94 | return False 95 | 96 | def probe_remote_versions(self, origin_url=None): 97 | if origin_url is None: 98 | origin_url = self.origin_url 99 | 100 | return sourceforge_probe_origin_versions(origin_url) 101 | 102 | def origin_url_with_varname(self, varname=None): 103 | return self.origin_url 104 | -------------------------------------------------------------------------------- /kraft/lib/provider/tarball.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import htmllistparse 36 | 37 | from .provider import LibraryProvider 38 | from kraft.const import SEMVER_PATTERN 39 | from kraft.const import TARBALL_SUPPORTED_EXTENSIONS 40 | from kraft.logger import logger 41 | 42 | 43 | def tarball_probe_origin_versions(origin_url=None): 44 | versions = {} 45 | 46 | if origin_url is None: 47 | return versions 48 | 49 | # Remove everything after the $ (start of variable) 50 | if '/$' in origin_url: 51 | origin_url = origin_url[:origin_url.index('$')] 52 | 53 | # Remove the filename 54 | else: 55 | for ext in TARBALL_SUPPORTED_EXTENSIONS: 56 | if origin_url.endswith(ext): 57 | filename = origin_url.split('/')[-1] 58 | origin_url = origin_url.replace(filename, '') 59 | break 60 | 61 | try: 62 | cwd, listings = htmllistparse.fetch_listing(origin_url, timeout=30) 63 | 64 | for listing in listings: 65 | if listing.name.endswith(tuple(TARBALL_SUPPORTED_EXTENSIONS)): 66 | ver = SEMVER_PATTERN.search(listing.name) 67 | if ver is not None and ver.group(0) not in versions.keys(): 68 | versions[ver.group(0)] = listing.name 69 | 70 | except Exception as e: 71 | logger.warn(e) 72 | pass 73 | 74 | print(versions) 75 | 76 | return versions 77 | 78 | 79 | class TarballLibraryProvider(LibraryProvider): 80 | @classmethod 81 | def is_type(cls, origin_url=None): 82 | if origin_url is None: 83 | return False 84 | 85 | for ext in TARBALL_SUPPORTED_EXTENSIONS: 86 | if origin_url.endswith(ext): 87 | return True 88 | 89 | return False 90 | 91 | def probe_remote_versions(self, origin_url=None): 92 | if origin_url is None: 93 | origin_url = self.origin_url 94 | 95 | return tarball_probe_origin_versions(origin_url) 96 | 97 | def origin_url_with_varname(self, varname=None): 98 | ver = SEMVER_PATTERN.search(self.origin_url) 99 | if ver is None: 100 | return None 101 | 102 | origin_url = self.origin_url.replace(ver.group(0), varname) 103 | return origin_url 104 | -------------------------------------------------------------------------------- /kraft/lib/provider/types.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from enum import Enum 36 | 37 | from .git import GitLibraryProvider 38 | from .github import GitHubLibraryProvider 39 | from .sourceforge import SourceForgeLibraryProvider 40 | from .tarball import TarballLibraryProvider 41 | 42 | 43 | def determine_lib_provider(origin_url=None): 44 | provider = None 45 | 46 | if origin_url is None: 47 | return provider 48 | 49 | for _, member in LibraryProviderType.__members__.items(): 50 | if member.is_type(origin_url): 51 | return member.cls 52 | 53 | return provider 54 | 55 | 56 | class LibraryProviderType(Enum): 57 | GITHUB = ("github" , GitHubLibraryProvider) # noqa 58 | GIT = ("git" , GitLibraryProvider) # noqa 59 | SOURCEFORGE = ("sourceforge", SourceForgeLibraryProvider) # noqa 60 | TARBALL = ("tarball" , TarballLibraryProvider) # noqa 61 | 62 | @property 63 | def name(self): 64 | return self.value[0] 65 | 66 | @property 67 | def cls(self): 68 | return self.value[1] 69 | 70 | def is_type(self, origin=None): 71 | return self.value[1].is_type(origin) 72 | 73 | def probe_remote_versions(self, origin=None): 74 | return self.value[1].probe_remote_versions(origin) 75 | -------------------------------------------------------------------------------- /kraft/logger.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import logging 36 | 37 | import click 38 | 39 | from kraft import __program__ 40 | 41 | TIME_FORMAT = "%(asctime)s " 42 | LEVEL_FORMAT = "%(levelname)-8s" 43 | MESSAGE_FORMAT = "%(message)s" 44 | LOGGING_COLORS = { 45 | 'WARNING': 'yellow', 46 | 'INFO': 'white', 47 | 'DEBUG': 'cyan', 48 | 'CRITICAL': 'red', 49 | 'ERROR': 'red' 50 | } 51 | 52 | 53 | class KraftFormatter(logging.Formatter): 54 | _use_color = False 55 | _logger = None 56 | 57 | def __init__(self, *args, **kwargs): 58 | self._logger = kwargs.get("logger") 59 | if self._logger is not None: 60 | del kwargs["logger"] 61 | 62 | logging.Formatter.__init__(self, *args, **kwargs) 63 | 64 | def format(self, record): 65 | fmt = "" 66 | 67 | if self._logger.use_timestamps: 68 | fmt += TIME_FORMAT 69 | 70 | fmt += "[" 71 | if self._logger.use_color: 72 | fmt += click.style(LEVEL_FORMAT, fg=LOGGING_COLORS[record.levelname]) 73 | else: 74 | fmt += LEVEL_FORMAT 75 | fmt += "] " 76 | 77 | fmt += MESSAGE_FORMAT 78 | 79 | self._style._fmt = fmt 80 | 81 | return logging.Formatter.format(self, record) 82 | 83 | 84 | class KraftLogger(logging.Logger): 85 | _use_timestamps = False 86 | @property 87 | def use_timestamps(self): return self._use_timestamps 88 | 89 | @use_timestamps.setter 90 | def use_timestamps(self, use_timestamps=False): 91 | self._use_timestamps = use_timestamps 92 | 93 | _use_color = True 94 | @property 95 | def use_color(self): return self._use_color 96 | 97 | @use_color.setter 98 | def use_color(self, use_color=False): 99 | self._use_color = use_color 100 | 101 | def __init__(self, name): 102 | logging.Logger.__init__(self, name, logging.ERROR) 103 | 104 | color_formatter = KraftFormatter( 105 | logger=self, 106 | datefmt="%Y-%m-%d %H:%M:%S" 107 | ) 108 | 109 | console = logging.StreamHandler() 110 | console.setFormatter(color_formatter) 111 | 112 | self.addHandler(console) 113 | 114 | 115 | logging.setLoggerClass(KraftLogger) 116 | logger = logging.getLogger(__program__) 117 | -------------------------------------------------------------------------------- /kraft/manifest/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Laboraties Europe GmbH.,NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .manifest import maniest_from_name # noqa: F401 36 | from .manifest import Manifest # noqa: F401 37 | from .manifest import manifest_from_localdir # noqa: F401 38 | from .manifest import ManifestIndex # noqa: F401 39 | from .manifest import ManifestItem # noqa: F401 40 | from .manifest import ManifestItemDistribution # noqa: F401 41 | from .manifest import ManifestItemVersion # noqa: F401 42 | from .manifest import ManifestVersionEquality # noqa: F401 43 | -------------------------------------------------------------------------------- /kraft/plat/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .plat import InternalPlatform # noqa: F401 36 | from .plat import Platform # noqa: F401 37 | from .plat import PlatformManager # noqa: F401 38 | from .runner import Runner # noqa: F401 39 | -------------------------------------------------------------------------------- /kraft/plat/network/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .driver import BRCTLDriver # noqa: F401 36 | from .driver import NetworkDriver # noqa: F401 37 | from .driver import NetworkDriverTypes # noqa: F401 38 | from .network import Network # noqa: F401 39 | from .network import NetworkManager # noqa: F401 40 | -------------------------------------------------------------------------------- /kraft/plat/network/driver/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .brctl import BRCTLDriver # noqa: F401 36 | from .driver import NetworkDriver # noqa: F401 37 | from .types import NetworkDriverTypes # noqa: F401 38 | -------------------------------------------------------------------------------- /kraft/plat/network/driver/brctl.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import subprocess 36 | from shutil import which 37 | 38 | import kraft.util as util 39 | from .driver import NetworkDriver 40 | from kraft.error import InvalidBridgeName 41 | from kraft.error import NetworkBridgeUnsupported 42 | from kraft.logger import logger 43 | 44 | BRCTL = "brctl" 45 | 46 | 47 | class BRCTLDriver(NetworkDriver): 48 | def __init__(self, name, type): 49 | super(BRCTLDriver, self).__init__(name, type) 50 | 51 | def integrity_ok(self): 52 | return which(BRCTL) is not None 53 | 54 | def create_bridge(self, name=None, dry_run=False): 55 | if not self.integrity_ok(): 56 | raise NetworkBridgeUnsupported(self.type.name) 57 | 58 | if name is None: 59 | name = self._name 60 | 61 | if self.bridge_exists(name): 62 | logger.warning("Bridge '%s' already exists!" % name) 63 | return True 64 | 65 | if name is not None and len(name) > 0: 66 | util.execute([ 67 | BRCTL, "addbr", name 68 | ], dry_run=dry_run) 69 | else: 70 | raise InvalidBridgeName(name) 71 | 72 | return True 73 | 74 | def destroy_bridge(self, name=None): 75 | if not self.integrity_ok(): 76 | raise NetworkBridgeUnsupported(self.type.name) 77 | 78 | if name is None: 79 | name = self.name 80 | 81 | if name is not None and len(name) > 0: 82 | util.execute([ 83 | BRCTL, "delbr", name 84 | ]) 85 | else: 86 | raise InvalidBridgeName(name) 87 | 88 | def bridge_exists(self, name=None): 89 | if not self.integrity_ok(): 90 | raise NetworkBridgeUnsupported(self.type.name) 91 | 92 | process = subprocess.Popen( 93 | [BRCTL, "show", name], 94 | stdout=subprocess.PIPE, 95 | stderr=subprocess.PIPE 96 | ) 97 | out, err = process.communicate() 98 | 99 | if err == b"can't get info No such device\n": 100 | return False 101 | elif "does not exist!" in err.decode('utf-8'): 102 | return False 103 | 104 | return True 105 | -------------------------------------------------------------------------------- /kraft/plat/network/driver/driver.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from kraft.error import KraftError 36 | from kraft.error import NetworkDriverError 37 | 38 | 39 | class NetworkDriver(object): 40 | _name = None 41 | _type = None 42 | 43 | @property 44 | def name(self): 45 | return self._name 46 | 47 | @property 48 | def type(self): 49 | return self._type 50 | 51 | def __init__(self, name=None, type=None): 52 | if name is not None: 53 | self._name = name 54 | else: 55 | self._name = NetworkDriver.generate_bridge_name() 56 | 57 | self._type = type 58 | 59 | def integrity_ok(self): 60 | return False 61 | 62 | def create_bridge(self, name=None, dry_run=False): 63 | raise NetworkDriverError( 64 | "Creating a bridge is not possible with driver %s" % self.type 65 | ) 66 | 67 | def add_vif(self, name=None): 68 | raise NetworkDriverError( 69 | "Adding an interface is not possible with driver %s" % self.type 70 | ) 71 | 72 | def remove_vif(self, name=None): 73 | raise NetworkDriverError( 74 | "Removing an interface is not possible with driver %s" % self.type 75 | ) 76 | 77 | def destroy_bridge(self, name=None): 78 | raise NetworkDriverError( 79 | "Removing a bridge is not possible with driver %s" % self.type 80 | ) 81 | 82 | def bridge_exists(self, name=None): 83 | raise NetworkDriverError( 84 | "Checking for a bridge is not possible with driver %s" % self.type 85 | ) 86 | 87 | def generate_bridge_name(self, prefix='virbr', max_tries=1024): 88 | suffix_i = 0 89 | new_name = None 90 | 91 | while suffix_i < max_tries: 92 | new_name = prefix + str(suffix_i) 93 | 94 | if not self.bridge_exists(new_name): 95 | return new_name 96 | 97 | suffix_i += 1 98 | 99 | raise KraftError("Max tries for bridge creation reached!") 100 | -------------------------------------------------------------------------------- /kraft/plat/network/driver/types.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from enum import Enum 36 | 37 | from .brctl import BRCTLDriver 38 | 39 | 40 | class NetworkDriverTypes(Enum): 41 | BRCTL = ("brctl" , BRCTLDriver) # noqa 42 | 43 | @property 44 | def name(self): 45 | return self.value[0] 46 | 47 | @property 48 | def cls(self): 49 | return self.value[1] 50 | -------------------------------------------------------------------------------- /kraft/plat/plat.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import click 36 | 37 | from kraft.component import Component 38 | from kraft.component import ComponentManager 39 | from kraft.const import UK_CORE_PLAT_DIR 40 | from kraft.error import DisabledComponentError 41 | from kraft.plat.runner import str_to_runner 42 | from kraft.types import ComponentType 43 | 44 | 45 | class Platform(Component): 46 | _type = ComponentType.PLAT 47 | 48 | _runner = None 49 | @property 50 | def runner(self): return self._runner 51 | 52 | @click.pass_context 53 | def __init__(ctx, self, *args, **kwargs): 54 | self._name = kwargs.get("name", None) 55 | self._core = kwargs.get("core", None) 56 | 57 | runner = str_to_runner(self.name) 58 | if runner is not None: 59 | self._runner = runner.cls() 60 | 61 | 62 | class InternalPlatform(Platform): 63 | _core = None 64 | @property 65 | def core(self): return self._core 66 | 67 | @property 68 | def is_downloaded(self): 69 | if self._core is not None: 70 | return self._core.is_downloaded 71 | return False 72 | 73 | _localdir = None 74 | 75 | @property 76 | @click.pass_context 77 | def localdir(ctx, self): 78 | if self._localdir is None and self._core is not None: 79 | self._localdir = UK_CORE_PLAT_DIR % ( 80 | self._core.localdir, self._name 81 | ) 82 | 83 | return self._localdir 84 | 85 | @click.pass_context 86 | def __init__(ctx, self, *args, **kwargs): 87 | super(InternalPlatform, self).__init__(*args, **kwargs) 88 | 89 | self._core = kwargs.get("core", None) 90 | self._kconfig = list() 91 | 92 | config = kwargs.get("config", None) 93 | 94 | if isinstance(config, bool) and config is False: 95 | raise DisabledComponentError(self._name) 96 | 97 | elif isinstance(config, dict): 98 | self._version = config.get("version", None) 99 | self._kconfig = config.get("kconfig", kwargs.get("kconfig", list())) 100 | 101 | def repr(self): 102 | config = {} 103 | 104 | if self._kconfig is not None and len(self._kconfig) > 0: 105 | config['kconfig'] = self._kconfig 106 | 107 | return self.name if not config else config 108 | 109 | 110 | class PlatformManager(ComponentManager): 111 | def __init__(self, components=[], t=None): 112 | super(PlatformManager, self).__init__(components, Platform) 113 | -------------------------------------------------------------------------------- /kraft/plat/runner/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .kvm import KVMRunner # noqa: F401 36 | from .linuxu import LinuxuRunner # noqa: F401 37 | from .runner import Runner # noqa: F401 38 | from .types import RunnerTypes # noqa: F401 39 | from .types import str_to_runner # noqa: F401 40 | from .xen import XenRunner # noqa: F401 41 | -------------------------------------------------------------------------------- /kraft/plat/runner/kvm.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import platform 36 | import subprocess 37 | 38 | import kraft.util as util 39 | from .runner import Runner 40 | from kraft.const import QEMU_GUEST 41 | from kraft.logger import logger 42 | 43 | 44 | class KVMRunner(Runner): 45 | def execute(self, # noqa: C901 46 | extra_args=None, 47 | background=False, 48 | paused=False, 49 | dry_run=False): 50 | logger.debug("Executing on KVM...") 51 | 52 | self._cmd.extend(('-k', self.unikernel)) 53 | 54 | if background: 55 | self._cmd.append('-x') 56 | if paused: 57 | self._cmd.append('-P') 58 | if dry_run: 59 | self._cmd.append('-D') 60 | if extra_args: 61 | self._cmd.extend(('-a', ' '.join(extra_args))) 62 | 63 | self.automount(dry_run) 64 | self.autoconnect(dry_run) 65 | 66 | if self.architecture == "x86_64": 67 | self._cmd.extend(('-t', 'x86pc')) 68 | elif self.architecture == "arm64": 69 | self._cmd.extend(('-t', 'arm64v')) 70 | 71 | if platform.machine() != self.architecture: 72 | self._cmd.append('-W') 73 | 74 | if self.arguments: 75 | self._cmd.extend(('-a', self.arguments)) 76 | 77 | cmd = [QEMU_GUEST] 78 | 79 | cmd.extend(self._cmd) 80 | 81 | for pre_up_cmd in self._pre_up: 82 | util.execute(pre_up_cmd, dry_run=dry_run) 83 | 84 | cmd = list(map(str, cmd)) 85 | logger.debug('Running: %s' % ' '.join(cmd)) 86 | 87 | if not dry_run: 88 | process = subprocess.Popen(cmd) 89 | 90 | try: 91 | process.wait() 92 | 93 | except KeyboardInterrupt: 94 | try: 95 | process.terminate() 96 | except OSError: 97 | pass 98 | process.wait() 99 | 100 | for post_down_cmd in self._post_down: 101 | util.execute(post_down_cmd, dry_run=dry_run) 102 | -------------------------------------------------------------------------------- /kraft/plat/runner/linuxu.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import subprocess 36 | 37 | import kraft.util as util 38 | from .runner import Runner 39 | from kraft.logger import logger 40 | 41 | 42 | class LinuxuRunner(Runner): 43 | _base_cmd = '' 44 | 45 | def add_initrd(self, initrd=None): 46 | pass 47 | 48 | def add_virtio_nic(self, virtio_nic=None): 49 | pass 50 | 51 | def add_bridge(self, bridge=None): 52 | pass 53 | 54 | def add_interface(self, interface=None): 55 | pass 56 | 57 | def add_virtio_raw(self, image=None): 58 | pass 59 | 60 | def add_virtio_qcow2(self, image=None): 61 | pass 62 | 63 | def add_virtio_9pfs(self, image=None): 64 | pass 65 | 66 | def open_gdb(self, port=None): 67 | pass 68 | 69 | def set_memory(self, memory=None): 70 | pass 71 | 72 | # TODO: Pin CPUs with isolcpus or taskset 73 | def set_cpu_sockets(self, cpu_sockets=None): 74 | pass 75 | 76 | # TODO: Pin CPUs with isolcpus or taskset 77 | def set_cpu_cores(self, cpu_cores=None): 78 | pass 79 | 80 | def execute(self, extra_args=None, background=False, paused=False, 81 | dry_run=False): 82 | logger.debug("Executing on Linux...") 83 | 84 | cmd = [ 85 | self.unikernel 86 | ] 87 | 88 | if self.arguments: 89 | cmd.append(self.arguments) 90 | 91 | if extra_args: 92 | cmd.extend(extra_args) 93 | 94 | for pre_up_cmd in self._pre_up: 95 | util.execute(pre_up_cmd, dry_run=dry_run) 96 | 97 | cmd = list(map(str, cmd)) 98 | logger.debug('Running: %s' % ' '.join(cmd)) 99 | 100 | if not dry_run: 101 | process = subprocess.Popen(cmd) 102 | 103 | try: 104 | process.wait() 105 | 106 | except KeyboardInterrupt: 107 | try: 108 | process.terminate() 109 | except OSError: 110 | pass 111 | process.wait() 112 | 113 | for post_down_cmd in self._post_down: 114 | util.execute(post_down_cmd, dry_run=dry_run) 115 | -------------------------------------------------------------------------------- /kraft/plat/runner/types.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from enum import Enum 36 | 37 | from .kvm import KVMRunner 38 | from .linuxu import LinuxuRunner 39 | from .xen import XenRunner 40 | 41 | 42 | class RunnerTypes(Enum): 43 | KVM = ("kvm" , KVMRunner) # noqa 44 | LINUXU = ("linuxu" , LinuxuRunner) # noqa 45 | XEN = ("xen" , XenRunner) # noqa 46 | 47 | @property 48 | def name(self): 49 | return self.value[0] 50 | 51 | @property 52 | def cls(self): 53 | return self.value[1] 54 | 55 | 56 | def str_to_runner(name=None): 57 | if name is None: 58 | return None 59 | 60 | for r in RunnerTypes.__members__.values(): 61 | if name == r.name: 62 | return r 63 | 64 | return None 65 | -------------------------------------------------------------------------------- /kraft/plat/runner/xen.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import subprocess 36 | 37 | import kraft.util as util 38 | from .runner import Runner 39 | from kraft.const import XEN_GUEST 40 | from kraft.logger import logger 41 | 42 | 43 | class XenRunner(Runner): 44 | def execute(self, # noqa: C901 45 | extra_args=None, 46 | background=False, 47 | paused=False, 48 | dry_run=False): 49 | logger.debug("Executing on Xen...") 50 | 51 | self._cmd.extend(('-k', self.unikernel)) 52 | 53 | if background: 54 | self._cmd.append('-X') 55 | if paused: 56 | self._cmd.append('-P') 57 | if dry_run: 58 | self._cmd.append('-D') 59 | if extra_args: 60 | self._cmd.extend(('-a', ' '.join(extra_args))) 61 | 62 | self.automount(dry_run) 63 | self.autoconnect(dry_run) 64 | 65 | if self.arguments: 66 | self._cmd.extend(('-a', self.arguments)) 67 | 68 | cmd = [XEN_GUEST] 69 | cmd.extend(self._cmd) 70 | 71 | for pre_up_cmd in self._pre_up: 72 | util.execute(pre_up_cmd, dry_run=dry_run) 73 | 74 | cmd = list(map(str, cmd)) 75 | logger.debug('Running: %s' % ' '.join(cmd)) 76 | 77 | if not dry_run: 78 | process = subprocess.Popen(cmd) 79 | 80 | try: 81 | process.wait() 82 | 83 | except KeyboardInterrupt: 84 | try: 85 | process.terminate() 86 | except OSError: 87 | pass 88 | process.wait() 89 | 90 | for post_down_cmd in self._post_down: 91 | util.execute(post_down_cmd, dry_run=dry_run) 92 | -------------------------------------------------------------------------------- /kraft/plat/volume/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .types import VolumeTypes # noqa: F401 36 | from .volume import Volume # noqa: F401 37 | from .volume import VolumeDriver # noqa: F401 38 | from .volume import VolumeManager # noqa: F401 39 | -------------------------------------------------------------------------------- /kraft/plat/volume/types.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from enum import Enum 36 | 37 | 38 | class VolumeTypes(Enum): 39 | VOL_INITRD = ("initrd", [""]) 40 | VOL_9PFS = ("9pfs", [ 41 | "CONFIG_LIBDEVFS=y" 42 | "CONFIG_LIB9PFS=y" 43 | ]) 44 | VOL_RAW = ("raw", [ 45 | "CONFIG_LIBDEVFS=y" 46 | ]) 47 | VOL_QCOW2 = ("qcow2", [ 48 | "CONFIG_LIBDEVFS=y" 49 | ]) 50 | 51 | @property 52 | def name(self): 53 | return self.value[0] 54 | 55 | @property 56 | def kconfig(self): 57 | return self.kconfig[0] 58 | 59 | @classmethod 60 | def from_name(cls, name=None): 61 | for vol in VolumeTypes.__members__.items(): 62 | if name == vol[1].name: 63 | return vol 64 | 65 | return None 66 | -------------------------------------------------------------------------------- /kraft/target/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2021, Lancaster University. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | # flake8: noqa 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .target import Target 36 | from .target import TargetManager 37 | -------------------------------------------------------------------------------- /kraft/template/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | 37 | import yaml 38 | 39 | from kraft.const import TEMPLATE_CONFIG 40 | from kraft.const import TEMPLATE_MANIFEST 41 | from kraft.util import delete_resource 42 | 43 | 44 | def get_templates_path(templatedir=None): 45 | if templatedir is None: 46 | raise ValueError("expected templatedir") 47 | return os.path.join( 48 | os.path.dirname(os.path.abspath(__file__)), 49 | templatedir 50 | ) 51 | 52 | 53 | def get_template_config(templatedir=None): 54 | if templatedir is None: 55 | raise ValueError("expected templatedir") 56 | 57 | return os.path.join( 58 | get_templates_path(templatedir), 59 | TEMPLATE_CONFIG 60 | ) 61 | 62 | 63 | def delete_template_resources_of_disabled_features(templatedir=None): 64 | if templatedir is None: 65 | return 66 | 67 | template_manifest = os.path.join(templatedir, TEMPLATE_MANIFEST) 68 | 69 | if os.path.exists(template_manifest) is False: 70 | return 71 | 72 | with open(template_manifest) as manifest_file: 73 | manifest = yaml.load(manifest_file, Loader=yaml.FullLoader) 74 | 75 | for feature in manifest['features']: 76 | if not feature['enabled']: 77 | for resource in feature['resources']: 78 | delete_resource(os.path.join(templatedir, resource)) 79 | 80 | delete_resource(template_manifest) 81 | -------------------------------------------------------------------------------- /kraft/template/lib/cookiecutter.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_name": "", 3 | "lib_name": "lib-template", 4 | "lib_kname": "LIBTEMPLATE", 5 | "version": "", 6 | "description": "", 7 | "author_name": "", 8 | "author_email": "", 9 | "provide_main": true, 10 | "with_gitignore": true, 11 | "with_docs": true, 12 | "with_patchedir": false, 13 | "initial_branch": "staging", 14 | "copyright_holder": "" 15 | } 16 | -------------------------------------------------------------------------------- /kraft/template/lib/{{cookiecutter.project_name}}/CODING_STYLE.md: -------------------------------------------------------------------------------- 1 | # Coding Style 2 | 3 | Please refer to the [`CODING_STYLE.md`](https://github.com/unikraft/unikraft/tree/staging/CODING_STYLE.md) file in the main Unikraft repository. 4 | -------------------------------------------------------------------------------- /kraft/template/lib/{{cookiecutter.project_name}}/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Unikraft 2 | 3 | Please refer to the [`CONTRIBUTING.md`](https://github.com/unikraft/unikraft/tree/staging/CONTRIBUTING.md) file in the main Unikraft repository. 4 | -------------------------------------------------------------------------------- /kraft/template/lib/{{cookiecutter.project_name}}/COPYING.md: -------------------------------------------------------------------------------- 1 | # License 2 | 3 | Unikraft {{ cookiecutter.project_name }} wrapper library 4 | 5 | This repository contains wrapper code to build {{ cookiecutter.project_name }} with Unikraft. 6 | Each C code file in this repository should declare who is the 7 | copyright owner and under which terms and conditions the code is 8 | licensed. If such a licence note is missing, the following copyright 9 | notice will apply: 10 | 11 | Copyright (c) Year, Institution. All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without 14 | modification, are permitted provided that the following conditions 15 | are met: 16 | 17 | 1. Redistributions of source code must retain the above copyright 18 | notice, this list of conditions and the following disclaimer. 19 | 2. Redistributions in binary form must reproduce the above copyright 20 | notice, this list of conditions and the following disclaimer in the 21 | documentation and/or other materials provided with the distribution. 22 | 3. Neither the name of the copyright holder nor the names of its 23 | contributors may be used to endorse or promote products derived from 24 | this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 27 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 30 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | POSSIBILITY OF SUCH DAMAGE. 37 | -------------------------------------------------------------------------------- /kraft/template/lib/{{cookiecutter.project_name}}/Config.uk: -------------------------------------------------------------------------------- 1 | menuconfig {{ cookiecutter.lib_kname|upper }} 2 | {%- if cookiecutter.description == "" %} 3 | bool "{{ cookiecutter.project_name }} Unikraft library" 4 | {%- else %} 5 | bool "{{ cookiecutter.description }}" 6 | {%- endif %} 7 | default n 8 | 9 | {%- for dependency in cookiecutter.kconfig_dependencies %} 10 | select {{ dependency|upper }} 11 | {%- endfor %} 12 | 13 | if {{ cookiecutter.lib_kname|upper }} 14 | 15 | {%- if cookiecutter.provide_main %} 16 | config {{ cookiecutter.lib_kname|upper }}_MAIN_FUNCTION 17 | bool "Provide main function" 18 | default n 19 | {%- endif %} 20 | 21 | endif 22 | -------------------------------------------------------------------------------- /kraft/template/lib/{{cookiecutter.project_name}}/MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | # Maintainers List 2 | 3 | For notes on how to read this information, please refer to [`MAINTAINERS.md`](https://github.com/unikraft/unikraft/tree/staging/MAINTAINERS.md) in 4 | the main Unikraft repository. 5 | 6 | {{ cookiecutter.lib_kname|upper }}-UNIKRAFT 7 | M: {{ cookiecutter.author_name }} <{{ cookiecutter.author_email }}> 8 | L: minios-devel@lists.xen.org 9 | F: * 10 | -------------------------------------------------------------------------------- /kraft/template/lib/{{cookiecutter.project_name}}/README.md: -------------------------------------------------------------------------------- 1 | # {{ cookiecutter.project_name }} for Unikraft 2 | 3 | This is the port of {{ cookiecutter.project_name }} for Unikraft as external library. 4 | 5 | Please refer to the [`README.md`](https://github.com/unikraft/unikraft/tree/staging/README.md) 6 | as well as the documentation in the [`doc/`](https://github.com/unikraft/unikraft/tree/staging/doc/) 7 | subdirectory of the main unikraft repository. 8 | -------------------------------------------------------------------------------- /kraft/template/lib/{{cookiecutter.project_name}}/main.c: -------------------------------------------------------------------------------- 1 | {%- if cookiecutter.copyright_holder != "" -%} 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | // 4 | // {{ cookiecutter.project_name }} Unikraft library 5 | // 6 | // Authors: {{ cookiecutter.author_name }} <{{ cookiecutter.author_email }}> 7 | // 8 | // Copyright (c) {{ cookiecutter.year }}, {{ cookiecutter.copyright_holder }}. All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions 12 | // are met: 13 | // 14 | // 1. Redistributions of source code must retain the above copyright 15 | // notice, this list of conditions and the following disclaimer. 16 | // 2. Redistributions in binary form must reproduce the above copyright 17 | // notice, this list of conditions and the following disclaimer in the 18 | // documentation and/or other materials provided with the distribution. 19 | // 3. Neither the name of the copyright holder nor the names of its 20 | // contributors may be used to endorse or promote products derived from 21 | // this software without specific prior written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 27 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | // POSSIBILITY OF SUCH DAMAGE. 34 | {% endif %} 35 | int main(int argc, char *argv[]) 36 | { 37 | // TODO: Replace with main 38 | return {{ cookiecutter.project_name|lower }}_main(argc, argv); 39 | } 40 | -------------------------------------------------------------------------------- /kraft/template/lib/{{cookiecutter.project_name}}/manifest.yaml: -------------------------------------------------------------------------------- 1 | features: 2 | - name: with_gitignore 3 | enabled: {{ cookiecutter.with_gitignore|lower }} 4 | resources: 5 | - .gitignore 6 | - name: with_docs 7 | enabled: {{ cookiecutter.with_docs|lower }} 8 | resources: 9 | - README.md 10 | - COPYING.md 11 | - MAINTAINERS.md 12 | - CODING_STYLE.md 13 | - CONTRIBUTING.md 14 | - name: provide_main 15 | enabled: {{ cookiecutter.provide_main|lower }} 16 | resources: 17 | - main.c 18 | - name: with_patchedir 19 | enabled: {{ cookiecutter.with_patchedir|lower }} 20 | resources: 21 | - patches/ 22 | -------------------------------------------------------------------------------- /kraft/unikraft.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from .component import Component 36 | from .types import ComponentType 37 | 38 | 39 | class Unikraft(Component): 40 | _type = ComponentType.CORE 41 | -------------------------------------------------------------------------------- /kraft/util/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | # flake8: noqa 33 | from __future__ import absolute_import 34 | from __future__ import unicode_literals 35 | 36 | from .cli import ClickOptionMutex 37 | from .cli import ClickReaderOption 38 | from .cli import ClickWriterCommand 39 | from .cli import ClickWriterOption 40 | from .cli import KraftHelpCommand 41 | from .cli import KraftHelpGroup 42 | from .dir import delete_resource 43 | from .dir import is_dir_empty 44 | from .dir import recursively_copy 45 | from .make import make_list_vars 46 | from .op import execute 47 | from .op import make_progressbar 48 | from .op import merge_dicts 49 | from .text import pretty_columns 50 | from .text import prettydate 51 | from .threading import ErrorPropagatingThread 52 | -------------------------------------------------------------------------------- /kraft/util/dir.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import os 36 | import shutil 37 | from shutil import copyfile 38 | from shutil import SameFileError 39 | 40 | from kraft.logger import logger 41 | 42 | 43 | def is_dir_empty(path=None): 44 | """Return a boolean of whether the provided directory `dir` is empty.""" 45 | return os.path.isdir(path) is False or \ 46 | len([f for f in os.listdir(path) if not f.startswith('.')]) == 0 47 | 48 | 49 | def recursively_copy(src, dest, overwrite=False, ignore=[]): 50 | if os.path.basename(src) in ignore: 51 | pass 52 | elif os.path.isdir(src): 53 | if not os.path.isdir(dest): 54 | os.makedirs(dest) 55 | 56 | files = os.listdir(src) 57 | 58 | for f in files: 59 | recursively_copy( 60 | os.path.join(src, f), 61 | os.path.join(dest, f), 62 | overwrite, 63 | ignore 64 | ) 65 | elif (os.path.exists(dest) and overwrite) or os.path.exists(dest) is False: 66 | try: 67 | copyfile(src, dest) 68 | except SameFileError: 69 | pass 70 | 71 | 72 | def delete_resource(resource): 73 | if os.path.isfile(resource): 74 | logger.debug("Removing file: %s" % resource) 75 | os.remove(resource) 76 | 77 | elif os.path.isdir(resource): 78 | logger.debug("Removing directory: %s" % resource) 79 | shutil.rmtree(resource) 80 | -------------------------------------------------------------------------------- /kraft/util/make.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import re 36 | import subprocess 37 | 38 | 39 | def make_list_vars(Makefile=None, origin=None): 40 | """ 41 | Generate the (key, value) dict of all variables defined in make process. 42 | 43 | Args: 44 | Makefile: The location of the Makefile to expand. 45 | origin: The means of selecting where the variable is derived from. 46 | Choose from: 'automatic', 'environment', 'default', 'override', 47 | 'makefile'. Setting to None returns all origins. 48 | 49 | Returns: 50 | A dict mapping keys to the corresponding variable. 51 | """ 52 | 53 | p = subprocess.getoutput("make -pnB -f %s" % Makefile) 54 | 55 | M = {} 56 | re_var = re.compile(r"^#\s*Variables\b") # start of variable segment 57 | re_varend = re.compile(r"^#\s*variable") # end of variables 58 | state = None # state of parser 59 | mname = None 60 | 61 | for line in p.splitlines(): 62 | if state is None and re_var.search(line): 63 | state = 'var' 64 | 65 | elif state == 'var': 66 | line = line.strip() 67 | 68 | if re_varend.search(line): # last line of variable block 69 | state = 'end' 70 | break 71 | 72 | if line.startswith("#"): # type of variable 73 | q = line.split() 74 | mname = q[1] 75 | 76 | elif mname is not None: 77 | if origin is not None and mname not in origin: 78 | continue 79 | 80 | if mname not in M: 81 | M[mname] = {} 82 | 83 | q = line.split(maxsplit=2) # key =|:= value 84 | 85 | if len(q) == 2: 86 | M[mname][q[0]] = '' 87 | else: 88 | M[mname][q[0]] = q[2] 89 | 90 | mname = None 91 | 92 | return M 93 | -------------------------------------------------------------------------------- /kraft/util/text.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | from datetime import datetime 36 | 37 | 38 | def pretty_columns(data=[]): 39 | widths = [max(map(len, col)) for col in zip(*data)] 40 | output = "" 41 | 42 | for row in data: 43 | output += "\t".join((val.ljust(width) for val, width in zip(row, widths))) + "\n" 44 | 45 | return output 46 | 47 | 48 | def prettydate(date=None): 49 | if date is None: 50 | return 'Never' 51 | 52 | diff = datetime.utcnow() - date 53 | s = diff.seconds 54 | 55 | if diff.days > 7 or diff.days < 0: 56 | return date.strftime('%d %b %y') 57 | elif diff.days == 1: 58 | return '1 day ago' 59 | elif diff.days > 1: 60 | return '{} days ago'.format(round(diff.days)) 61 | elif s <= 1: 62 | return 'just now' 63 | elif s < 60: 64 | return '{} seconds ago'.format(round(s)) 65 | elif s < 120: 66 | return '1 minute ago' 67 | elif s < 3600: 68 | return '{} minutes ago'.format(round(s/60)) 69 | elif s < 7200: 70 | return '1 hour ago' 71 | else: 72 | return '{} hours ago'.format(round(s/3600)) 73 | -------------------------------------------------------------------------------- /kraft/util/threading.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Laboratories GmbH., NEC Corporation. 6 | # All rights reserved. 7 | # 8 | # Redistribution and use in source and binary forms, with or without 9 | # modification, are permitted provided that the following conditions 10 | # are met: 11 | # 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 3. Neither the name of the copyright holder nor the names of its 18 | # contributors may be used to endorse or promote products derived from 19 | # this software without specific prior written permission. 20 | # 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | # POSSIBILITY OF SUCH DAMAGE. 32 | from __future__ import absolute_import 33 | from __future__ import unicode_literals 34 | 35 | import threading 36 | 37 | 38 | class ErrorPropagatingThread(threading.Thread): 39 | def run(self): 40 | self.exc = None 41 | try: 42 | # Thread uses name mangling prior to Python 3. 43 | if hasattr(self, '_Thread__target'): 44 | self.ret = self._Thread__target( 45 | *self._Thread__args, 46 | **self._Thread__kwargs 47 | ) 48 | else: 49 | self.ret = self._target(*self._args, **self._kwargs) 50 | 51 | except BaseException as e: 52 | self.exc = e 53 | 54 | def join(self): 55 | super(ErrorPropagatingThread, self).join() 56 | 57 | if self.exc: 58 | raise self.exc 59 | 60 | return self.ret 61 | -------------------------------------------------------------------------------- /package/debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /package/debian/control: -------------------------------------------------------------------------------- 1 | Source: unikraft-tools 2 | Section: devel 3 | Priority: optional 4 | Maintainer: Alexander Jung 5 | Build-Depends: debhelper (>= 9), 6 | python3, 7 | python3-dev, 8 | dh-virtualenv (>= 1.0), 9 | tar 10 | Standards-Version: 3.9.5 11 | Homepage: http://unikraft.org 12 | 13 | Package: unikraft-tools 14 | Conflicts: kraft 15 | Architecture: all 16 | Pre-Depends: dpkg (>= 1.16.1), ${misc:Pre-Depends} 17 | Depends: ${misc:Depends}, 18 | python3.5 | python3 (>= 3.5), 19 | python3-distutils | python3-distutils-extra, 20 | git, 21 | make, 22 | libncursesw5-dev, 23 | libyaml-dev, 24 | flex, 25 | git, 26 | wget, 27 | patch, 28 | gawk, 29 | socat, 30 | bison, 31 | unzip, 32 | uuid-runtime 33 | Recommends: dnsmasq, 34 | qemu, 35 | qemu-kvm, 36 | sgabios 37 | Description: Define, configure, build and run unikernel applications. 38 | To begin using Unikraft SDK you can use the command-line utility kraft, which 39 | is a companion tool used for defining, configuring, building, and running 40 | unikernel applications. With kraft you can seamlessly create a build 41 | environment for your unikernel and painlessly manage dependencies for its 42 | build. 43 | -------------------------------------------------------------------------------- /package/debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: unikraft-tools 3 | Upstream-Contact: Alexander Jung 4 | Source: https://github.com/unikraft/kraft.git 5 | 6 | Files: * 7 | Copyright: 2019-2020 NEC Europe Ltd., NEC Corporation 8 | License: BSD-3-clause 9 | 10 | Files: debian/* 11 | Copyright: 2019-2020 NEC Europe Ltd., NEC Corporation 12 | License: BSD-3-clause 13 | 14 | License: BSD-3-clause 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions are met: 17 | . 18 | 1) Redistributions of source code must retain the above copyright notice, 19 | this list of conditions and the following disclaimer. 20 | . 21 | 2) Redistributions in binary form must reproduce the above copyright notice, 22 | this list of conditions and the following disclaimer in the documentation 23 | and/or other materials provided with the distribution. 24 | . 25 | 3) Neither the name of the ORGANIZATION nor the names of its contributors 26 | may be used to endorse or promote products derived from this software 27 | without specific prior written permission. 28 | . 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 30 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 32 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 33 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 35 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 36 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 37 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 | POSSIBILITY OF SUCH DAMAGE. 40 | -------------------------------------------------------------------------------- /package/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # 3 | # Build Debian package using https://github.com/spotify/dh-virtualenv 4 | # 5 | # The below targets create a clean copy of the workdir via 6 | # using "sdist", else "pip" goes haywire when installing from 7 | # sourcedir ".", because that includes the debian build stage, 8 | # and a recursive explosion ensues when symlinks are followed. 9 | # 10 | # It also ensures your MANIFEST is complete and at least covers 11 | # all files needed for a release build. 12 | 13 | # Increase trace logging, see debhelper(7) (uncomment to enable) 14 | #DH_VERBOSE=1 15 | 16 | export PYBUILD_NAME=unikraft-tools 17 | export DH_VIRTUALENV_INSTALL_ROOT=/usr/share 18 | 19 | SNAKE = /usr/bin/python3 20 | 21 | DH_VENV_ARGS = --python=$(SNAKE) --upgrade-pip \ 22 | --preinstall "setuptools>=38" --preinstall "wheel" 23 | 24 | ifneq ($(HTTP_PROXY),) 25 | DH_VENV_ARGS += --extra-pip-arg=--proxy=$(HTTP_PROXY) 26 | else ifneq ($(http_proxy),) 27 | DH_VENV_ARGS += --extra-pip-arg=--proxy=$(http_proxy) 28 | endif 29 | 30 | PACKAGE = $(shell dh_listpackages) 31 | VERSION = $(shell $(SNAKE) setup.py --version) 32 | SDIST_DIR = $(CURDIR) 33 | 34 | .PHONY: clean build-arch override_dh_virtualenv override_dh_strip 35 | 36 | clean: 37 | dh $@ $(DH_VENV_ARGS) 38 | 39 | build-arch: 40 | dh $@ $(DH_VENV_ARGS) --sourcedir $(SDIST_DIR) 41 | 42 | %: 43 | dh $@ --with python-virtualenv --sourcedir $(SDIST_DIR) 44 | 45 | override_dh_virtualenv: 46 | dh_virtualenv $(DH_VENV_ARGS) 47 | 48 | override_dh_python3: 49 | dh_python3 --shebang=$(SNAKE) 50 | -------------------------------------------------------------------------------- /package/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /package/debian/source/options: -------------------------------------------------------------------------------- 1 | extend-diff-ignore = "^[^/]*[.]egg-info/" 2 | 3 | tar-ignore 4 | tar-ignore = .coverage 5 | tar-ignore = .tox 6 | tar-ignore = .venv 7 | tar-ignore = bin 8 | tar-ignore = docs/_build 9 | tar-ignore = *.log 10 | tar-ignore = *.egg-info 11 | -------------------------------------------------------------------------------- /package/debian/unikraft-tools.links: -------------------------------------------------------------------------------- 1 | usr/share/unikraft-tools/bin/kraft usr/bin/kraft 2 | usr/share/unikraft-tools/bin/kraft-net usr/bin/kraft-net 3 | usr/share/unikraft-tools/bin/qemu-guest usr/bin/qemu-guest 4 | usr/share/unikraft-tools/bin/kvm-guest usr/bin/kvm-guest 5 | -------------------------------------------------------------------------------- /package/debian/unikraft-tools.lintian-overrides: -------------------------------------------------------------------------------- 1 | # Don't lint executables installed by dependencies 2 | wrong-path-for-interpreter usr/share/unikraft-tools/bin/* 3 | python-script-but-no-python-dep usr/share/unikraft-tools/bin/* 4 | 5 | # Ignore pycache created when running code of dependencies 6 | package-installs-python-pycache-dir 7 | 8 | # Where else? 9 | arch-dependent-file-in-usr-share 10 | -------------------------------------------------------------------------------- /package/debian/unikraft-tools.triggers: -------------------------------------------------------------------------------- 1 | # Register interest in Python interpreter changes; and don't make the Python 2 | # package dependent on the virtualenv package processing (noawait) 3 | interest-noawait /usr/bin/python3.5 4 | interest-noawait /usr/bin/python3.6 5 | interest-noawait /usr/bin/python3.7 6 | interest-noawait /usr/bin/python3.8 7 | 8 | # Also provide a symbolic trigger for all dh-virtualenv packages 9 | interest dh-virtualenv-interpreter-update 10 | -------------------------------------------------------------------------------- /package/docker/Dockerfile.pkg-deb: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | 32 | ARG PKG_VENDOR=debian 33 | ARG PKG_DISTRIBUTION=stretch-20200224 34 | 35 | FROM ${PKG_VENDOR}:${PKG_DISTRIBUTION} 36 | 37 | LABEL MAINTAINER="Alexander Jung " 38 | 39 | WORKDIR /usr/src/kraft 40 | 41 | COPY requirements-dev.txt /tmp/requirements-dev.txt 42 | COPY requirements-pkg-deb.txt /tmp/requirements-pkg-deb.txt 43 | 44 | ENV DEBIAN_FRONTEND=noninteractive 45 | 46 | RUN set -xe; \ 47 | apt-get update; \ 48 | apt-get install -y \ 49 | lsb-release; \ 50 | RELEASE=$(lsb_release -cs); \ 51 | case ${RELEASE} in \ 52 | trusty) \ 53 | apt-get install -y \ 54 | python3.5; \ 55 | update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1; \ 56 | ;; \ 57 | sid|focal) \ 58 | apt-get install -y \ 59 | python3-all \ 60 | python3-pip; \ 61 | update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1; \ 62 | ;; \ 63 | *) \ 64 | apt-get install -y \ 65 | python3-all \ 66 | python-mock \ 67 | python-pip; \ 68 | ;; \ 69 | esac; \ 70 | apt-get install -y \ 71 | build-essential \ 72 | debhelper \ 73 | devscripts \ 74 | equivs \ 75 | libdpkg-perl \ 76 | python \ 77 | python-setuptools \ 78 | python-dev \ 79 | docutils-common \ 80 | dh-exec \ 81 | dh-python \ 82 | devscripts \ 83 | debhelper \ 84 | python-setuptools \ 85 | python3-setuptools \ 86 | python3-dev \ 87 | libncursesw5-dev \ 88 | libyaml-dev \ 89 | flex \ 90 | git \ 91 | wget \ 92 | curl \ 93 | socat \ 94 | patch \ 95 | gawk \ 96 | bison \ 97 | uuid-runtime; \ 98 | case ${RELEASE} in \ 99 | focal) \ 100 | pip install --upgrade --force-reinstall pip==9.0.3; \ 101 | ;; \ 102 | *) \ 103 | python -m pip install --upgrade --force-reinstall pip==9.0.3; \ 104 | ;; \ 105 | esac; \ 106 | pip install -r /tmp/requirements-dev.txt; \ 107 | pip install -r /tmp/requirements-pkg-deb.txt; \ 108 | git clone https://github.com/spotify/dh-virtualenv.git /tmp/dh-virtualenv; \ 109 | cd /tmp/dh-virtualenv; \ 110 | git checkout 98b4822; \ 111 | sed -i -e 's/ python-sphinx-rtd-theme/#/g' debian/control; \ 112 | sed -i -e 's/, python-sphinx//g' debian/control; \ 113 | sed -i -e 's/, python-mock//g' debian/control; \ 114 | sed -i -e 's/dh-python,//g' debian/control; \ 115 | sed -i -re "1s/..unstable/~$(lsb_release -cs)) $(lsb_release -cs)/" debian/changelog; \ 116 | DEB_BUILD_OPTIONS=nodoc dpkg-buildpackage -us -uc -b; \ 117 | dpkg -i ../dh-virtualenv_*.deb || apt-get install -yf; \ 118 | rm /usr/bin/virtualenv; \ 119 | ln -s /usr/local/bin/virtualenv /usr/bin/virtualenv 120 | 121 | ENV LC_ALL=C.UTF-8 122 | -------------------------------------------------------------------------------- /package/docker/Dockerfile.pkg-deb-test: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | 32 | ARG PKG_VENDOR=debian 33 | ARG PKG_DISTRIBUTION=stretch 34 | 35 | FROM ${PKG_VENDOR}:${PKG_DISTRIBUTION} 36 | 37 | ARG APP_VERSION=0.4.0 38 | ARG PKG_DISTRIBUTION=stretch 39 | 40 | LABEL MAINTAINER="Alexander Jung " 41 | 42 | COPY dist /usr/src/kraft/dist 43 | 44 | WORKDIR /usr/src/kraft/dist 45 | 46 | ENV LC_ALL=C.UTF-8 47 | ENV LANG=C.UTF-8 48 | 49 | RUN set -xe; \ 50 | apt-get update; \ 51 | dpkg -i ./unikraft-tools_*~${PKG_DISTRIBUTION}_all.deb || true; \ 52 | apt-get install -yf; \ 53 | kraft --version 54 | -------------------------------------------------------------------------------- /package/docker/Dockerfile.qemu: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | 32 | ARG DEBIAN_VERSION=stretch-20191224 33 | 34 | FROM debian:${DEBIAN_VERSION} AS qemu-build 35 | 36 | LABEL MAINTAINER="Alexander Jung " 37 | 38 | ARG QEMU_VERSION=4.2.0 39 | WORKDIR /out 40 | 41 | RUN set -ex; \ 42 | apt-get -y update; \ 43 | apt-get -y upgrade; \ 44 | apt-get install -y \ 45 | build-essential \ 46 | curl \ 47 | libaio-dev \ 48 | libcap-dev \ 49 | libcap-ng-dev \ 50 | libglib2.0-dev \ 51 | liblzo2-dev \ 52 | libpixman-1-dev \ 53 | pkg-config \ 54 | flex \ 55 | bison \ 56 | python \ 57 | texinfo \ 58 | vde2 \ 59 | zlib1g-dev \ 60 | xz-utils; \ 61 | curl -O https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz; \ 62 | tar xf qemu-${QEMU_VERSION}.tar.xz; \ 63 | apt-get install -y; \ 64 | cd qemu-${QEMU_VERSION}; \ 65 | ./configure \ 66 | --prefix=/ \ 67 | --static \ 68 | --python=/usr/bin/python2 \ 69 | --audio-drv-list="" \ 70 | --disable-docs \ 71 | --disable-debug-info \ 72 | --disable-opengl \ 73 | --disable-virglrenderer \ 74 | --disable-vte \ 75 | --disable-gtk \ 76 | --disable-sdl \ 77 | --disable-bluez \ 78 | --disable-spice \ 79 | --disable-vnc \ 80 | --disable-curses \ 81 | --disable-smartcard \ 82 | --disable-libnfs \ 83 | --disable-libusb \ 84 | --disable-glusterfs \ 85 | --disable-werror \ 86 | --target-list="x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu"; \ 87 | make; \ 88 | make install 89 | 90 | FROM scratch AS qemu 91 | 92 | COPY --from=qemu-build /bin/qemu-ga /bin/ 93 | COPY --from=qemu-build /bin/qemu-img /bin/ 94 | COPY --from=qemu-build /bin/qemu-io /bin/ 95 | COPY --from=qemu-build /bin/qemu-nbd /bin/ 96 | COPY --from=qemu-build /bin/qemu-pr-helper /bin/ 97 | COPY --from=qemu-build /bin/qemu-system-aarch64 /bin/ 98 | COPY --from=qemu-build /bin/qemu-system-arm /bin/ 99 | COPY --from=qemu-build /bin/qemu-system-i386 /bin/ 100 | COPY --from=qemu-build /bin/qemu-system-x86_64 /bin/ 101 | COPY --from=qemu-build /share/qemu/ /share/qemu/ 102 | COPY --from=qemu-build /lib/x86_64-linux-gnu/ /lib/x86_64-linux-gnu/ 103 | -------------------------------------------------------------------------------- /package/docker/linuxu/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG GCC_VERSION=9.2.0 2 | ARG UK_ARCH=x86_64 3 | 4 | FROM unikraft/tools:gcc${GCC_VERSION}-${UK_ARCH} AS gcc 5 | FROM ubuntu:19.10 6 | 7 | LABEL MAINTAINER="Alexander Jung " 8 | 9 | WORKDIR ${UK_APP} 10 | 11 | ARG UK_VER=staging 12 | ENV UK_APPS=/usr/src/apps \ 13 | UK_APP=${UK_APPS}/app \ 14 | UK_ROOT=/usr/src/unikraft \ 15 | UK_LIBS=/usr/src/libs \ 16 | UK_UID=1001 \ 17 | UK_GID=1001 \ 18 | TERM=xterm-256color \ 19 | PWD=${UK_APP} 20 | 21 | RUN groupadd -g ${UK_GID} unikraft; \ 22 | useradd -g ${UK_UID} -u ${UK_UID} -M unikraft; \ 23 | apt-get update; \ 24 | apt-get install -y --no-install-recommends \ 25 | build-essential \ 26 | libncurses-dev \ 27 | flex \ 28 | wget \ 29 | bison \ 30 | unzip \ 31 | python3 32 | 33 | COPY --from=gcc /bin/* /bin/ 34 | 35 | USER ${UK_UID} 36 | -------------------------------------------------------------------------------- /package/docker/linuxu/Makefile.in: -------------------------------------------------------------------------------- 1 | KERNEL_VERSIONS := 5.4.4 2 | -------------------------------------------------------------------------------- /package/docker/linuxu/config-arm: -------------------------------------------------------------------------------- 1 | CONFIG_ARCH_ARM_32=y 2 | CONFIG_MARCH_ARM32_CORTEXA7=y 3 | CONFIG_PLAT_LINUXU=y 4 | CONFIG_LINUXU_DEFAULT_HEAPMB=4 5 | CONFIG_LIBNOLIBC_UKDEBUG_ASSERT=y 6 | CONFIG_OPTIMIZE_STRIP=n 7 | CONFIG_OPTIMIZE_DEADELIM=y 8 | CONFIG_DEBUG_SYMBOLS_LVL3=y 9 | CONFIG_OPTIMIZE_COMPRESS=y 10 | -------------------------------------------------------------------------------- /package/docker/linuxu/config-x86_64: -------------------------------------------------------------------------------- 1 | CONFIG_ARCH_X86_64=y 2 | CONFIG_MARCH_X86_64_GENERIC=y 3 | CONFIG_PLAT_LINUXU=y 4 | CONFIG_LINUXU_DEFAULT_HEAPMB=4 5 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | coverage==5.5 2 | ddt==1.2.2 3 | flake8==3.7.9 4 | mock==3.0.5 5 | pre-commit==1.21.0 6 | pytest==6.2.2; python_version >= '3.5' 7 | pytest==4.6.5; python_version < '3.5' 8 | pytest-cov==2.8.1 9 | tox>=3.14.6 10 | -------------------------------------------------------------------------------- /requirements-pkg-deb.txt: -------------------------------------------------------------------------------- 1 | sphinx_rtd_theme==0.5.1 2 | virtualenv==16.7.3 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | atpbar >= 1.0.0 2 | cached_property >= 1.5.1 3 | # Required pypi modules 4 | click >= 7.0 5 | click-log >= 0.3.2 6 | colorama >= 0.4.3 7 | cookiecutter >= 1.7.0 8 | dpath >= 2.0.1 9 | fcache >= 0.4.7 10 | feedparser >= 5.2.1, < 7 11 | GitPython >= 3.1.0 12 | htmllistparse >= 0.5.2 13 | inquirer >= 2.7.0 14 | jsonschema >= 2.5.1, < 4 15 | kconfiglib >= 13.7.1 16 | memorize.py >= 1.2 17 | PyGithub >= 1.26 18 | python-dotenv >= 0.10.5, < 1 19 | PyYAML >= 5.3.1, < 6 20 | ruamel.yaml >= 0.16.12 21 | semver >= 2.10.0, < 3 22 | six >= 1.3.0, < 2 23 | toml >= 0.10.0 24 | tqdm >= 4.59.0 25 | validators >= 0.14.2 26 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | from __future__ import absolute_import 32 | from __future__ import unicode_literals 33 | 34 | from setuptools import find_packages 35 | from setuptools import setup 36 | 37 | from kraft import __description__ 38 | from kraft import __program__ 39 | 40 | 41 | with open('requirements.txt') as f: 42 | required = [x for x in f.read().splitlines() if not x.startswith("#")] 43 | 44 | 45 | def version_scheme(version): 46 | import setuptools_scm.version 47 | if version.exact: 48 | return setuptools_scm.version.guess_next_simple_semver( 49 | version.tag, 50 | retain=setuptools_scm.version.SEMVER_LEN, 51 | increment=False 52 | ) 53 | else: 54 | return version.format_next_version( 55 | setuptools_scm.version.guess_next_simple_semver, 56 | retain=setuptools_scm.version.SEMVER_MINOR 57 | ) 58 | 59 | 60 | setup( 61 | name=__program__, 62 | use_scm_version={ 63 | "version_scheme": version_scheme, 64 | "local_scheme": "dirty-tag", 65 | }, 66 | setup_requires=[ 67 | 'setuptools_scm' 68 | ], 69 | packages=find_packages(exclude=['tests.*', 'tests']), 70 | description=__description__, 71 | license='', 72 | url='https://github.com/unikraft/kraft.git', 73 | author='Alexander Jung', 74 | author_email='a.jung@lancs.ac.uk', 75 | classifiers=[ 76 | 'Development Status :: 4 - Beta', 77 | 'Intended Audience :: Science/Research', 78 | 'Intended Audience :: Developers', 79 | 'Topic :: Scientific/Engineering', 80 | 'Topic :: Software Development :: Build Tools', 81 | 'License :: OSI Approved :: BSD License', 82 | 'Programming Language :: Python :: 3', 83 | 'Programming Language :: Python :: 3.5', 84 | 'Programming Language :: Python :: 3.6', 85 | 'Programming Language :: Python :: 3.7', 86 | 'Programming Language :: Python :: 3.8', 87 | ], 88 | python_requires='>=3.5, <4', 89 | entry_points=""" 90 | [console_scripts] 91 | kraft=kraft.kraft:kraft 92 | """, 93 | scripts=[ 94 | 'scripts/qemu-guest', 95 | 'scripts/xen-guest', 96 | 'scripts/kraft-net' 97 | ], 98 | keywords=[], 99 | tests_require=['pytest', 'coveralls'], 100 | zip_safe=False, 101 | install_requires=required, 102 | include_package_data=True 103 | ) 104 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | from __future__ import absolute_import 32 | from __future__ import unicode_literals 33 | 34 | import sys 35 | 36 | if sys.version_info >= (2, 7): 37 | import unittest # noqa 38 | else: 39 | import unittest2 as unittest # noqa 40 | 41 | try: 42 | from unittest import mock 43 | except ImportError: 44 | import mock # noqa 45 | -------------------------------------------------------------------------------- /tests/helpers.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | from __future__ import absolute_import 32 | from __future__ import unicode_literals 33 | 34 | import contextlib 35 | import os 36 | 37 | 38 | @contextlib.contextmanager 39 | def cd(path): 40 | """ 41 | A context manager which changes the working directory to the given 42 | path, and then changes it back to its previous value on exit. 43 | """ 44 | prev_cwd = os.getcwd() 45 | os.chdir(path) 46 | try: 47 | yield 48 | finally: 49 | os.chdir(prev_cwd) 50 | -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unikraft/pykraft/c648d2ea1d360685502b94727bd113a13b0f82ee/tests/unit/__init__.py -------------------------------------------------------------------------------- /tests/unit/cli_test.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: BSD-3-Clause 2 | # 3 | # Authors: Alexander Jung 4 | # 5 | # Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved. 6 | # 7 | # Redistribution and use in source and binary forms, with or without 8 | # modification, are permitted provided that the following conditions 9 | # are met: 10 | # 11 | # 1. Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # 2. Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # 3. Neither the name of the copyright holder nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | # POSSIBILITY OF SUCH DAMAGE. 31 | from __future__ import absolute_import 32 | from __future__ import unicode_literals 33 | 34 | from click.testing import CliRunner 35 | 36 | from .. import unittest 37 | from kraft import kraft 38 | 39 | 40 | class CLITestCase(unittest.TestCase): 41 | def test_version(self): 42 | runner = CliRunner() 43 | result = runner.invoke(kraft.kraft, ['--version']) 44 | assert result.exit_code == 0 45 | assert 'kraft, version' in result.output 46 | 47 | def test_help(self): 48 | runner = CliRunner() 49 | result = runner.invoke(kraft.kraft, ['--help']) 50 | assert result.exit_code == 0 51 | assert 'Usage: kraft [OPTIONS] COMMAND [ARGS]...' in result.output 52 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py37,pre-commit 3 | 4 | [testenv] 5 | usedevelop=True 6 | whitelist_externals=mkdir 7 | passenv = 8 | LD_LIBRARY_PATH 9 | setenv = 10 | HOME=/tmp 11 | deps = 12 | -rrequirements.txt 13 | -rrequirements-dev.txt 14 | commands = 15 | mkdir -p .coverage-binfiles 16 | py.test -v \ 17 | --cov=compose \ 18 | --cov-report html \ 19 | --cov-report term \ 20 | --cov-config=tox.ini \ 21 | {posargs:tests} 22 | 23 | [testenv:pre-commit] 24 | skip_install = True 25 | deps = 26 | pre-commit 27 | commands = 28 | pre-commit install 29 | pre-commit run --all-files 30 | 31 | # Coverage configuration 32 | [run] 33 | branch = True 34 | data_file = .coverage-binfiles/.coverage 35 | 36 | [report] 37 | show_missing = true 38 | 39 | [html] 40 | directory = coverage-html 41 | # end coverage configuration 42 | 43 | [flake8] 44 | max-line-length = 105 45 | # Set this high for now 46 | max-complexity = 11 47 | exclude = package 48 | 49 | [pytest] 50 | addopts = --tb=short -rxs 51 | --------------------------------------------------------------------------------