This repository has been archived by the owner on Oct 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
/
make-xpi.py
executable file
·123 lines (100 loc) · 3.87 KB
/
make-xpi.py
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
117
118
119
120
121
122
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import sys
import os
import shutil
import argparse
sys.path.insert(0, "./build")
import console
import addonconf
from themebuilder import ThemeBuilder
from extensionbuilder import ExtensionBuilder
from packagebuilder import PackageBuilder
def main():
console.start_timer()
config = addonconf.load("config.json")
if not config:
sys.exit(1)
available_actions = []
package_is_avaliable = True
for t in ["theme", "extension"]:
if t in config:
available_actions = available_actions + [t]
else:
package_is_avaliable = False
if package_is_avaliable and "package" in config:
available_actions = available_actions + ["package"]
parser = argparse.ArgumentParser()
parser.add_argument("action", nargs='?', default="all",
choices=["all"] + available_actions + ["clean"],
help="build theme, extension, package or clean sources")
parser.add_argument("--version",
help="override version from config.json")
parser.add_argument("--target-version", type=int,
help="build for a certain version only")
parser.add_argument("--force-rebuild", action="store_true",
help="regenerate all needed files")
parser.add_argument("-v", "--verbose", action="count", default=0,
help="increase output verbosity")
args = parser.parse_args()
action = args.action
# Override preferences from config.json
if "VERSION" in os.environ:
config["version"] = os.environ.get("VERSION")
config["override-version"] = True
if args.version:
config["version"] = args.version
config["override-version"] = True
if args.target_version:
config["target-version"] = args.target_version
config["force-rebuild"] = args.force_rebuild
config["verbose"] = args.verbose
config = addonconf.validate(config)
if not config:
sys.exit(1)
# Clean up
if action == "clean":
clean_paths = []
if os.path.isdir(".build"):
for base, dirs, files in os.walk(".build", topdown=False):
for name in files:
clean_paths.append(os.path.join(base, name))
for name in dirs:
clean_paths.append(os.path.join(base, name))
clean_paths.append(".build")
for base, dirs, files in os.walk("build"):
for name in files:
if name.endswith(".pyc"):
clean_paths.append(os.path.join(base, name))
clean_paths.append("build/__pycache__")
for i in available_actions:
clean_paths.append(config[i]["xpi"])
for path in clean_paths:
path = os.path.abspath(path)
if not os.path.exists(path):
continue
console.log("removing", path)
if os.path.isfile(path):
os.remove(path)
else:
os.rmdir(path)
sys.exit(0)
# Theme building
if action in ["theme", "all"] and "theme" in available_actions:
builder = ThemeBuilder(config)
print(":: Starting build theme...")
builder.build()
# Extension building
if action in ["extension", "all"] and "extension" in available_actions:
builder = ExtensionBuilder(config)
print(":: Starting build extension...")
builder.build()
# Package building
if action in ["package", "all"] and "package" in available_actions:
builder = PackageBuilder(config)
print(":: Starting make package...")
builder.build()
if __name__ == "__main__":
main()