LEFT | RIGHT |
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_PATH = os.path.dirname(os.path.abspath(__file__)) |
26 _ABP_DIR = "adblockpluschrome" | 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", | 28 _SUBSCRIPTIONS_PATH = os.path.join(_BASE_DIR_PATH, _ABP_DIR, _ABP_CORE_DIR, |
29 "content", "ui", "subscriptions.xml") | 29 "chrome", "content", "ui", |
| 30 "subscriptions.xml") |
30 | 31 |
31 | 32 |
32 def _copy_subscriptions(xpi_path): | 33 def _import_issue_patch(src_path, patched_path, issue_name): |
33 xpi_dir = os.path.dirname(xpi_path) | 34 patch_filename = "issue-%s.patch" % issue_name |
34 shutil.copy2(_SUBSCRIPTIONS_PATH, xpi_dir) | 35 subprocess.check_call(["hg", "import", "-q", "-R", src_path, |
| 36 os.path.join(patched_path, patch_filename)]) |
35 | 37 |
36 | 38 |
37 def _patch_abp(patched_dir): | 39 def _patch_abp(patched_path): |
38 shutil.copytree(_BASE_DIR, patched_dir) | 40 shutil.copytree(_BASE_DIR_PATH, patched_path) |
39 abp_dir = os.path.join(patched_dir, _ABP_DIR) | 41 abp_path = os.path.join(patched_path, _ABP_DIR) |
40 abp_core_dir = os.path.join(abp_dir, _ABP_CORE_DIR) | 42 abp_core_path = os.path.join(abp_path, _ABP_CORE_DIR) |
41 subprocess.check_call(["hg", "import", "-q", "-R", abp_core_dir, | 43 _import_issue_patch(abp_core_path, patched_path, "6070") |
42 os.path.join(patched_dir, "issue-6070.patch")]) | 44 _import_issue_patch(abp_path, patched_path, "6865") |
43 | 45 |
44 | 46 |
45 def _build_abp(base_dir, xpi_path): | 47 def _build_abp(base_path, xpi_path): |
46 xpi_dir = os.path.dirname(os.path.abspath(xpi_path)) | 48 xpi_dir_path = os.path.dirname(xpi_path) |
47 if not os.path.exists(xpi_dir): | 49 if not os.path.exists(xpi_dir_path): |
48 os.makedirs(xpi_dir) | 50 os.makedirs(xpi_dir_path) |
49 | 51 |
50 abp_dir = os.path.join(base_dir, _ABP_DIR) | 52 abp_dir_path = os.path.join(base_path, _ABP_DIR) |
51 sys.path.insert(0, abp_dir) | 53 sys.path.insert(0, abp_dir_path) |
52 import buildtools.build as tools_build | 54 import buildtools.build as tools_build |
53 import buildtools.packager as tools_packager | 55 import buildtools.packager as tools_packager |
54 | 56 |
55 def get_metadata_path(dir, type): | 57 def get_metadata_path(dir, type): |
56 return os.path.join(base_dir, "metadata.gecko") | 58 return os.path.join(base_path, "metadata.gecko") |
57 | 59 |
58 tools_packager.getMetadataPath = get_metadata_path | 60 tools_packager.getMetadataPath = get_metadata_path |
59 tools_build.process_args(abp_dir, "build", "-t", "gecko", "-r", xpi_path) | 61 tools_build.process_args(abp_dir_path, "build", "-t", "gecko", "-r", |
| 62 xpi_path) |
| 63 |
| 64 |
| 65 def _copy_subscriptions(xpi_path): |
| 66 xpi_dir_path = os.path.dirname(xpi_path) |
| 67 shutil.copy2(_SUBSCRIPTIONS_PATH, xpi_dir_path) |
| 68 |
60 | 69 |
61 if __name__ == "__main__": | 70 if __name__ == "__main__": |
62 if len(sys.argv) < 2: | 71 if len(sys.argv) < 2: |
63 error_message = "Usage: %s XPI_PATH" % os.path.basename(sys.argv[0]) | 72 error_message = "Usage: %s XPI_PATH" % os.path.basename(sys.argv[0]) |
64 print >>sys.stderr, error_message | 73 print >>sys.stderr, error_message |
65 sys.exit(1) | 74 sys.exit(1) |
66 | 75 |
67 xpi_path = sys.argv[1] | 76 xpi_path = os.path.abspath(sys.argv[1]) |
68 patched_dir = tempfile.NamedTemporaryFile().name | 77 patched_path = tempfile.NamedTemporaryFile().name |
69 try: | 78 try: |
| 79 _patch_abp(patched_path) |
| 80 _build_abp(patched_path, xpi_path) |
70 _copy_subscriptions(xpi_path) | 81 _copy_subscriptions(xpi_path) |
71 _patch_abp(patched_dir) | |
72 _build_abp(patched_dir, xpi_path) | |
73 finally: | 82 finally: |
74 shutil.rmtree(patched_dir) | 83 shutil.rmtree(patched_path) |
LEFT | RIGHT |