Skip to content

Commit

Permalink
Added post_install method for building Docker images for backends (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTimperley committed Jan 30, 2020
1 parent 76ee80d commit d02d367
Show file tree
Hide file tree
Showing 64 changed files with 87 additions and 33 deletions.
4 changes: 0 additions & 4 deletions Dockerfile.debug

This file was deleted.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graft lib/kaskara/clang/backend
19 changes: 16 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ A simple, unified API for performing static analysis on programs in a variety
of languages. Kaskara avoids dependency hell when analysing programs by making
use of Docker.

* Kaskara currently provides C and C++ analysis support via its Clang driver.
* Python analysis support is planned for the end of December 2019.

* Kaskara currently provides C and C++ analysis support via its Clang driver,
* As of January 2020, Kaskara now provides support for Python analysis.
* Support for analysis of Java code is planned for February 2020.

.. image:: https://upload.wikimedia.org/wikipedia/commons/f/fc/Kaskara-Sword.jpg


Post-Installation
-----------------

After installing the `kaskara` package as a dependency of your project, you
should execute the following code to complete the installation by building the
support backends:

.. code:: python
import kaskara
kaskara.post_install()
7 changes: 0 additions & 7 deletions debug.sh

This file was deleted.

2 changes: 2 additions & 0 deletions python/kaskara/__init__.py → lib/kaskara/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from .insertions import InsertionPoint
from .statements import Statement
from .loops import ProgramLoops
from .post_install import post_install
from . import clang
from . import python


_logger.disable('kaskara')
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from .analysis import ClangFunction
from .analyser import ClangAnalyser
from .post_install import post_install
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions lib/kaskara/clang/backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**
!CMakeLists.txt
!cmake
!src
!scripts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@ add_definitions(${CLANG_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS})
add_definitions(-fno-rtti -std=c++17)

add_subdirectory(cpp)
add_subdirectory(src)
19 changes: 8 additions & 11 deletions Dockerfile → lib/kaskara/clang/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,20 @@ ADD . /tmp/kaskara
RUN mkdir /tmp/kaskara/build && \
cd /tmp/kaskara/build && \
cmake .. && \
make -j $(nproc)
make -j4
RUN mkdir -p /opt/kaskara/bin \
&& cp /tmp/kaskara/build/cpp/kaskara-loop-finder /opt/kaskara/bin \
&& cp /tmp/kaskara/build/cpp/kaskara-statement-finder /opt/kaskara/bin \
&& cp /tmp/kaskara/build/cpp/kaskara-function-scanner /opt/kaskara/bin \
&& cp /tmp/kaskara/build/cpp/kaskara-insertion-point-finder /opt/kaskara/bin \
&& cp /tmp/kaskara/build/cpp/kaskara-snippet-extractor /opt/kaskara/bin
&& cp /tmp/kaskara/build/src/kaskara-loop-finder /opt/kaskara/bin \
&& cp /tmp/kaskara/build/src/kaskara-statement-finder /opt/kaskara/bin \
&& cp /tmp/kaskara/build/src/kaskara-function-scanner /opt/kaskara/bin \
&& cp /tmp/kaskara/build/src/kaskara-insertion-point-finder /opt/kaskara/bin \
&& cp /tmp/kaskara/build/src/kaskara-snippet-extractor /opt/kaskara/bin
RUN mkdir -p /opt/kaskara/clang \
&& cp -r /usr/local/lib/clang/5.0.0/include/* /opt/kaskara/clang

# install scripts
ADD scripts /opt/kaskara/scripts

FROM alpine:3.7 as python
FROM alpine:3.7 as minimal
COPY --from=cpp /opt/kaskara /opt/kaskara
COPY scripts /opt/kaskara/scripts
WORKDIR /opt/kaskara
COPY python /opt/kaskara/python
COPY setup.py /opt/kaskara
ENV PATH "/opt/kaskara/scripts:${PATH}"
VOLUME /opt/kaskara
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions lib/kaskara/clang/post_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""
This module is responsible for installing the backend for the C++ plugin.
"""
__all__ = ('post_install,')

import contextlib
import pkg_resources

from loguru import logger
import docker

IMAGE_NAME: str = 'christimperley/kaskara:cpp'


def post_install() -> None:
"""Installs the C++ plugin backend."""
logger.info('installing C++ plugin backend')
backend_directory = pkg_resources.resource_filename(__name__, 'backend')
logger.debug(f'backend located at: {backend_directory}')
with contextlib.closing(docker.from_env()) as docker_client:
logger.debug('prepared Docker client for C++ backend installation')
image, _ = docker_client.images.build(path=backend_directory,
tag=IMAGE_NAME,
pull=True)
logger.info(f"built Docker image for C++ plugin: {image.tags}")
logger.info('installed C++ plugin backend')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions lib/kaskara/post_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""
This module is used to install Kaskara's various language backends following
the installation of the Kaskara Python package via setuptools/pip.
"""
__all__ = ('post_install',)

from loguru import logger

from .clang import post_install as post_install_clang


def post_install() -> None:
logger.info('performing post-installation of Kaskara')
post_install_clang()
logger.info('completed post-installation of Kaskara')
3 changes: 2 additions & 1 deletion python/kaskara/project.py → lib/kaskara/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from .container import ProjectContainer

KASKARA_IMAGE = 'squareslab/kaskara'
# FIXME the plugin container shouldn't be launched from here
KASKARA_IMAGE = 'christimperley/kaskara:cpp'


@attr.s(frozen=True, slots=True, auto_attribs=True)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion python/kaskara/version.py → lib/kaskara/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '0.0.9'
__version__ = '0.1.0'
10 changes: 6 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ classifiers =
Programming Language :: Python :: 3.8

[options]
include_package_data = True
python_requires = >= 3.6
install_requires =
astor ~= 0.8.1
Expand All @@ -27,12 +28,13 @@ install_requires =
loguru ~= 0.3.2
requests ~= 2.22.0
sourcelocation ~= 1.0.2
importlib_resources >= 1.0.2
package_dir =
=python
=lib
packages = find:

[options.packages.find]
where = python
where = lib

[aliases]
test = pytest
Expand All @@ -57,8 +59,8 @@ commands =
# NOTE nasty hack to prevent tox failing to install deps
# https://github.com/tox-dev/tox/issues/149
pip install {toxinidir}
mypy python
pycodestyle python
mypy lib
pycodestyle lib
pytest

[mypy]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import setup, find_packages

MODULE_FILE = \
os.path.join(os.path.dirname(__file__), 'python/kaskara/version.py')
os.path.join(os.path.dirname(__file__), 'lib/kaskara/version.py')
VERSION_REGEX = \
r"__version__\s+=\s+['|\"](.*)['|\"]\s*"

Expand Down

0 comments on commit d02d367

Please sign in to comment.