aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo/bootstrapper/windows_msvc.py
blob: f4926276549fbfd4f132c02c26c73ec0bda9753e (plain) (blame)
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
# 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 os
import sys
import shutil
from distutils import spawn

from base import BaseBootstrapper
from packages import WINDOWS_MSVC as deps


class WindowsMsvcBootstrapper(BaseBootstrapper):
    '''Bootstrapper for MSVC building on Windows.'''

    def __init__(self, **kwargs):
        BaseBootstrapper.__init__(self, **kwargs)

    def ensure_system_packages(self):
        self.install_system_packages()

    def install_system_packages(self, packages=deps):
        from servo.bootstrap_commands import extract, download_file

        deps_dir = os.path.join(".servo", "msvc-dependencies")
        deps_url = "https://servo-rust.s3.amazonaws.com/msvc-deps/"
        first_run = True

        if self.force:
            if os.path.isdir(deps_dir):
                shutil.rmtree(deps_dir)

        if not os.path.isdir(deps_dir):
            os.makedirs(deps_dir)

        # Read file with installed dependencies, if exist
        installed_deps_file = os.path.join(deps_dir, "installed-dependencies.txt")
        if os.path.exists(installed_deps_file):
            installed_deps = [l.strip() for l in open(installed_deps_file)]
        else:
            installed_deps = []

        # list of dependencies that need to be updated
        update_deps = list(set(packages) - set(installed_deps))

        for dep in packages:
            dep_name = dep.split("-")[0]

            # Don't download CMake if already exists in PATH
            if dep_name == "cmake":
                if spawn.find_executable(dep_name):
                    continue

            dep_dir = os.path.join(deps_dir, dep_name)
            # if not installed or need to be updated
            if not os.path.exists(dep_dir) or dep in update_deps:
                if first_run:
                    print "Installing missing MSVC dependencies..."
                    first_run = False

                dep_version_dir = os.path.join(deps_dir, dep)

                if os.path.exists(dep_version_dir):
                    shutil.rmtree(dep_version_dir)

                dep_zip = dep_version_dir + ".zip"
                if not os.path.isfile(dep_zip):
                    download_file(dep, "%s%s.zip" % (deps_url, dep), dep_zip)

                print "Extracting %s..." % dep,
                extract(dep_zip, deps_dir)
                print "done"

                # Delete directory if exist
                if os.path.exists(dep_dir):
                    shutil.rmtree(dep_dir)
                os.rename(dep_version_dir, dep_dir)

        # Write in installed-dependencies.txt file
        with open(installed_deps_file, 'w') as installed_file:
            for line in packages:
                installed_file.write(line + "\n")

    def install_mobile_android_packages(self):
        sys.exit('We do not support building Android on Windows. Sorry!')