[Openlp-core] [Merge] lp:~raoul-snyman/openlp/fix-macos-codesign into lp:openlp/packaging

2018-12-02 Thread noreply
The proposal to merge lp:~raoul-snyman/openlp/fix-macos-codesign into 
lp:openlp/packaging has been updated.

Status: Needs review => Merged

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/fix-macos-codesign/+merge/359972
-- 
Your team OpenLP Core is subscribed to branch lp:openlp/packaging.

___
Mailing list: https://launchpad.net/~openlp-core
Post to : openlp-core@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openlp-core
More help   : https://help.launchpad.net/ListHelp


Re: [Openlp-core] [Merge] lp:~raoul-snyman/openlp/fix-macos-codesign into lp:openlp/packaging

2018-12-02 Thread Tim Bentley
Review: Approve


-- 
https://code.launchpad.net/~raoul-snyman/openlp/fix-macos-codesign/+merge/359972
Your team OpenLP Core is subscribed to branch lp:openlp/packaging.

___
Mailing list: https://launchpad.net/~openlp-core
Post to : openlp-core@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openlp-core
More help   : https://help.launchpad.net/ListHelp


[Openlp-core] [Merge] lp:~raoul-snyman/openlp/fix-macos-codesign into lp:openlp/packaging

2018-12-01 Thread Raoul Snyman
Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/fix-macos-codesign 
into lp:openlp/packaging.

Commit message:
macOS codesigning fails on Apps with periods in file names. Incorporated fixes 
from PyInstaller's wiki and also updated the version number to match our new 
versioning scheme.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/fix-macos-codesign/+merge/359972

macOS codesigning fails on Apps with periods in file names. Incorporated fixes 
from PyInstaller's wiki and also updated the version number to match our new 
versioning scheme.
-- 
Your team OpenLP Core is requested to review the proposed merge of 
lp:~raoul-snyman/openlp/fix-macos-codesign into lp:openlp/packaging.
=== modified file 'builders/builder.py'
--- builders/builder.py	2018-10-27 06:08:24 +
+++ builders/builder.py	2018-12-02 06:11:42 +
@@ -311,7 +311,7 @@
 tag, revision = lines[-1].split()
 output = self._bzr('log', self.branch_path, ['--line', '-r', '-1'], 'Error running bzr log')
 revision = output.split(':')[0]
-self.version = '{tag}-bzr{revision}'.format(tag=tag, revision=revision)
+self.version = '{tag}.dev{revision}'.format(tag=tag, revision=revision)
 # Write the version to the version file
 with open(os.path.join(self.dist_path, '.version'), 'w') as version_file:
 version_file.write(str(self.version))

=== modified file 'builders/macosx-builder.py'
--- builders/macosx-builder.py	2016-12-06 20:51:27 +
+++ builders/macosx-builder.py	2018-12-02 06:11:42 +
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
 
 ###
 # OpenLP - Open Source Lyrics Projection  #
@@ -94,15 +94,15 @@
 """
 
 import os
-import plistlib
-import signal
-from shutil import copy, copytree
+from pathlib import Path
+from shutil import copy, copytree, move, rmtree
 
 from macholib.MachO import MachO
-from macholib.util import flipwritable, in_system_path
+from macholib.util import in_system_path
 
 from builder import Builder
 
+
 class MacOSXBuilder(Builder):
 """
 The :class:`MacosxBuilder` class encapsulates everything that is needed
@@ -119,6 +119,99 @@
 dir_size += os.path.getsize(filename)
 return dir_size
 
+def _create_symlink(self, folder):
+"""
+Create the appropriate symlink in the MacOS folder pointing to the Resources folder.
+"""
+sibling = Path(str(folder).replace('MacOS', ''))
+
+# PyQt5/Qt/qml/QtQml/Models.2
+root = str(sibling).partition('Contents')[2].lstrip('/')
+# ../../../../
+backward = '../' * len(root.split('/'))
+# ../../../../Resources/PyQt5/Qt/qml/QtQml/Models.2
+good_path = f'{backward}Resources/{root}'
+
+folder.symlink_to(good_path)
+
+def _fix_qt_dll(self, dll):
+"""
+Fix the DLL lookup paths to use relative ones for Qt dependencies.
+Inspiration: PyInstaller/depend/dylib.py:mac_set_relative_dylib_deps()
+Currently one header is pointing to (we are in the Resources folder):
+@loader_path/../../../../QtCore (it is referencing to the old MacOS folder)
+It will be converted to:
+@loader_path/../../../../../../MacOS/QtCore
+"""
+
+def match_func(pth):
+"""
+Callback function for MachO.rewriteLoadCommands() that is
+called on every lookup path setted in the DLL headers.
+By returning None for system libraries, it changes nothing.
+Else we return a relative path pointing to the good file
+in the MacOS folder.
+"""
+basename = os.path.basename(pth)
+if not basename.startswith('Qt'):
+return None
+return f'@loader_path{good_path}/{basename}'
+
+# Resources/PyQt5/Qt/qml/QtQuick/Controls.2/Fusion
+root = str(dll.parent).partition('Contents')[2][1:]
+# /../../../../../../..
+backward = '/..' * len(root.split('/'))
+# /../../../../../../../MacOS
+good_path = f'{backward}/MacOS'
+
+# Rewrite Mach headers with corrected @loader_path
+dll = MachO(dll)
+dll.rewriteLoadCommands(match_func)
+with open(dll.filename, 'rb+') as f:
+for header in dll.headers:
+f.seek(0)
+dll.write(f)
+f.seek(0, 2)
+f.flush()
+
+def _find_problematic_qt_folders(self, folder):
+"""
+Recursively yields problematic folders (containing a dot in their name).
+"""
+for path in