Add Windows support
[bitmask_bundler.git] / bundler / main.py
1 # TODO:
2 #  - Check if inside a virtualenv, and warn before doing anything
3 #  - Build everything that we are currently expecting as a binary
4 #  - Create complete bundle changelog
5
6 import argparse
7 import os
8 import tempfile
9
10 from contextlib import contextmanager
11 from distutils import dir_util
12
13 from actions import GitCloneAll, PythonSetupAll, CreateDirStructure
14 from actions import CollectAllDeps, CopyBinaries, PLister, SeededConfig
15 from actions import DarwinLauncher, CopyAssets, CopyMisc, FixDylibs
16 from actions import DmgIt, PycRemover, TarballIt, MtEmAll, ZipIt
17
18 from utils import IS_MAC, IS_WIN
19
20 sorted_repos = [
21     "leap_assets",
22     "leap_pycommon",
23     "keymanager",
24     "soledad",
25     "leap_mail",
26     "bitmask_client",
27     "bitmask_launcher",
28     "thandy"
29 ]
30
31 @contextmanager
32 def new_build_dir(default=None):
33     bd = default
34     if bd is None:
35         bd = tempfile.mkdtemp(prefix="bundler-")
36     yield bd
37     # Only remove if created a temp dir
38     if default is None:
39         dir_util.remove_tree(bd)
40
41 def main():
42     parser = argparse.ArgumentParser(description='Bundle creation tool.')
43     parser.add_argument('--workon', help="")
44     parser.add_argument('--skip', nargs="*", default=[], help="")
45     parser.add_argument('--do', nargs="*", default=[], help="")
46     parser.add_argument('--paths-file', help="")
47     parser.add_argument('--binaries', help="")
48     parser.add_argument('--seeded-config', help="")
49     parser.add_argument('--nightly', action="store_true", help="")
50
51     args = parser.parse_args()
52
53     assert args.paths_file is not None, \
54         "We need a paths file, otherwise you'll get " \
55         "problems with distutils and site"
56     paths_file = os.path.realpath(args.paths_file)
57
58     assert args.binaries is not None, \
59         "We don't support building from source, so you'll need to " \
60         "specify a binaries path"
61     binaries_path = os.path.realpath(args.binaries)
62
63     seeded_config = None
64     if args.seeded_config is not None:
65         seeded_config = os.path.realpath(args.seeded_config)
66
67     with new_build_dir(os.path.realpath(args.workon)) as bd:
68         print "Doing it all in", bd
69
70         def init(t, bd=bd):
71             return t(bd, args.skip, args.do)
72
73         gc = init(GitCloneAll)
74         gc.run(sorted_repos, args.nightly)
75
76         ps = init(PythonSetupAll)
77         ps.run(sorted_repos)
78
79         cd = init(CreateDirStructure, os.path.join(bd, "Bitmask"))
80         cd.run()
81
82         dp = init(CollectAllDeps)
83         dp.run(paths_file)
84
85         if binaries_path is not None:
86             cb = init(CopyBinaries)
87             cb.run(binaries_path)
88
89         if seeded_config is not None:
90             sc = init(SeededConfig)
91             sc.run(seeded_config)
92
93         if IS_MAC:
94             pl = init(PLister)
95             pl.run()
96             dl = init(DarwinLauncher)
97             dl.run()
98             ca = init(CopyAssets)
99             ca.run()
100             fd = init(FixDylibs)
101             fd.run()
102
103         cm = init(CopyMisc)
104         cm.run()
105
106         pyc = init(PycRemover)
107         pyc.run()
108
109         if IS_WIN:
110             mt = init(MtEmAll)
111             mt.run()
112
113         if IS_MAC:
114             dm = init(DmgIt)
115             dm.run(sorted_repos, args.nightly)
116         elif IS_WIN:
117             zi = init(ZipIt)
118             zi.run(sorted_repos, args.nightly)
119         else:
120             ti = init(TarballIt)
121             ti.run(sorted_repos, args.nightly)
122
123         # do manifest on windows
124
125 if __name__ == "__main__":
126     main()