summaryrefslogtreecommitdiff
path: root/bundler/main.py
blob: 2c1207e408673fa03e21d10ffa814d7f67ddba8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# TODO:
#  - Check if inside a virtualenv, and warn before doing anything
#  - Build everything that we are currently expecting as a binary
#  - Create complete bundle changelog

import argparse
import os
import tempfile

from contextlib import contextmanager
from distutils import dir_util

from actions import GitCloneAll, PythonSetupAll, CreateDirStructure
from actions import CollectAllDeps, CopyBinaries, PLister, SeededConfig
from actions import DarwinLauncher, CopyAssets, CopyMisc, FixDylibs
from actions import DmgIt, PycRemover

from utils import IS_MAC

sorted_repos = [
    "leap_assets",
    "leap_pycommon",
    "keymanager",
    "soledad",
    "leap_mail",
    "bitmask_client",
    "bitmask_launcher",
    "thandy"
]

@contextmanager
def new_build_dir(default=None):
    bd = default
    if bd is None:
        bd = tempfile.mkdtemp(prefix="bundler-")
    yield bd
    # Only remove if created a temp dir
    if default is None:
        dir_util.remove_tree(bd)

def main():
    parser = argparse.ArgumentParser(description='Bundle creation tool.')
    parser.add_argument('--workon', help="")
    parser.add_argument('--skip', nargs="*", default=[], help="")
    parser.add_argument('--do', nargs="*", default=[], help="")
    parser.add_argument('--paths-file', help="")
    parser.add_argument('--binaries', help="")
    parser.add_argument('--seeded-config', help="")
    parser.add_argument('--nightly', action="store_true", help="")

    args = parser.parse_args()

    assert args.paths_file is not None, \
        "We need a paths file, otherwise you'll get " \
        "problems with distutils and site"
    paths_file = os.path.realpath(args.paths_file)

    assert args.binaries is not None, \
        "We don't support building from source, so you'll need to " \
        "specify a binaries path"
    binaries_path = os.path.realpath(args.binaries)

    seeded_config = None
    if args.seeded_config is not None:
        seeded_config = os.path.realpath(args.seeded_config)

    with new_build_dir(os.path.realpath(args.workon)) as bd:
        print "Doing it all in", bd

        def init(t, bd=bd):
            return t(bd, args.skip, args.do)

        gc = init(GitCloneAll)
        gc.run(sorted_repos, args.nightly)

        ps = init(PythonSetupAll)
        ps.run(sorted_repos)

        cd = init(CreateDirStructure, os.path.join(bd, "Bitmask"))
        cd.run()

        dp = init(CollectAllDeps)
        dp.run(paths_file)

        if binaries_path is not None:
            cb = init(CopyBinaries)
            cb.run(binaries_path)

        if seeded_config is not None:
            sc = init(SeededConfig)
            sc.run(seeded_config)

        if IS_MAC:
            pl = init(PLister)
            pl.run()
            dl = init(DarwinLauncher)
            dl.run()
            ca = init(CopyAssets)
            ca.run()
            fd = init(FixDylibs)
            fd.run()

        cm = init(CopyMisc)
        cm.run()

        pyc = init(PycRemover)
        pyc.run()

        if IS_MAC:
            dm = init(DmgIt)
            dm.run()

        # do manifest on windows

if __name__ == "__main__":
    main()