diff options
Diffstat (limited to 'python/mozboot/bin')
-rw-r--r-- | python/mozboot/bin/bootstrap-msys2.vbs | 116 | ||||
-rwxr-xr-x | python/mozboot/bin/bootstrap.py | 170 |
2 files changed, 286 insertions, 0 deletions
diff --git a/python/mozboot/bin/bootstrap-msys2.vbs b/python/mozboot/bin/bootstrap-msys2.vbs new file mode 100644 index 000000000..304d4f9df --- /dev/null +++ b/python/mozboot/bin/bootstrap-msys2.vbs @@ -0,0 +1,116 @@ +' 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/. + +' This script downloads and install MSYS2 and the preferred terminal emulator ConEmu + +Sub Download(uri, path) + Dim httpRequest, stream + + Set httpRequest = CreateObject("MSXML2.ServerXMLHTTP.6.0") + Set stream = CreateObject("Adodb.Stream") + + httpRequest.Open "GET", uri, False + httpRequest.Send + + With stream + .type = 1 + .open + .write httpRequest.responseBody + .savetofile path, 2 + End With +End Sub + +Function GetInstallPath() + Dim message, prompt + + message = "When you click OK, we will download and extract a build environment to the directory specified. You should see various windows appear. Do NOT interact with them until one explicitly prompts you to continue." & vbCrLf & vbCrLf & "Installation Path:" + title = "Select Installation Location" + GetInstallPath = InputBox(message, title, "c:\mozdev") +end Function + +Dim installPath, msysPath, conemuPath, conemuSettingsPath, conemuExecutable, bashExecutable +Dim conemuSettingsURI, settingsFile, settingsText, fso, shell, msysArchive, appShell, errorCode +Dim mingwExecutable + +' Set up OS interaction like filesystem and shell +Set fso = CreateObject("Scripting.FileSystemObject") +Set shell = CreateObject("WScript.Shell") +Set appShell = CreateObject("Shell.Application") + +' Get where MSYS2 and ConEmu should be installed, create directories if necessary +installPath = GetInstallPath() +msysPath = fso.BuildPath(installPath, "msys64") +conemuPath = fso.BuildPath(installPath, "ConEmu") +If NOT fso.FolderExists(installPath) Then + fso.CreateFolder(installPath) + fso.CreateFolder(msysPath) +End If +If NOT fso.FolderExists(installPath) Then + MsgBox("Failed to create folder. Do you have permission to install in this directory?") + WScript.Quit 1 +End If + +On Error Resume Next +' Download and move MSYS2 into the right place +Download "https://api.pub.build.mozilla.org/tooltool/sha512/f93a685c8a10abbd349cbef5306441ba235c4cbfba1cc000299e11b58f258e9953cbe23463515407925eeca94c3f5d8e5f637c95be387e620845efa43cdcb0c0", "msys2.zip" +Set FilesInZip = appShell.NameSpace(fso.GetAbsolutePathName("msys2.zip")).Items() +appShell.NameSpace(msysPath).CopyHere(FilesInZip) +' MSYS2 archive doesn't have tmp directory... +fso.CreateFolder(fso.BuildPath(msysPath, "tmp")) +fso.DeleteFile("msys2.zip") +If Err.Number <> 0 Then + MsgBox("Error downloading and installing MSYS2. Make sure you have internet connection. If you think this is a bug, please file one in Bugzilla https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config") + WScript.Quit 1 +End If +On Error GoTo 0 + +' Install ConEmu +' Download installer +On Error Resume Next +Download "https://conemu.github.io/install2.ps1", "install2.ps1" +conemuSettingsURI = "https://api.pub.build.mozilla.org/tooltool/sha512/9aa384ecc8025a974999e913c83064b3b797e05d19806e62ef558c8300e4c3f72967e9464ace59759f76216fc2fc66f338a1e5cdea3b9aa264529487f091d929" +' Run installer +errorCode = shell.Run("powershell.exe -NoProfile -ExecutionPolicy Unrestricted set dst '" & conemuPath & "'; set ver 'stable'; set lnk 'Mozilla Development Shell'; set xml '" & conemuSettingsURI & "'; set run $FALSE; .\install2.ps1", 0, true) +' Delete ConEmu installer +fso.DeleteFile("install2.ps1") +If Err.Number <> 0 Then + MsgBox("Error downloading and installing ConEmu. Make sure you have internet connection and Powershell installed. If you think this is a bug, please file one in Bugzilla https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config") + WScript.Quit 1 +End If +On Error GoTo 0 + +' Replace paths in ConEmu settings file +conemuSettingsPath = fso.BuildPath(conemuPath, "ConEmu.xml") +Set settingsFile = fso.OpenTextFile(conemuSettingsPath, 1) +settingsText = settingsFile.ReadAll +settingsFile.Close +settingsText = Replace(settingsText, "%MSYS2_PATH", msysPath) +Set settingsFile = fso.OpenTextFile(conemuSettingsPath, 2) +settingsFile.WriteLine settingsText +settingsFile.Close + +' Make MSYS2 Mozilla-ready +bashExecutable = fso.BuildPath(msysPath, fso.BuildPath("usr", fso.BuildPath("bin", "bash.exe"))) +conemuExecutable = fso.BuildPath(conemuPath, "ConEmu.exe") +' There may be spaces in the paths to the executable, this ensures they're parsed correctly +bashExecutable = """" & bashExecutable & """" +conemuExecutable = """" & conemuExecutable & """" + +errorCode = shell.Run(bashExecutable & " -l -c 'logout", 1, true) +If errorCode <> 0 Then + MsgBox("MSYS2 initial setup failed. Make sure you have full access to the path you specified. If you think this is a bug, please file one in Bugzilla at https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config") + WScript.Quit 1 +End If + +errorCode = shell.Run(bashExecutable & " -l -c 'pacman -Syu --noconfirm wget mingw-w64-x86_64-python2-pip && logout'", 1, true) +If errorCode <> 0 Then + MsgBox("Package update failed. Make sure you have internet access. If you think this is a bug, please file one in Bugzilla at https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config") + WScript.Quit 1 +End If + +errorCode = shell.Run(conemuExecutable & " -run set CHERE_INVOKING=1 & set MSYSTEM=MINGW64 & " & bashExecutable & " -cil 'export MOZ_WINDOWS_BOOTSTRAP=1 && cd """ & installPath & """ && wget -q https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py -O /tmp/bootstrap.py && python /tmp/bootstrap.py'", 1, true) +If errorCode <> 0 Then + MsgBox("Bootstrap failed. Make sure you have internet access. If you think this is a bug, please file one in Bugzilla https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Build%20Config") + WScript.Quit 1 +End If diff --git a/python/mozboot/bin/bootstrap.py b/python/mozboot/bin/bootstrap.py new file mode 100755 index 000000000..d916351e7 --- /dev/null +++ b/python/mozboot/bin/bootstrap.py @@ -0,0 +1,170 @@ +#!/usr/bin/env python +# 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/. + +# This script provides one-line bootstrap support to configure systems to build +# the tree. +# +# The role of this script is to load the Python modules containing actual +# bootstrap support. It does this through various means, including fetching +# content from the upstream source repository. + +# If we add unicode_literals, optparse breaks on Python 2.6.1 (which is needed +# to support OS X 10.6). + +from __future__ import print_function + +WRONG_PYTHON_VERSION_MESSAGE = ''' +Bootstrap currently only runs on Python 2.7 or Python 2.6. Please try re-running with python2.7 or python2.6. + +If these aren't available on your system, you may need to install them. Look for a "python2" or "python27" package in your package manager. +''' + +import sys +if sys.version_info[:2] not in [(2, 6), (2, 7)]: + print(WRONG_PYTHON_VERSION_MESSAGE) + sys.exit(1) + +import os +import shutil +from StringIO import StringIO +import tempfile +try: + from urllib2 import urlopen +except ImportError: + from urllib.request import urlopen +import zipfile + +from optparse import OptionParser + +# The next two variables define where in the repository the Python files +# reside. This is used to remotely download file content when it isn't +# available locally. +REPOSITORY_PATH_PREFIX = 'python/mozboot/' + +TEMPDIR = None + + +def setup_proxy(): + # Some Linux environments define ALL_PROXY, which is a SOCKS proxy + # intended for all protocols. Python doesn't currently automatically + # detect this like it does for http_proxy and https_proxy. + if 'ALL_PROXY' in os.environ and 'https_proxy' not in os.environ: + os.environ['https_proxy'] = os.environ['ALL_PROXY'] + if 'ALL_PROXY' in os.environ and 'http_proxy' not in os.environ: + os.environ['http_proxy'] = os.environ['ALL_PROXY'] + + +def fetch_files(repo_url, repo_type): + setup_proxy() + repo_url = repo_url.rstrip('/') + + files = {} + + if repo_type == 'hgweb': + url = repo_url + '/archive/default.zip/python/mozboot' + req = urlopen(url=url, timeout=30) + data = StringIO(req.read()) + data.seek(0) + zip = zipfile.ZipFile(data, 'r') + for f in zip.infolist(): + # The paths are prefixed with the repo and revision name before the + # directory name. + offset = f.filename.find(REPOSITORY_PATH_PREFIX) + len(REPOSITORY_PATH_PREFIX) + name = f.filename[offset:] + + # We only care about the Python modules. + if not name.startswith('mozboot/'): + continue + + files[name] = zip.read(f) + else: + raise NotImplementedError('Not sure how to handle repo type.', repo_type) + + return files + + +def ensure_environment(repo_url=None, repo_type=None): + """Ensure we can load the Python modules necessary to perform bootstrap.""" + + try: + from mozboot.bootstrap import Bootstrapper + return Bootstrapper + except ImportError: + # The first fallback is to assume we are running from a tree checkout + # and have the files in a sibling directory. + pardir = os.path.join(os.path.dirname(__file__), os.path.pardir) + include = os.path.normpath(pardir) + + sys.path.append(include) + try: + from mozboot.bootstrap import Bootstrapper + return Bootstrapper + except ImportError: + sys.path.pop() + + # The next fallback is to download the files from the source + # repository. + files = fetch_files(repo_url, repo_type) + + # Install them into a temporary location. They will be deleted + # after this script has finished executing. + global TEMPDIR + TEMPDIR = tempfile.mkdtemp() + + for relpath in files.keys(): + destpath = os.path.join(TEMPDIR, relpath) + destdir = os.path.dirname(destpath) + + if not os.path.exists(destdir): + os.makedirs(destdir) + + with open(destpath, 'wb') as fh: + fh.write(files[relpath]) + + # This should always work. + sys.path.append(TEMPDIR) + from mozboot.bootstrap import Bootstrapper + return Bootstrapper + + +def main(args): + parser = OptionParser() + parser.add_option('-r', '--repo-url', dest='repo_url', + default='https://hg.mozilla.org/mozilla-central/', + help='Base URL of source control repository where bootstrap files can ' + 'be downloaded.') + parser.add_option('--repo-type', dest='repo_type', + default='hgweb', + help='The type of the repository. This defines how we fetch file ' + 'content. Like --repo, you should not need to set this.') + + parser.add_option('--application-choice', dest='application_choice', + help='Pass in an application choice (desktop/android) instead of using the ' + 'default interactive prompt.') + parser.add_option('--no-interactive', dest='no_interactive', action='store_true', + help='Answer yes to any (Y/n) interactive prompts.') + + options, leftover = parser.parse_args(args) + + try: + try: + cls = ensure_environment(options.repo_url, options.repo_type) + except Exception as e: + print('Could not load the bootstrap Python environment.\n') + print('This should never happen. Consider filing a bug.\n') + print('\n') + print(e) + return 1 + dasboot = cls(choice=options.application_choice, no_interactive=options.no_interactive) + dasboot.bootstrap() + + return 0 + finally: + if TEMPDIR is not None: + shutil.rmtree(TEMPDIR) + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) |