Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Add the dependency analyser with the go toolchain to kraft (V2) #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kraft/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .init import init
from .lib.bump import bump as libbump
from .lib.init import init as libinit
from .devel.dependency import dependency as develdependency
from .list import list
from .run import run
from .up import up
71 changes: 71 additions & 0 deletions kraft/commands/devel/dependency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Authors: Gaulthier Gain <[email protected]>
#
# Copyright (c) 2020, Université de Liège., ULiege. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
from __future__ import absolute_import
from __future__ import unicode_literals

import os
import sys

import click

from kraft.commands.list import update
from kraft.components.library import Library
from kraft.components.types import RepositoryType
from kraft.context import kraft_context
from kraft.errors import KraftError
from kraft.logger import logger
from kraft.utils import op, dir

import platform
import subprocess

TOOLS_PATH = './package/docker/gotools/tools_'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be dependent on where how the package is installed, the extra binaries can be referenced globally, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, using an absolute path?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the TOOLS_PATH may just need to call a method to determine where the binaries were installed on the system. I will check this.


@click.command('dependency', short_help='Gather the dependencies of a specific application.', context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True)) # noqa: C901
@click.pass_context
def dependency(ctx):
"""
Gather the dependencies of a specific application.
"""
try:

path = TOOLS_PATH + platform.system()
if not op.isExecutable(path):
op.execute_command('chmod +x', [path])

# Execute the toolchain with unparsed arguments
op.execute_command(path, ctx.args)

except KraftError as e:
logger.critical(e)
sys.exit(1)
11 changes: 11 additions & 0 deletions kraft/kraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from kraft.commands import build
from kraft.commands import clean
from kraft.commands import configure
from kraft.commands import develdependency
from kraft.commands import init
from kraft.commands import libbump
from kraft.commands import libinit
Expand Down Expand Up @@ -87,9 +88,18 @@ def lib(ctx):
"""
pass

@click.group(name='devel', short_help='Unikraft devel commands.')
@kraft_context
def devel(ctx):
"""
Unikraft developer sub-commands useful for maintaing and working
directly with Unikraft source code.
"""
pass

lib.add_command(libinit)
lib.add_command(libbump)
devel.add_command(develdependency)

kraft.add_command(up)
kraft.add_command(run)
Expand All @@ -99,3 +109,4 @@ def lib(ctx):
kraft.add_command(clean)
kraft.add_command(configure)
kraft.add_command(lib)
kraft.add_command(devel)
13 changes: 13 additions & 0 deletions kraft/utils/op.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Authors: Alexander Jung <[email protected]>
# Gaulthier Gain <[email protected]>
#
# Copyright (c) 2020, NEC Europe Ltd., NEC Corporation. All rights reserved.
#
Expand Down Expand Up @@ -32,10 +33,22 @@
from __future__ import unicode_literals

import os
import stat
import shlex
import subprocess

from kraft.logger import logger

def isExecutable(filepath):
"""Check if a file is executable."""
stats = os.stat(filepath)
return bool(stats.st_mode & stat.S_IXUSR)


def execute_command(command, parameters=' '):
"""Run a specific command on the host."""
subprocess.call(shlex.split(command + ' ' + ' '.join(parameters)))


def merge_dicts(x, y):
z = x.copy()
Expand Down
45 changes: 45 additions & 0 deletions package/docker/Dockerfile.gotools
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Authors: Gaulthier Gain <[email protected]>
#
# Copyright (c) 2020, Université de Liège., ULiege. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
ARG GOLANG_VERSION=1.14.4
ARG SHARED_DIR=/usr/shared

FROM golang:${GOLANG_VERSION}

RUN mkdir /usr/src/gotools
COPY gotools/tools_Linux /usr/src/gotools
WORKDIR /usr/src/gotools

RUN mkdir /usr/shared
VOLUME [${SHARED_DIR}]

RUN set -xe
RUN chmod +x ./tools_Linux
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely this file can be put into the Dockerfile verbatim as it won't be run outside

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just seen this is a binary. The Dockerfile is intended to build go files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by binary? Creating the binary from sources only in the Dockerfile ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

ENTRYPOINT ["./tools_Linux"]
4 changes: 4 additions & 0 deletions package/docker/Dockerfile.kraft
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

ARG UK_ARCH=x86_64
ARG GCC_VERSION=9.2.0
ARG GO_VERSION=1.14.4

FROM unikraft/gcc:${GCC_VERSION}-${UK_ARCH} AS gcc
FROM unikraft/gotools:${GO_VERSION} AS gotools

LABEL MAINTAINER="Alexander Jung <[email protected]>"

Expand All @@ -43,6 +45,8 @@ COPY --from=gcc /lib/ /lib
COPY --from=gcc /include/ /include
COPY --from=gcc /libexec/ /libexec

COPY --from=gotools /usr/src/gotools /usr/src/gotools

COPY . /usr/src/kraft

WORKDIR /usr/src/unikraft/apps/app
Expand Down
20 changes: 20 additions & 0 deletions package/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ else
$(DOCKER_BUILD_EXTRA) $(DOCKERDIR)
endif

# GO build targets
GO_VERSION ?= 1.14.4

.PHONY: docker-gotools
docker-gotools: IMAGE_NAME ?= $(ORG)/gotools:$(GO_VERSION)
docker-gotools:
ifneq (,$(findstring help,$(MAKECMDGOALS)))
@echo "Usage: [IMAGE_NAME=...] $(MAKE) $@ "
@echo " "
@echo
else
$(DOCKER) build \
--build-arg GO_VERSION=$(GO_VERSION) \
--tag $(IMAGE_NAME) \
--cache-from $(ORG)/gotools:$(GO_VERSION) \
--cache-from $(IMAGE_NAME) \
--file $(DOCKERDIR)/Dockerfile.gotools \
$(DOCKER_BUILD_EXTRA) $(DOCKERDIR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may have to be $(KRAFTDIR) and not $(DOCKERDIR), but I will check when I run the build myself

endif

# GCC build targets
GCC_VERSION ?= 9.2.0
BINUTILS_VERSION ?= 2.31.1
Expand Down
Binary file added package/docker/gotools/tools_Darwin
Binary file not shown.
Binary file added package/docker/gotools/tools_Linux
Binary file not shown.