rust/hgcli/pyoxidizer.bzl
author Matt Harbison <matt_harbison@yahoo.com>
Mon, 16 Mar 2020 14:33:35 -0400
changeset 44647 99fa161a883c
parent 44639 bc847878f4c0
child 44763 94f4f2ec7dee
permissions -rw-r--r--
phabricator: extract the logic to amend diff properties to a function This will be needed on a separate code path when dealing with folding revisions. And since we know that will involve adding multiple local commmits to the diff properties instead of just one, restructure the logic slightly to allow it. Differential Revision: https://phab.mercurial-scm.org/D8312

ROOT = CWD + "/../.."

def make_exe():
    dist = default_python_distribution()

    code = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()"

    config = PythonInterpreterConfig(
        raw_allocator = "system",
        run_eval = code,
        # We want to let the user load extensions from the file system
        filesystem_importer = True,
        # We need this to make resourceutil happy, since it looks for sys.frozen.
        sys_frozen = True,
        legacy_windows_stdio = True,
    )

    exe = dist.to_python_executable(
        name = "hg",
        resources_policy = "prefer-in-memory-fallback-filesystem-relative:lib",
        config = config,
        # Extension may depend on any Python functionality. Include all
        # extensions.
        extension_module_filter = "all",
    )

    exe.add_python_resources(dist.pip_install([ROOT]))

    return exe

def make_install(exe):
    m = FileManifest()

    # `hg` goes in root directory.
    m.add_python_resource(".", exe)

    templates = glob(
        include = [ROOT + "/mercurial/templates/**/*"],
        strip_prefix = ROOT + "/mercurial/",
    )
    m.add_manifest(templates)

    return m

def make_embedded_resources(exe):
    return exe.to_embedded_resources()

register_target("exe", make_exe)
register_target("app", make_install, depends = ["exe"], default = True)
register_target("embedded", make_embedded_resources, depends = ["exe"], default_build_script = True)
resolve_targets()

# END OF COMMON USER-ADJUSTED SETTINGS.
#
# Everything below this is typically managed by PyOxidizer and doesn't need
# to be updated by people.

PYOXIDIZER_VERSION = "0.7.0-pre"
PYOXIDIZER_COMMIT = "c772a1379c3026314eda1c8ea244b86c0658951d"