Skip to content

Commit

Permalink
Merge pull request #159 from augustozanellato/pyinstaller
Browse files Browse the repository at this point in the history
Add client PyInstaller support
  • Loading branch information
doegox authored Sep 27, 2023
2 parents e757c58 + 55b4053 commit 43cadeb
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/build_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,47 @@ jobs:
pre_command: |
? .
bundle_command: |
Compress-Archive -Path software\* -DestinationPath client-windows.zip
Compress-Archive -Path software\dist\* -DestinationPath client-windows.zip
- name: linux
os: ubuntu-latest
pre_command: |
true
bundle_command: |
(cd software && zip -r "$OLDPWD/client-linux.zip" .)
(cd software/dist && zip -r "$OLDPWD/client-linux.zip" .)
- name: macos
os: macos-latest
pre_command: |
true
bundle_command: |
(cd software && zip -r "$OLDPWD/client-macos.zip" .)
(cd software/dist && zip -r "$OLDPWD/client-macos.zip" .)
runs-on: ${{ matrix.os }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
ref: ${{ inputs.checkout-sha == null && github.sha || inputs.checkout-sha }}
- name: Install PyInstaller and client dependencies
run: |
pip3 install pyinstaller
pip3 install -r software/script/requirements.txt
- name: Run OS specific setup
run: ${{ matrix.pre_command }}
- name: Compile native code
run: |
cd software/src
mkdir out
cd out
cmake ..
cmake --build . --config Release
- name: Run PyInstaller
run: |
cd software
pyinstaller pyinstaller.spec
- name: Upload built client
uses: actions/upload-artifact@v3
with:
name: client-${{ matrix.name }}
path: software/*
path: software/dist/*
- name: Zip up client for release
run: ${{ matrix.bundle_command }}
- name: Upload release artifacts
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...

## [unreleased][unreleased]
- Add PyInstaller support for CLI client (@augustozanellato)

## [v2.0.0][2023-09-26]
- Changed APP_FW_VER now deduced from git tag vx.y.z (@doegox)
Expand Down
3 changes: 3 additions & 0 deletions software/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ script/__pycache__
src/out
# Ignore the compiled scripts
script/*.pyc
# Ignore pyinstaller folders
build/
dist/
46 changes: 46 additions & 0 deletions software/pyinstaller.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
['script/chameleon_cli_main.py'],
pathex=[],
binaries=[
("bin/*", "bin/"),
],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='chameleon_cli_main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
9 changes: 8 additions & 1 deletion software/script/chameleon_cli_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import serial.tools.list_ports
import threading
import struct
from pathlib import Path
from platform import uname

import chameleon_com
Expand Down Expand Up @@ -38,6 +39,12 @@
0x38: "SmartMX with MIFARE Classic 4K",
}

if getattr(sys, 'frozen', False):
# in pyinstaller
default_cwd = str(Path(sys._MEIPASS) / "bin")
else:
# from source
default_cwd = str(Path(__file__).parent.parent / "bin")

class BaseCLIUnit:

Expand Down Expand Up @@ -81,7 +88,7 @@ def on_exec(self, args: argparse.Namespace):
raise NotImplementedError("Please implement this")

@staticmethod
def sub_process(cmd, cwd=os.path.abspath("bin/")):
def sub_process(cmd, cwd=default_cwd):
class ShadowProcess:
def __init__(self):
self.output = ""
Expand Down
1 change: 1 addition & 0 deletions software/src/mfkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "crapto1.h"

// MIFARE
extern int compare_uint64(const void *a, const void *b);
int inline compare_uint64(const void *a, const void *b) {
if (*(uint64_t *)b == *(uint64_t *)a) return 0;
if (*(uint64_t *)b < * (uint64_t *)a) return 1;
Expand Down

0 comments on commit 43cadeb

Please sign in to comment.