如何在 Travis CI 上构建 MacOSX 可执行文件?

Bjö*_*son 4 python macos wxpython

我有一个仅依赖于 wxPython 的小型 python 程序。我在 Linux 上开发了这个,我已经设法在 Travis CI(github 上的 seguid_calculator)上使用 wine 设置了 Windows 可执行文件的自动构建。

我的解决方案涉及最近发布的 wine 和 Pyinstaller 的组合。

我想为 MacOS 做类似的事情。我知道 Travis 上也有一个 MacOSX 构建环境。我对 MacOSX 操作系统的经验为零,我没有 Mac。我了解到您可以使用称为“自制软件”的东西安装第三方软件包

有没有我想做的例子?一个示例 travis.yml 文件会很棒!

感谢您的任何输入,/Björn

* 编辑 *

我创建了一个仅打开一个窗口的示例 wxpython 应用程序。它位于https://github.com/BjornFJohansson/macapp。我使用下面的 .travis.yml 生成不起作用的可执行文件。

os:
- osx
language: objective-c
python:
- '2.7'
before_install:
- brew update
- brew outdated xctool || brew upgrade xctool
- brew install python
- brew install wxpython
- pip install pyinstaller
- pyinstaller --noconsole --onefile hw.py
- ls
- ls dist/
- hdiutil create dist/hw.dmg -srcfolder dist/ -ov
install: true
deploy:
  skip_cleanup: true
  provider: releases
  api_key:
    secure: VK1oVWQCRomgcFNVua00B3YSsotezzU1p6/fh73/0vwQFzVMolVnAsnfSq6EAwIcJvakU0TI9pqZR+0S3PKnUs+Kn3Ar8OwQ88t2azZNwewBfKua3tM2/7BF4y7O0gOtN1F29Yxyu0zPInIVY17BqGygibQ1kthBTm+tj3YyNW8=
  file: 
    - "dist/hw"
    - "dist/hw.dmg"
  on:
    tags: true
    all_branches: true
    repo: BjornFJohansson/macapp
Run Code Online (Sandbox Code Playgroud)

基本上,首先我更新 xtools(我看到很多人这样做,所以我决定也这样做)。然后我 brew install python 和 wxpython。然后我 pip install pyinstaller。我使用 pyinstaller 命令,它在 ./dist 下生成一个可执行文件 (hw) 和一个“hw.app”文件夹。

我没有设法部署 .app 文件夹,所以我使用 hdiutil 制作了一个 .dmg。然后我部署到 github 版本。

有人能告诉我这个设置可能有什么问题吗?

travis 日志可以在这里找到:https : //travis-ci.org/BjornFJohansson/macapp

小智 6

它不起作用的原因是通过自制软件安装的 wxPython 版本不是 32 位。您需要从 wxPython 主页安装 dmg。我在那里找到了一个脚本:https : //github.com/ayufan/travis-osx-vm-templates/blob/master/scripts/packages.sh

我分叉了你的例子并设法让它运行(https://github.com/paulmueller/macapp/releases)。

.travis.yml 现在看起来像这样:

language: objective-c
python:
- '2.7'
before_install:
- which python
- brew install python --universal --framework
- brew install wget
- which python
- export VERSIONER_PYTHON_PREFER_32_BIT=yes
- defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
- which python
- python --version
# https://github.com/Homebrew/homebrew/issues/34470
#- arch -i386 brew install wxpython --universal
- mkdir dl
- cd dl
- wget http://downloads.sourceforge.net/wxpython/wxPython3.0-osx-3.0.2.0-cocoa-py2.7.dmg
- ls
- cd ..
- sudo ./packages.sh
- arch -i386 python -c "import wx; print wx.__version__"
- arch -i386 pip install pyinstaller
- arch -i386 pyinstaller --noconsole --onefile hw.py
- ls
- hdiutil create dist/hw.dmg -srcfolder dist/ -ov
- zip -r dist/hw.zip dist/hw.app
- ls dist/
install: true
deploy:
  provider: releases
  skip_cleanup: true
  api_key:
    secure: KjdN4hSHWU3ZDg6lpDNMB2we9jLayM9C8pwyQrV/Xzq8HNH5eNHP8ScI64tvnS0yJegOXnHFwUhUrkMtEs3X29TKrom+8tJ5E52IdBO7xO8fqOfeugC2239vLzc3tNI6RJX/K7CZTsSRu5U++1RJVgcWYjrCln87DuXG+HZRdOI=
  file: 
    - "dist/hw.dmg"
    - "dist/hw.zip"
  on:
    tags: true
    all_branches: true
    repo: paulmueller/macapp
Run Code Online (Sandbox Code Playgroud)