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 _ABP_UI_DIR = "adblockplusui" |
28 | 29 |
29 | 30 def _copy_subscriptions(xpi_path): |
30 def _build_abp(base_dir, xpi_path): | 31 xpi_dir = os.path.dirname(xpi_path) |
31 xpi_dir = os.path.dirname(os.path.abspath(xpi_path)) | 32 subscriptions_file = os.path.join(_BASE_DIR, _ABP_DIR, _ABP_UI_DIR, |
32 if not os.path.exists(xpi_dir): | 33 "subscriptions.xml") |
33 os.makedirs(xpi_dir) | 34 shutil.copy2(subscriptions_file, xpi_dir) |
34 | |
35 abp_dir = os.path.join(base_dir, _ABP_DIR) | |
36 sys.path.insert(0, abp_dir) | |
37 import buildtools.build | |
38 import buildtools.packager | |
39 | |
40 def get_metadata_path(dir, type): | |
41 return os.path.join(base_dir, "metadata.gecko") | |
42 | |
43 buildtools.packager.getMetadataPath = get_metadata_path | |
44 buildtools.build.processArgs(abp_dir, ["", "build", xpi_path]) | |
45 | 35 |
46 | 36 |
47 def _patch_abp(patched_dir): | 37 def _patch_abp(patched_dir): |
48 shutil.copytree(_BASE_DIR, patched_dir) | 38 shutil.copytree(_BASE_DIR, patched_dir) |
49 abp_dir = os.path.join(patched_dir, _ABP_DIR) | 39 abp_dir = os.path.join(patched_dir, _ABP_DIR) |
50 abp_core_dir = os.path.join(abp_dir, _ABP_CORE_DIR) | 40 abp_core_dir = os.path.join(abp_dir, _ABP_CORE_DIR) |
51 subprocess.check_call(["hg", "import", "-q", "-R", abp_core_dir, | 41 subprocess.check_call(["hg", "import", "-q", "-R", abp_core_dir, |
52 os.path.join(patched_dir, "issue-6070.patch")]) | 42 os.path.join(patched_dir, "issue-6070.patch")]) |
53 | 43 |
54 subprocess.check_call(["hg", "import", "-q", "-R", abp_core_dir, | 44 def _build_abp(base_dir, xpi_path): |
55 os.path.join(patched_dir, "issue-6108.patch")]) | 45 xpi_dir = os.path.dirname(os.path.abspath(xpi_path)) |
| 46 if not os.path.exists(xpi_dir): |
| 47 os.makedirs(xpi_dir) |
| 48 |
| 49 abp_dir = os.path.join(base_dir, _ABP_DIR) |
| 50 sys.path.insert(0, abp_dir) |
| 51 import buildtools.build as tools_build |
| 52 import buildtools.packager as tools_packager |
| 53 |
| 54 def get_metadata_path(dir, type): |
| 55 return os.path.join(base_dir, "metadata.gecko") |
| 56 |
| 57 tools_packager.getMetadataPath = get_metadata_path |
| 58 tools_build.process_args(abp_dir, "build", "-t", "gecko", "-r", xpi_path) |
56 | 59 |
57 if __name__ == "__main__": | 60 if __name__ == "__main__": |
58 if len(sys.argv) < 2: | 61 if len(sys.argv) < 2: |
59 error_message = "Usage: %s XPI_PATH" % os.path.basename(sys.argv[0]) | 62 error_message = "Usage: %s XPI_PATH" % os.path.basename(sys.argv[0]) |
60 print >>sys.stderr, error_message | 63 print >>sys.stderr, error_message |
61 sys.exit(1) | 64 sys.exit(1) |
62 | 65 |
63 xpi_path = sys.argv[1] | 66 xpi_path = sys.argv[1] |
64 patched_dir = tempfile.NamedTemporaryFile().name | 67 patched_dir = tempfile.NamedTemporaryFile().name |
65 try: | 68 try: |
| 69 _copy_subscriptions(xpi_path) |
66 _patch_abp(patched_dir) | 70 _patch_abp(patched_dir) |
67 _build_abp(patched_dir, xpi_path) | 71 _build_abp(patched_dir, xpi_path) |
68 finally: | 72 finally: |
69 shutil.rmtree(patched_dir) | 73 shutil.rmtree(patched_dir) |
OLD | NEW |