diff options
Diffstat (limited to 'sources/shiboken6/libshiboken/embed/embedding_generator.py')
-rw-r--r-- | sources/shiboken6/libshiboken/embed/embedding_generator.py | 91 |
1 files changed, 36 insertions, 55 deletions
diff --git a/sources/shiboken6/libshiboken/embed/embedding_generator.py b/sources/shiboken6/libshiboken/embed/embedding_generator.py index f9ec60cbc..a058fd372 100644 --- a/sources/shiboken6/libshiboken/embed/embedding_generator.py +++ b/sources/shiboken6/libshiboken/embed/embedding_generator.py @@ -1,41 +1,5 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of PySide6. -## -## $QT_BEGIN_LICENSE:LGPL$ -## Commercial License Usage -## Licensees holding valid commercial Qt licenses may use this file in -## accordance with the commercial license agreement provided with the -## Software or, alternatively, in accordance with the terms contained in -## a written agreement between you and The Qt Company. For licensing terms -## and conditions see https://www.qt.io/terms-conditions. For further -## information use the contact form at https://www.qt.io/contact-us. -## -## GNU Lesser General Public License Usage -## Alternatively, this file may be used under the terms of the GNU Lesser -## General Public License version 3 as published by the Free Software -## Foundation and appearing in the file LICENSE.LGPL3 included in the -## packaging of this file. Please review the following information to -## ensure the GNU Lesser General Public License version 3 requirements -## will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 2.0 or (at your option) the GNU General -## Public license version 3 or any later version approved by the KDE Free -## Qt Foundation. The licenses are as published by the Free Software -## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -## included in the packaging of this file. Please review the following -## information to ensure the GNU General Public License requirements will -## be met: https://www.gnu.org/licenses/gpl-2.0.html and -## https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only """ embedding_generator.py @@ -62,7 +26,7 @@ import marshal import traceback from pathlib import Path -# work_dir is set to the source for testing, onl. +# work_dir is set to the source for testing, only. # It can be overridden in the command line. work_dir = Path(__file__).parent.resolve() embed_dir = work_dir @@ -81,7 +45,7 @@ def runpy(cmd, **kw): subprocess.call([sys.executable, '-E'] + cmd.split(), **kw) -def create_zipfile(limited_api): +def create_zipfile(use_pyc, quiet): """ Collect all Python files, compile them, create a zip file and make a chunked base64 encoded file from it. @@ -110,7 +74,7 @@ def create_zipfile(limited_api): if embed_dir != work_dir: utils.copyfile(embed_dir / "signature_bootstrap.py", work_dir) - if limited_api: + if not use_pyc: pass # We cannot compile, unless we have folders per Python version else: files = ' '.join(fn for fn in os.listdir('.')) @@ -124,11 +88,26 @@ def create_zipfile(limited_api): with open(inc_name, "w") as inc: _embed_file(tmp, inc) tmp.close() + # also generate a simple embeddable .pyc file for signature_bootstrap.pyc - boot_name = "signature_bootstrap.py" if limited_api else "signature_bootstrap.pyc" + boot_name = "signature_bootstrap.py" if not use_pyc else "signature_bootstrap.pyc" with open(boot_name, "rb") as ldr, open("signature_bootstrap_inc.h", "w") as inc: - _embed_bytefile(ldr, inc, limited_api) + _embed_bytefile(ldr, inc, not use_pyc) os.chdir(cur_dir) + if quiet: + return + + # have a look at our populated folder unless quiet option + def tree(directory): + print(f'+ {directory}') + for path in sorted(directory.rglob('*')): + depth = len(path.relative_to(directory).parts) + spacer = ' ' * depth + print(f'{spacer}+ {path.name}') + + print("++++ Current contents of") + tree(work_dir) + print("++++") def _embed_file(fin, fout): @@ -143,22 +122,23 @@ def _embed_file(fin, fout): limit = 50 text = fin.readlines() print(textwrap.dedent(""" - /* - * This is a ZIP archive of all Python files in the directory - * "shiboken6/shibokenmodule/files.dir/shibokensupport/signature" - * There is also a toplevel file "signature_bootstrap.py[c]" that will be - * directly executed from C++ as a bootstrap loader. - */ + // This is a ZIP archive of all Python files in the directory + // "shiboken6/shibokenmodule/files.dir/shibokensupport/signature" + // There is also a toplevel file "signature_bootstrap.py[c]" that will be + // directly executed from C++ as a bootstrap loader. """).strip(), file=fout) block, blocks = 0, len(text) // limit + 1 for idx, line in enumerate(text): if idx % limit == 0: + if block: + fout.write(')"\n') comma = "," if block else "" block += 1 - print(file=fout) - print(f'/* Block {block} of {blocks} */{comma}', file=fout) - print(f'\"{line.strip()}\"', file=fout) - print(f'/* Sentinel */, \"\"', file=fout) + fout.write(f'\n{comma} // Block {block} of {blocks}\nR"(') + else: + fout.write('\n') + fout.write(line.strip()) + fout.write(')"\n\n/* Sentinel */, ""\n') def _embed_bytefile(fin, fout, is_text): @@ -232,8 +212,9 @@ def str2bool(v): if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--cmake-dir', nargs="?") - parser.add_argument('--limited-api', type=str2bool) + parser.add_argument('--use-pyc', type=str2bool) + parser.add_argument('--quiet', action='store_true') args = parser.parse_args() if args.cmake_dir: work_dir = Path(args.cmake_dir).resolve() - create_zipfile(args.limited_api) + create_zipfile(args.use_pyc, args.quiet) |