Ejemplo n.º 1
0
def bundle(build_dir, dest_dir):
    '''Bundle the programme: copy all the necessary file into
    ':dest_dir:/release' and make an archive with the data in :dest_dir:

    :param build_dir: directory with the built executable,
    :param dest_dir: directory to put the archive into
    '''

    print('Bundling Myfyrio...')

    dest_dir = pathlib.Path(dest_dir)
    release_dir = dest_dir / 'release'

    if release_dir.exists():
        shutil.rmtree(release_dir)
    release_dir.mkdir(parents=True)

    copy_exe(build_dir, release_dir, strip=True)

    sysroot_dir = project_dir / 'sysroot'
    copy_licenses(release_dir, sysroot_dir)

    if utils.is_linux():
        copy_icon(release_dir)
        generate_desktop(release_dir, '', '', user_mode=True)

    pack(dest_dir, release_dir)
Ejemplo n.º 2
0
def _copy_thirdparty_licenses(dest_dir):
    # Copy the prepared earlier the '3RD-PARTY-LICENSE' licenses
    deploy_dir = project_dir / 'deploy'
    shutil.copytree(deploy_dir / '3RD-PARTY-LICENSE', dest_dir)
    if not utils.is_linux():
        libffi_license = dest_dir / 'libffi'
        shutil.rmtree(libffi_license)

    _set_license_dir_permissions(dest_dir)
Ejemplo n.º 3
0
def copy_exe(src_dir, dest_dir, strip=False):
    '''Copy the executable from :src_dir: into :dest_dir: and set its mod
    to 755. Also the symbols can be stripped

    :param src_dir: directory where the executable is located,
    :param dest_dir: directory to put the executable into,
    :param strip: True - strip the executable (optional)
    '''

    exe_name = md.NAME.lower()
    if not utils.is_linux():
        exe_name += '.exe'
        src_dir = pathlib.Path(src_dir) / 'release'
    new_exe = pathlib.Path(dest_dir) / exe_name
    shutil.copyfile(src_dir / exe_name, new_exe)

    if strip and utils.is_linux():
        utils.strip_exe(new_exe)

    os.chmod(new_exe, 0o755)
Ejemplo n.º 4
0
def run(cmd, src_dir, cwd=None):
    '''Run a command in the shell

    :param cmd: command to run,
    :param src_dir: folder with Qt5 source (to set environment variables in
                    Windows),
    :param cwd: set the current working directory (optional, default - None)
    '''

    if not utils.is_linux():
        set_vars_cmd = set_vars_msvc_cmd(src_dir)
        cmd = f'{set_vars_cmd} && {cmd}'

    utils.run(cmd, cwd=cwd)
Ejemplo n.º 5
0
def build(src_dir,
          build_dir,
          install_dir,
          options='',
          disabled_features='',
          clean=True):
    '''Build Qt5

    :param src_dir: folder with Qt5 source,
    :param build_dir: path to the build directory,
    :param install_dir: installation directory,
    :param options: Qt5 build options (optional),
    :param disabled_features: Qt5 disabled features with '-no-feature' prefix
                              (optional),
    :param clean: True - remove the existing :build_dir:, False - not
                  (optional, default - True)
    '''

    print('Building Qt...')

    if build_dir.exists():
        if clean:
            shutil.rmtree(build_dir)
            build_dir.mkdir()
        else:
            config_file = build_dir / 'config.cache'
            if config_file.exists():
                config_file.unlink()
    else:
        build_dir.mkdir()

    configure_path = src_dir / 'configure'
    configure_cmd = (f'{configure_path} {options} {disabled_features} '
                     f'-prefix {install_dir}')
    run(configure_cmd, src_dir, cwd=build_dir)

    make_cmd = 'make' if utils.is_linux() else 'nmake'
    run(make_cmd, src_dir, cwd=build_dir)

    print('Installing Qt...')

    if install_dir.exists():
        shutil.rmtree(install_dir)
    install_dir.mkdir()

    install_cmd = f'{make_cmd} install'
    run(install_cmd, src_dir, cwd=build_dir)
Ejemplo n.º 6
0
def check_build_dependencies():
    '''Check that all the necessary dependencies are installed'''

    # https://doc.qt.io/qt-5/windows-requirements.html
    # https://doc.qt.io/qt-5/linux-requirements.html

    print('Checking build dependencies...')

    if utils.is_linux():
        deps = [
            'libfontconfig1-dev', 'libfreetype6-dev', 'libx11-dev',
            'libxext-dev', 'libxfixes-dev', 'libxi-dev', 'libxrender-dev',
            'libxcb1-dev', 'libx11-xcb-dev', 'libxcb-glx0-dev',
            'libxkbcommon-x11-dev', 'libxkbcommon-dev'
        ]
        #system_xcb_deps = [
        #    'libxcb-keysyms1-dev',
        #    'libxcb-image0-dev',
        #    'libxcb-shm0-dev',
        #    'libxcb-icccm4-dev',
        #    'libxcb-sync0-dev',
        #    'libxcb-xfixes0-dev',
        #    'libxcb-shape0-dev',
        #    'libxcb-randr0-dev',
        #    'libxcb-render-util0-dev',
        #]
        check_func = utils.apt_installed
        msg = 'is not installed'
    else:
        deps = [
            'Perl64',  # ActivePerl
            'Python'
        ]
        path = os.environ['PATH']
        check_func = lambda names: [(n, n in path) for n in names]
        msg = "is not installed (or, at least, not in 'PATH')"

    all_installed = True
    for name, installed in check_func(deps):
        if not installed:
            all_installed = False
            print(f'{name} {msg}')

    if not all_installed:
        input("Some dependencies are missing. If you are sure that "
              "everything is fine, press any key to continue...")
Ejemplo n.º 7
0
def pack(dest_dir, dir_to_arch):
    '''Pack the data in :dir_to_arch: and put the result archive
    into :dest_dir:

    :param dest_dir: directory to put the result archive into,
    :param dir_to_arch: directory to pack
    '''

    if utils.is_linux():
        platform = 'linux64'
        arch_format = 'gztar'
    else:
        platform = 'win64'
        arch_format = 'zip'

    arch_name = f'{md.NAME.lower()}-{md.VERSION}-{platform}'
    arch = pathlib.Path(dest_dir) / arch_name
    shutil.make_archive(arch, arch_format, root_dir=dir_to_arch)
Ejemplo n.º 8
0
def build_myfyrio(sysroot_dir, pdy_file, build_dir):
    '''Build the programme

    :param sysroot_dir: path to the sysroot folder,
    :param pdy_file: path to the project '.pdy' file,
    :param build_dir: myfyrio build directory
    '''

    print('Building Myfyrio...')

    qt_src = sysroot_dir.joinpath('build', 'qtbase-everywhere-src-5.14.2')

    options = f'--sysroot {sysroot_dir} --build-dir {build_dir}'
    build_project_cmd = f'pyqtdeploy-build {options} {pdy_file}'
    qt.run(build_project_cmd, qt_src)

    qmake_cmd = sysroot_dir.joinpath('qt', 'bin', 'qmake')
    qt.run(str(qmake_cmd), qt_src, cwd=build_dir)

    make_cmd = 'make' if utils.is_linux() else 'nmake'
    qt.run(make_cmd, qt_src, cwd=build_dir)
Ejemplo n.º 9
0
def build(src_dir, build_dir, qmake, build_options=None, install_dir=None):
    '''Build PyQt5

    :param src_dir: folder with the unpacked PyQt5,
    :param build_dir: path to the build directory,
    :param qmake: path to the Qt5 'qmake',
    :param build_options: list with build options,
                          e.g. ['--confirm-license', '--verbose'],
    :param install_dir: installation directory (optional, default - None,
                        if None, it will be installed in the Python
                        'site-packages' directory)
    '''

    # pip install PyQt-builder
    print('Building PyQt...')

    if build_dir.exists():
        shutil.rmtree(build_dir)
    build_dir.mkdir()

    options = [
        f'--build-dir {build_dir}',
        f'--qmake {qmake}',
    ]

    if build_options is not None:
        options.extend(build_options)

    if install_dir is not None:
        if not install_dir.exists():
            install_dir.mkdir()

        options.append(f'--target-dir {install_dir}')

    options = ' '.join(options)
    cmd = f'sip-install {options}'
    if utils.is_linux():
        add_ccache_cmd = utils.add_ccache_to_PATH_cmd()
        cmd = f'{add_ccache_cmd} && {cmd}'
    qt.run(cmd, src_dir, cwd=src_dir)
Ejemplo n.º 10
0
def set_project_toml():
    # TODO: add disabled features to toml dynamically
    pass


if __name__ == '__main__':
    check_build_dependencies()

    sysroot = project_dir / 'sysroot'
    if not sysroot.exists():
        sysroot.mkdir()

    src_dir = project_dir.joinpath('build-src', 'PyQt5-5.14.2mod')
    build_dir = sysroot / 'build-pyqt'
    install_dir = sysroot / 'PyQt'
    qt_bin = sysroot.joinpath('Qt', 'bin')
    qmake = qt_bin / ('qmake' if utils.is_linux() else 'qmake.exe')

    options = [
        '--confirm-license', '--no-dbus-python', '--no-designer-plugin',
        '--no-qml-plugin', '--no-tools', '--no-docstring', '--enable QtCore',
        '--enable QtGui', '--enable QtWidgets', '--verbose'
    ]

    build(src_dir,
          build_dir,
          qmake,
          build_options=options,
          install_dir=install_dir)