OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding: utf-8 | 2 # coding: utf-8 |
3 | 3 |
4 # This file is part of Adblock Plus <https://adblockplus.org/>, | 4 # This file is part of Adblock Plus <https://adblockplus.org/>, |
5 # Copyright (C) 2006-present eyeo GmbH | 5 # Copyright (C) 2006-present eyeo GmbH |
6 # | 6 # |
7 # Adblock Plus is free software: you can redistribute it and/or modify | 7 # Adblock Plus is free software: you can redistribute it and/or modify |
8 # it under the terms of the GNU General Public License version 3 as | 8 # it under the terms of the GNU General Public License version 3 as |
9 # published by the Free Software Foundation. | 9 # published by the Free Software Foundation. |
10 # | 10 # |
11 # Adblock Plus is distributed in the hope that it will be useful, | 11 # Adblock Plus is distributed in the hope that it will be useful, |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 # GNU General Public License for more details. | 14 # GNU General Public License for more details. |
15 # | 15 # |
16 # You should have received a copy of the GNU General Public License | 16 # You should have received a copy of the GNU General Public License |
17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
19 import os | 19 import os |
20 import shutil | 20 import shutil |
21 import subprocess | 21 import subprocess |
22 import sys | 22 import sys |
23 import tempfile | 23 import tempfile |
24 | 24 |
25 _BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 25 _BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
26 _ABP_DIR = "adblockplus" | 26 _ABP_DIR = "adblockpluschrome" |
27 _ABP_CORE_DIR = "adblockpluscore" | 27 _ABP_CORE_DIR = "adblockpluscore" |
| 28 _SUBSCRIPTIONS_PATH = os.path.join(_BASE_DIR, _ABP_DIR, _ABP_CORE_DIR, "chrome", |
| 29 "content", "ui", "subscriptions.xml") |
| 30 |
| 31 |
| 32 def _copy_subscriptions(xpi_path): |
| 33 xpi_dir = os.path.dirname(xpi_path) |
| 34 shutil.copy2(_SUBSCRIPTIONS_PATH, xpi_dir) |
| 35 |
| 36 |
| 37 def _patch_abp(patched_dir): |
| 38 shutil.copytree(_BASE_DIR, patched_dir) |
| 39 abp_dir = os.path.join(patched_dir, _ABP_DIR) |
| 40 abp_core_dir = os.path.join(abp_dir, _ABP_CORE_DIR) |
| 41 subprocess.check_call(["hg", "import", "-q", "-R", abp_core_dir, |
| 42 os.path.join(patched_dir, "issue-6070.patch")]) |
28 | 43 |
29 | 44 |
30 def _build_abp(base_dir, xpi_path): | 45 def _build_abp(base_dir, xpi_path): |
31 xpi_dir = os.path.dirname(os.path.abspath(xpi_path)) | 46 xpi_dir = os.path.dirname(os.path.abspath(xpi_path)) |
32 if not os.path.exists(xpi_dir): | 47 if not os.path.exists(xpi_dir): |
33 os.makedirs(xpi_dir) | 48 os.makedirs(xpi_dir) |
34 | 49 |
35 abp_dir = os.path.join(base_dir, _ABP_DIR) | 50 abp_dir = os.path.join(base_dir, _ABP_DIR) |
36 sys.path.insert(0, abp_dir) | 51 sys.path.insert(0, abp_dir) |
37 import buildtools.build | 52 import buildtools.build as tools_build |
38 import buildtools.packager | 53 import buildtools.packager as tools_packager |
39 | 54 |
40 def get_metadata_path(dir, type): | 55 def get_metadata_path(dir, type): |
41 return os.path.join(base_dir, "metadata.gecko") | 56 return os.path.join(base_dir, "metadata.gecko") |
42 | 57 |
43 buildtools.packager.getMetadataPath = get_metadata_path | 58 tools_packager.getMetadataPath = get_metadata_path |
44 buildtools.build.processArgs(abp_dir, ["", "build", xpi_path]) | 59 tools_build.process_args(abp_dir, "build", "-t", "gecko", "-r", xpi_path) |
45 | |
46 | |
47 def _patch_abp(patched_dir): | |
48 shutil.copytree(_BASE_DIR, patched_dir) | |
49 abp_dir = os.path.join(patched_dir, _ABP_DIR) | |
50 abp_core_dir = os.path.join(abp_dir, _ABP_CORE_DIR) | |
51 subprocess.check_call(["hg", "import", "-q", "-R", abp_core_dir, | |
52 os.path.join(patched_dir, "issue-6070.patch")]) | |
53 | |
54 subprocess.check_call(["hg", "import", "-q", "-R", abp_core_dir, | |
55 os.path.join(patched_dir, "issue-6108.patch")]) | |
56 | 60 |
57 if __name__ == "__main__": | 61 if __name__ == "__main__": |
58 if len(sys.argv) < 2: | 62 if len(sys.argv) < 2: |
59 error_message = "Usage: %s XPI_PATH" % os.path.basename(sys.argv[0]) | 63 error_message = "Usage: %s XPI_PATH" % os.path.basename(sys.argv[0]) |
60 print >>sys.stderr, error_message | 64 print >>sys.stderr, error_message |
61 sys.exit(1) | 65 sys.exit(1) |
62 | 66 |
63 xpi_path = sys.argv[1] | 67 xpi_path = sys.argv[1] |
64 patched_dir = tempfile.NamedTemporaryFile().name | 68 patched_dir = tempfile.NamedTemporaryFile().name |
65 try: | 69 try: |
| 70 _copy_subscriptions(xpi_path) |
66 _patch_abp(patched_dir) | 71 _patch_abp(patched_dir) |
67 _build_abp(patched_dir, xpi_path) | 72 _build_abp(patched_dir, xpi_path) |
68 finally: | 73 finally: |
69 shutil.rmtree(patched_dir) | 74 shutil.rmtree(patched_dir) |
OLD | NEW |