Skip to content

Commit

Permalink
Factorize Python packages
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Jul 25, 2017
1 parent cbd1aed commit 968e93f
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 45 deletions.
13 changes: 10 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,29 @@ test_script:
after_build:
- cmake --build . --config Release --target package -- /v:m /logger:%MSBuildLogger%
- cd api\python
- python.exe .\setup.py sdist --formats=zip && exit 0 # Ignore warnings...
- ps: gci dist\*.zip | % { rename-item –path $_.Fullname –Newname ( "windows_" + $env:PLATFORM + "_" + $_.basename + "_py" + $env:PYTHON_VERSION + $_.extension) }
- python.exe .\setup.py bdist_egg && exit 0 # Ignore warnings...
- ps: if ($env:APPVEYOR_REPO_TAG -eq "true") { python.exe .\setup.py sdist --formats=zip } # Ignore warnings...
- ps: if ($env:APPVEYOR_REPO_TAG -eq "false") { python.exe .\setup.py sdist --dev --formats=zip } # Ignore warnings...
- cd ..\..
- bash ./.github/deploy.sh

artifacts:
- path: '*.zip'
name: sdk

- path: 'api\python\dist\*.zip'
name: python-src

- path: 'api\python\dist\*.egg'
name: python-egg


deploy:
description: "LIEF version $(APPVEYOR_REPO_TAG_NAME)"
provider: GitHub
auth_token:
secure: FU9CGrZ1lm0VDHUZg6zvTL4tidluDvRegVUTehCRo2xgiOv6NZePi7TdSy5CsOdG
artifact: /.*\.zip/
artifact: sdk;python-src;python-egg
draft: false
prerelease: false
force_update: true
Expand Down
6 changes: 4 additions & 2 deletions .github/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ fi

git ls-files -v


/bin/cp -rf $LIEF_BUILDDIR/api/python/dist/*.zip .
/bin/cp -rf $LIEF_BUILDDIR/api/python/dist/*.egg .

if [[ -n $APPVEYOR_JOB_ID ]]; then
/bin/cp -rf $LIEF_BUILDDIR/api/python/dist/*.zip .
/bin/cp -rf $LIEF_BUILDDIR/*.zip .
else
/bin/cp -rf $LIEF_BUILDDIR/api/python/dist/*.tar.gz .
/bin/cp -rf $LIEF_BUILDDIR/*.tar.gz .
fi

Expand Down
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ sudo: required
cache:
- apt
- ccache
- $HOME/.pyenv
- build/rang_cpp_color-prefix
- build/mbed_tls
- build/libjson-prefix
Expand Down Expand Up @@ -148,9 +149,9 @@ after_success:
- sudo $PYTHON_BINARY -m pip install setuptools
- sudo $PYTHON_BINARY -m pip install --upgrade setuptools
- cd api/python
- $PYTHON_BINARY setup.py sdist
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then bash -c 'cd dist && for f in *.tar.gz; do mv $f "linux_${f%.tar.gz}_py${PYTHON_VERSION}.tar.gz"; done' ;fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then bash -c 'cd dist && for f in *.tar.gz; do mv $f "osx_${f%.tar.gz}_py$PYTHON_VERSION.tar.gz"; done' ;fi
- $PYTHON_BINARY setup.py bdist_egg
- if [[ -z "$TRAVIS_TAG" ]]; then $PYTHON_BINARY setup.py sdist --dev --formats=zip ;fi
- if [[ -n "$TRAVIS_TAG" ]]; then $PYTHON_BINARY setup.py sdist --formats=zip ;fi
- cd $TRAVIS_BUILD_DIR
- bash ./.github/deploy.sh

Expand All @@ -161,7 +162,8 @@ deploy:
- secure: "RlyaagAWt1BrcOBDSpmOnP+/FYUJqQiURlWw7JWvuBBWBDPBta+WI1zZvH6x5H+1bm8F77LrGdU1mRES/MAlhzb8o/VHgOAFhu2si/A+A7Xa9fAIOQw12jcGbtZQUQ7HCkRfa5VGrW4IlMI5+FJ7uFUU2lLoWOsA3u8pLEwApbdiB/LmtEY+kKhXzX0bT3h9cZATDWTeEoopXOseaBmTFC9IUATE3Ht1wVP49wXRUZHNJA10PJILbKtR1OITCAKm0iu1rVdLhoMzqH3T2dXDZ5ykF9TuYQaXJzKMFHaAeSe135JYOiIEWUUiif80q/mTWXiJAQ6gQXXOyDVu6R0Hi03TKsWXPlEKDBpDCRDu58I2hJyxsc5MPbFg8IAjraXkOLIQkIpgBOfV0JYVihikOLTfbCBKO+w9RFwrEVy91YsKCDosEAUa9p5nyRoV+k9Epmr/2atlHY8z7RyycB2fNQv3/NkHX8jZesiUFUwu5SHaZD76mKGELEZlf7LW8XwL4Cwfa2OB2vsKFcN1qyGUmXS57MODVBAUubQY4oTFwFJJUv28s06KA6BfZE4QqAeWoRSslDr9ORLUlsHHoCpZrAAY0uyl8kff/jL8IJMd8qng9bBTLu8hiK0yyQWKkebMvMWXhvAjssXeqWt3OeL2mssbUG5N1pXt6eHFmQvxqzs="
file_glob: true
file:
- ${TRAVIS_BUILD_DIR}/build/api/python/dist/*.tar.gz
- ${TRAVIS_BUILD_DIR}/build/api/python/dist/*.egg
- ${TRAVIS_BUILD_DIR}/build/api/python/dist/*.zip
- ${TRAVIS_BUILD_DIR}/build/*.tar.gz
skip_cleanup: true
on:
Expand Down
25 changes: 24 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ include(Findcppcheck)
include(CppcheckTargets)
include(ExternalProject)

find_package(Git REQUIRED)

execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE LIEF_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
COMMAND ${GIT_EXECUTABLE} rev-list --count ${LIEF_COMMIT_HASH}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE LIEF_COMMIT_COUNT
OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE LIEF_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)


# LIEF version
set(LIEF_VERSION_MAJOR 0)
set(LIEF_VERSION_MINOR 7)
Expand Down Expand Up @@ -47,7 +71,6 @@ endif()

# Dependencies
# ============
find_package(Git REQUIRED)

# Json
# ----
Expand Down
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Latest **tagged** version can be downloaded in the [Release](https://github.com/

Pre-built packages from the [master](https://github.com/lief-project/LIEF/tree/master)'s **latest commit** are automatically uploaded in the [*lief-project/packages*](https://github.com/lief-project/packages) repository:

:warning: *master* packages have a same name as *tagged* packages (e.g. ``LIEF-0.7.0-Linux.tar.gz``, ``windows_x64_lief-0.7.0_py3.5.zip``) :warning:
:warning: *master* **SDK** packages have a same name as *tagged* packages (e.g. ``LIEF-0.7.0-Linux.tar.gz``) :warning:

:warning: *master* **Python** package has ``dev`` suffix (e.g. ``pylief-0.7.0.dev.zip``) :warning:

<table>
<tr><td colspan="4"><img src="https://img.shields.io/badge/release-master-brightgreen.svg?style=default"></td></tr>
Expand All @@ -61,24 +63,7 @@ Pre-built packages from the [master](https://github.com/lief-project/LIEF/tree/m
</tr>

<tr>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/linux_lief-0.7.0_py2.7.tar.gz">Python 2.7</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/windows_x86_lief-0.7.0_py2.7.zip">Python 2.7</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/windows_x64_lief-0.7.0_py2.7.zip">Python 2.7</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/osx_lief-0.7.0_py2.7.tar.gz">Python 2.7</a></td>
</tr>

<tr>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/linux_lief-0.7.0_py3.5.tar.gz">Python 3.5</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/windows_x86_lief-0.7.0_py3.5.zip">Python 3.5</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/windows_x64_lief-0.7.0_py3.5.zip">Python 3.5</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/osx_lief-0.7.0_py3.5.tar.gz">Python 3.5</a></td>
</tr>

<tr>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/linux_lief-0.7.0_py3.6.tar.gz">Python 3.6</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/windows_x86_lief-0.7.0_py3.6.zip">Python 3.6</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/windows_x64_lief-0.7.0_py3.6.zip">Python 3.6</a></td>
<td><a href="https://github.com/lief-project/packages/raw/lief-master-latest/osx_lief-0.7.0_py3.6.tar.gz">Python 3.6</a></td>
<td colspan="4"><p align="center"><a href="https://github.com/lief-project/packages/raw/lief-master-latest/pylief-0.7.0.dev.zip">Python</a></p></td>
</tr>

<tr><td colspan="4"><b><img src="https://img.shields.io/badge/release-0.7.0-brightgreen.svg?style=default"></b></td></tr>
Expand Down
17 changes: 12 additions & 5 deletions api/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(pyLIEF PRIVATE ${PYLIEF_COMPILE_FLAGS})
endif()

set_target_properties(pyLIEF PROPERTIES PREFIX "" OUTPUT_NAME "lief")
#set_target_properties(pyLIEF PROPERTIES PREFIX "" OUTPUT_NAME "lief")
set_target_properties(pyLIEF PROPERTIES PREFIX "" OUTPUT_NAME "_pylief")
add_dependencies(pyLIEF pybind11)

if(APPLE)
Expand All @@ -170,12 +171,18 @@ endif()
target_link_libraries(pyLIEF PUBLIC ${PYLIEF_DEPS_LIBRARIES})

add_custom_command(TARGET pyLIEF POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pyLIEF> ${PROJECT_BINARY_DIR}/api/python/
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pyLIEF> ${PROJECT_BINARY_DIR}/api/python/lief
)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in" "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" "${CMAKE_CURRENT_BINARY_DIR}/__init__.py")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/README.in" "${CMAKE_CURRENT_BINARY_DIR}/README")
if (MSVC)
add_custom_command(TARGET pyLIEF POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pyLIEF> ${CMAKE_CURRENT_BINARY_DIR}
)
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in" "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" "${CMAKE_CURRENT_BINARY_DIR}/lief/__init__.py")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/README.in" "${CMAKE_CURRENT_BINARY_DIR}/README")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/MANIFEST.in.in" "${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in")

MESSAGE(STATUS "OS: ${CMAKE_HOST_SYSTEM}")
Expand Down
11 changes: 11 additions & 0 deletions api/python/__init__.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python

import sys
import _pylief
from _pylief import *

__version__ = _pylief.__version__

sys.modules["lief.PE"] = _pylief.PE
sys.modules["lief.ELF"] = _pylief.ELF
sys.modules["lief.MachO"] = _pylief.MachO
7 changes: 5 additions & 2 deletions api/python/pyLIEF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
* limitations under the License.
*/
#include "LIEF/logging.hpp"
#include "LIEF/version.h"
#include "pyLIEF.hpp"

PYBIND11_PLUGIN(lief) {
PYBIND11_PLUGIN(_pylief) {

py::module LIEF_module("lief", "Python API for LIEF");
py::module LIEF_module("_pylief", "Python API for LIEF");

LIEF_module.attr("__version__") = py::str(LIEF_VERSION);

init_LIEF_iterators(LIEF_module);

Expand Down

0 comments on commit 968e93f

Please sign in to comment.