如何使用CPack构建debian包来执行setup.py? [英] How to build debian package with CPack to execute setup.py?

查看:789
本文介绍了如何使用CPack构建debian包来执行setup.py?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我的项目只有 .cpp 文件被编译成不同的二进制文件,我设法配置 CPack 来构建一个正确的 debian包没有任何问题。



最近我写了几个python应用程序,并将它们添加到项目,以及一些自定义模块,我也想结合包装。



写了一个 setup.py 脚本后,我想知道如何将这些文件添加到 CPack 配置,当用户使用 dpkg -i软件包在系统上安装软件包时, setup.py deb



我很难找到有关如何配置CPack来安装自定义python应用程序/模块的相关信息。有没有人试过这个?

解决方案

我想出了一种方法,但它不是很简单。



这种方法的想法是使用 postinst



CMakeLists.txt 中定义项目,您需要表示 CPACK 将用于生成 .deb软件包。有一些变量需要用与包本身相关的信息填充,但是一个名为 CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA 的变量是非常重要的,因为它用于指定 postinst prerm ,这是 dpkg 在安装/删除软件包时自动执行的 debian包装系统的标准脚本。 / p>

主要 CMakeLists.txt 的某一点,应该有这样的:

  add_subdirectory(name_of_python_app)

设定(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)

(CPACK_PACKAGE_VENDORACME)
设置(CPACK_PACKAGE_DESCRIPTION_SUMMARYfake-package - ACME提供给您)
设置(CPACK_PACKAGE_VERSION1.0.2 )
set(CPACK_PACKAGE_VERSION_MAJOR1)
set(CPACK_PACKAGE_VERSION_MINOR0)
set(CPACK_PACKAGE_VERSION_PATCH2)
SET(CPACK_SYSTEM_NAMEi386)

set(CPACK_GENERATORDEB)
set(CPACK_DEBIAN_PACKAGE_MAINTAINERACME Technology)
set(CPACK_DEBIAN_PACKAGE_DEPENDSlibc6(> = 2.3.1-6),libgcc1(> = 1:3.4 .2-12),python2.6,libboost-program-options1.40.0(> = 1.40.0))
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA$ {CMAKE_SOURCE_DIR} / name_of_python_app / postinst; $ {CMAKE_SOURCE_DIR} / name_of_python_app / prerm;)
set(CPACK_SET_DESTDIRON)

include(CPack)

这些变量中的一些可选,但我填写的信息用于教育目的。



让我们来看看脚本:



postinst

 #!/ bin / sh 
#postinst script for fake_python_app

set -e

cd / usr / share / pyshared / fake_package
sudo python setup.py install

prerm

 #!/ bin / sh 
#prerm script

#删除安装的所有文件: ./setup.py install
sudo rm -rf / usr / share / pyshared / fake_package
sudo rm / usr / local / bin / fake_python_app

如果您注意到,脚本 postinst 输入 / usr / share / pyshared / fake_package 并执行位于此处的 setup.py ,以在系统上安装应用程序。这个文件从哪里来,怎么结束呢?此文件由您创建,并且将在您的软件包安装在系统上时复制到该位置。此操作在 name_of_python_app / CMakeLists.txt 中配置:

 安装FILES setup.py 
DESTINATION/ usr / share / pyshared / fake_package


install(FILES __init__.py
DESTINATION/ usr / share / pyshared / fake_package / fake_package


install(FILES fake_python_app
DESTINATION/ usr / share / pyshared / fake_package / fake_package


install(FILES fake_module_1.py
DESTINATION/ usr / share / pyshared / fake_package / fake_package


安装(FILES fake_module_2.py
DESTINATION / usr / share / pyshared / fake_package / fake_package

,除了python应用程序我想安装还有2自定义python模块,我写,也需要安装。下面我将描述最重要的文件的内容:



setup.py

 #!/ usr / bin / env python 
from distutils.core import setup

setup(name ='fake_package',
version ='1.0.5',
description ='fake-package'使用的Python模块,
py_modules = ['fake_package.fake_module_1','fake_package.fake_module_2'],
scripts = ['fake_package / fake_python_app']

_ _。py :是一个空文件。



fake_python_app :您的python应用程序将安装在/ usr / local / bin



这真是太棒了!


Until now, my project had only .cpp files that were compiled into different binaries and I managed to configure CPack to build a proper debian package without any problems.

Recently I wrote a couple of python applications and added them to the project, as well as some custom modules that I would also like to incorporate to the package.

After writing a setup.py script, I'm wondering how to add these files to the CPack configuration in a way that setup.py get's executed automatically when the user installs the package on the system with dpkg -i package.deb.

I'm struggling to find relevant information on how to configure CPack to install custom python applications/modules. Has anyone tried this?

解决方案

I figured out a way to do it but it's not very simple. I'll do my best to explain the procedure so please be patient.

The idea of this approach is to use postinst and prerm to install and remove the python application from the system.

In the CMakeLists.txt that defines the project, you need to state that CPACK is going to be used to generate a .deb package. There's some variables that need to be filled with info related to the package itself, but one named CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA is very important because it's used to specify the location of postinst and prerm, which are standard scripts of the debian packaging system that are automatically executed by dpkg when the package is installed/removed.

At some point of your main CMakeLists.txt you should have something like this:

add_subdirectory(name_of_python_app)

set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)

set(CPACK_PACKAGE_NAME "fake-package")
set(CPACK_PACKAGE_VENDOR "ACME")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake-package - brought to you by ACME")
set(CPACK_PACKAGE_VERSION "1.0.2")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "2")
SET(CPACK_SYSTEM_NAME "i386")

set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ACME Technology")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3.1-6), libgcc1 (>= 1:3.4.2-12), python2.6, libboost-program-options1.40.0 (>= 1.40.0)")
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/name_of_python_app/postinst;${CMAKE_SOURCE_DIR}/name_of_python_app/prerm;")
set(CPACK_SET_DESTDIR "ON")

include(CPack)

Some of these variables are optional, but I'm filling them with info for educational purposes.

Now, let's take a look at the scripts:

postinst:

#!/bin/sh
# postinst script for fake_python_app

set -e

cd /usr/share/pyshared/fake_package
sudo python setup.py install

prerm:

#!/bin/sh
# prerm script
#
# Removes all files installed by: ./setup.py install
sudo rm -rf /usr/share/pyshared/fake_package
sudo rm /usr/local/bin/fake_python_app

If you noticed, script postinst enters at /usr/share/pyshared/fake_package and executes the setup.py that is laying there to install the app on the system. Where does this file come from and how it ends up there? This file is created by you and will be copied to that location when your package is installed on the system. This action is configured in name_of_python_app/CMakeLists.txt:

install(FILES setup.py
        DESTINATION "/usr/share/pyshared/fake_package"
)

install(FILES __init__.py
        DESTINATION "/usr/share/pyshared/fake_package/fake_package"
)

install(FILES fake_python_app
        DESTINATION "/usr/share/pyshared/fake_package/fake_package"
)

install(FILES fake_module_1.py
        DESTINATION "/usr/share/pyshared/fake_package/fake_package"
)

install(FILES fake_module_2.py
        DESTINATION "/usr/share/pyshared/fake_package/fake_package"
)

As you can probably tell, besides the python application I want to install there's also 2 custom python modules that I wrote that also need to be installed. Below I describe the contents of the most important files:

setup.py:

#!/usr/bin/env python
from distutils.core import setup

setup(name='fake_package',
      version='1.0.5',
      description='Python modules used by fake-package',
      py_modules=['fake_package.fake_module_1', 'fake_package.fake_module_2'],
      scripts=['fake_package/fake_python_app']
     )

_init_.py: is an empty file.

fake_python_app : your python application that will be installed in /usr/local/bin

And that's pretty much it!

这篇关于如何使用CPack构建debian包来执行setup.py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆