Skip to content

Commit

Permalink
Create pip package from tu-collector
Browse files Browse the repository at this point in the history
  • Loading branch information
csordasmarton committed Mar 22, 2019
1 parent 8a5265d commit c723d68
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 7 deletions.
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ package: clean_package build_dir gen-docs thrift userguide build_plist_to_html b
ln -s $(CC_BUILD_LIB_DIR)/plist_to_html/PlistToHtml.py $(CC_BUILD_BIN_DIR)/plist-to-html

# Copy tu_collector files.
cp -r $(CC_TOOLS)/tu_collector/tu_collector $(CC_BUILD_LIB_DIR) && \
cp -r $(CC_TOOLS)/tu_collector/build $(CC_BUILD_DIR)/tu_collector && \
ln -s $(CC_BUILD_DIR)/tu_collector/bin/tu-collector $(CC_BUILD_DIR)/bin/tu-collector
cp -r $(CC_TOOLS)/tu_collector/build/tu_collector/tu_collector $(CC_BUILD_LIB_DIR)

# Copy generated thrift files.
mkdir -p $(CC_BUILD_GEN_DIR) && \
Expand Down Expand Up @@ -163,7 +161,7 @@ build_plist_to_html:
$(MAKE) -C $(CC_TOOLS)/plist_to_html

build_tu_collector:
$(MAKE) -C $(CC_TOOLS)/tu_collector
$(MAKE) -C $(CC_TOOLS)/tu_collector build

venv:
# Create a virtual environment which can be used to run the build package.
Expand Down Expand Up @@ -215,7 +213,7 @@ clean_plist_to_html:
rm -rf $(CC_TOOLS)/plist_to_html/build

clean_tu_collector:
rm -rf $(CC_TOOLS)/tu_collector/build
$(MAKE) -C $(CC_TOOLS)/tu_collector clean

clean_travis:
# Clean CodeChecker config files stored in the users home directory.
Expand Down
3 changes: 3 additions & 0 deletions tools/tu_collector/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
dist/
tu_collector.egg-info
10 changes: 10 additions & 0 deletions tools/tu_collector/.pypirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[distutils]
index-servers =
pypi
testpypi

[pypi]
repository: https://upload.pypi.org/legacy/

[testpypi]
repository: https://test.pypi.org/legacy/
39 changes: 39 additions & 0 deletions tools/tu_collector/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
University of Illinois/NCSA Open Source License

Copyright (c) 2015 Ericsson.
All rights reserved.

Developed by:

CodeChecker Team

Ericsson

http://www.ericsson.com

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal with
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimers in the
documentation and/or other materials provided with the distribution.

* Neither the names of the CodeChecker Team, Ericsson, nor the names of
its contributors may be used to endorse or promote products derived
from this Software without specific prior written permission.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
SOFTWARE.

2 changes: 2 additions & 0 deletions tools/tu_collector/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.md
include *.txt
30 changes: 28 additions & 2 deletions tools/tu_collector/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,39 @@
BUILD_DIR = build
BIN_DIR = $(BUILD_DIR)/bin

TU_COLLECTOR_DIR = $(BUILD_DIR)/tu_collector

PKG_NAME := $(shell python setup.py --name)
PKG_VERSION := $(shell python setup.py --version)

ACTIVATE_VENV ?= . venv/bin/activate

venv:
# Create a virtual environment which can be used to run the build package.
virtualenv -p python2 venv && $(ACTIVATE_VENV)

default: all

all: package

package:
mkdir -p $(BIN_DIR)
cp tu_collector/tu_collector.py $(BIN_DIR)/tu-collector
# Install package in 'development mode'.
python setup.py develop

build:
python setup.py build --build-purelib $(TU_COLLECTOR_DIR)

dist:
# Create a source distribution.
python setup.py sdist

upload_test: dist
# Upload package to the TestPyPI repository.
twine upload -r testpypi dist/$(PKG_NAME)-$(PKG_VERSION).tar.gz

upload: dist
# Upload package to the PyPI repository.
twine upload -r pypi dist/$(PKG_NAME)-$(PKG_VERSION).tar.gz

clean:
rm -rf $(BUILD_DIR)
Expand Down
49 changes: 49 additions & 0 deletions tools/tu_collector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# tu-collector
`tu-collector` is a python tool which collects the source files constituting a
translation unit. This script does this action based on a compilation database
JSON file. The output of the script is a ZIP package with the collected
sources.

## Install guide
```sh
# Create a Python virtualenv and set it as your environment.
make venv
source $PWD/venv/bin/activate

# Build and install tu-collector package.
make package
```

## Usage
```sh
usage: tu_collector.py [-h] (-b COMMAND | -l LOGFILE) -z ZIP [-f FILTER]

This script collects all the source files constituting specific translation
units. The files are written to a ZIP file which will contain the sources
preserving the original directory hierarchy.

optional arguments:
-h, --help show this help message and exit
-z ZIP, --zip ZIP Output ZIP file.
-f FILTER, --filter FILTER
This flag restricts the collection on the build
actions of which the compiled source file matches this
path. E.g.: /path/to/*/files

log arguments:
Specify how the build information database should be obtained. You need to
specify either an already existing log file, or a build command which will
be used to generate a log file on the fly.

-b COMMAND, --build COMMAND
Execute and record a build command. Build commands can
be simple calls to 'g++' or 'clang++'.
-l LOGFILE, --logfile LOGFILE
Use an already existing JSON compilation command
database file specified at this path.
```

## License

The project is licensed under University of Illinois/NCSA Open Source License.
See LICENSE.TXT for details.
37 changes: 37 additions & 0 deletions tools/tu_collector/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="tu_collector",
version="0.1.0",
author='CodeChecker Team (Ericsson)',
description="Collect the source files constituting a translation unit.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Ericsson/CodeChecker",
keywords=['tu-collector', 'translation unit', 'collector',
'compilation database'],
license='LICENSE.txt',
packages=setuptools.find_packages(),
include_package_data=True,
classifiers=[
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: University of Illinois/NCSA Open Source License",
"Operating System :: MacOS",
"Operating System :: POSIX",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
],
entry_points={
'console_scripts': [
'tu-collector = tu_collector.tu_collector:main'
]
},
)

0 comments on commit c723d68

Please sign in to comment.