contrib/packaging/pyoxidizer.bzl
branchstable
changeset 44761 686d738b9df9
parent 44760 6a6c15cea1fa
child 44762 eec66d9c9e50
equal deleted inserted replaced
44760:6a6c15cea1fa 44761:686d738b9df9
     1 # Instructions:
       
     2 #
       
     3 # 1. cargo install --version 0.5.0 pyoxidizer
       
     4 # 2. cd /path/to/hg
       
     5 # 3. pyoxidizer build --path contrib/packaging [--release]
       
     6 # 4. Run build/pyoxidizer/<arch>/<debug|release>/app/hg
       
     7 #
       
     8 # If you need to build again, you need to remove the build/lib.* and
       
     9 # build/temp.* directories, otherwise PyOxidizer fails to pick up C
       
    10 # extensions. This is a bug in PyOxidizer.
       
    11 
       
    12 ROOT = CWD + "/../.."
       
    13 
       
    14 set_build_path(ROOT + "/build/pyoxidizer")
       
    15 
       
    16 def make_exe():
       
    17     dist = default_python_distribution()
       
    18 
       
    19     code = "import hgdemandimport; hgdemandimport.enable(); from mercurial import dispatch; dispatch.run()"
       
    20 
       
    21     config = PythonInterpreterConfig(
       
    22         raw_allocator = "system",
       
    23         run_eval = code,
       
    24         # We want to let the user load extensions from the file system
       
    25         filesystem_importer = True,
       
    26         # We need this to make resourceutil happy, since it looks for sys.frozen.
       
    27         sys_frozen = True,
       
    28         legacy_windows_stdio = True,
       
    29     )
       
    30 
       
    31     exe = dist.to_python_executable(
       
    32         name = "hg",
       
    33         config = config,
       
    34     )
       
    35 
       
    36     # Use setup.py install to build Mercurial and collect Python resources to
       
    37     # embed in the executable.
       
    38     resources = dist.setup_py_install(ROOT)
       
    39     exe.add_python_resources(resources)
       
    40 
       
    41     return exe
       
    42 
       
    43 def make_install(exe):
       
    44     m = FileManifest()
       
    45 
       
    46     # `hg` goes in root directory.
       
    47     m.add_python_resource(".", exe)
       
    48 
       
    49     templates = glob(
       
    50         include=[ROOT + "/mercurial/templates/**/*"],
       
    51         strip_prefix = ROOT + "/mercurial/",
       
    52     )
       
    53     m.add_manifest(templates)
       
    54 
       
    55     return m
       
    56 
       
    57 register_target("exe", make_exe)
       
    58 register_target("app", make_install, depends = ["exe"], default = True)
       
    59 
       
    60 resolve_targets()