1# This Source Code Form is subject to the terms of the Mozilla Public
2# License, v. 2.0. If a copy of the MPL was not distributed with this
3# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5from __future__ import absolute_import, print_function, unicode_literals
6
7from mozboot.base import BaseBootstrapper
8from mozboot.linux_common import LinuxBootstrapper
9
10
11class OpenSUSEBootstrapper(LinuxBootstrapper, BaseBootstrapper):
12    """openSUSE experimental bootstrapper."""
13
14    SYSTEM_PACKAGES = [
15        "nodejs16",
16        "npm16",
17        "which",
18        "rpmconf",
19        "libcurl-devel",
20        "libpulse-devel",
21    ]
22
23    BROWSER_PACKAGES = [
24        "alsa-devel",
25        "gcc-c++",
26        "gtk3-devel",
27        "dbus-1-glib-devel",
28        "gconf2-devel",
29        "glibc-devel-static",
30        "libstdc++-devel",
31        "libXt-devel",
32        "libproxy-devel",
33        "libuuid-devel",
34        "clang-devel",
35        "patterns-gnome-devel_gnome",
36    ]
37
38    BROWSER_GROUP_PACKAGES = [
39        "devel_C_C++",
40        "devel_gnome",
41    ]
42
43    MOBILE_ANDROID_COMMON_PACKAGES = [
44        "java-1_8_0-openjdk",
45        "wget",
46    ]
47
48    def __init__(self, version, dist_id, **kwargs):
49        print("Using an experimental bootstrapper for openSUSE.")
50        BaseBootstrapper.__init__(self, **kwargs)
51
52    def install_system_packages(self):
53        self.zypper_install(*self.SYSTEM_PACKAGES)
54
55    def install_browser_packages(self, mozconfig_builder):
56        self.ensure_browser_packages()
57
58    def install_browser_group_packages(self):
59        self.ensure_browser_group_packages()
60
61    def install_browser_artifact_mode_packages(self, mozconfig_builder):
62        self.ensure_browser_packages(artifact_mode=True)
63
64    def install_mobile_android_packages(self, mozconfig_builder):
65        self.ensure_mobile_android_packages()
66
67    def install_mobile_android_artifact_mode_packages(self, mozconfig_builder):
68        self.ensure_mobile_android_packages(artifact_mode=True)
69
70    def install_mercurial(self):
71        self(["pip", "install", "--upgrade", "pip", "--user"])
72        self(["pip", "install", "--upgrade", "Mercurial", "--user"])
73
74    def ensure_clang_static_analysis_package(self, state_dir, checkout_root):
75        from mozboot import static_analysis
76
77        self.install_toolchain_static_analysis(
78            state_dir, checkout_root, static_analysis.LINUX_CLANG_TIDY
79        )
80
81    def ensure_browser_packages(self, artifact_mode=False):
82        # TODO: Figure out what not to install for artifact mode
83        self.zypper_install(*self.BROWSER_PACKAGES)
84
85    def ensure_browser_group_packages(self, artifact_mode=False):
86        # TODO: Figure out what not to install for artifact mode
87        self.zypper_patterninstall(*self.BROWSER_GROUP_PACKAGES)
88
89    def ensure_mobile_android_packages(self, artifact_mode=False):
90        # Multi-part process:
91        # 1. System packages.
92        # 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
93
94        # 1. This is hard to believe, but the Android SDK binaries are 32-bit
95        # and that conflicts with 64-bit Arch installations out of the box.  The
96        # solution is to add the multilibs repository; unfortunately, this
97        # requires manual intervention.
98        try:
99            self.zypper_install(*self.MOBILE_ANDROID_COMMON_PACKAGES)
100        except Exception as e:
101            print(
102                "Failed to install all packages.  The Android developer "
103                "toolchain requires 32 bit binaries be enabled"
104            )
105            raise e
106
107        # 2. Android pieces.
108        super().ensure_mobile_android_packages(artifact_mode=artifact_mode)
109
110    def _update_package_manager(self):
111        self.zypper_update
112
113    def upgrade_mercurial(self, current):
114        self(["pip3", "install", "--upgrade", "pip", "--user"])
115        self(["pip3", "install", "--upgrade", "Mercurial", "--user"])
116
117    def ensure_nasm_packages(self, state_dir, checkout_root):
118        self.zypper_install("nasm")
119
120    def zypper_install(self, *packages):
121        command = ["zypper", "install"]
122        if self.no_interactive:
123            command.append("-n")
124
125        command.extend(packages)
126
127        self.run_as_root(command)
128
129    def zypper_update(self, *packages):
130        command = ["zypper", "update"]
131        if self.no_interactive:
132            command.append("-n")
133
134        command.extend(packages)
135
136        self.run_as_root(command)
137
138    def zypper_patterninstall(self, *packages):
139        command = ["zypper", "install", "-t", "pattern"]
140        if self.no_interactive:
141            command.append("-y")
142
143        command.extend(packages)
144
145        self.run_as_root(command)
146