Пример #1
0
    def install_toolchain_artifact(self,
                                   state_dir,
                                   checkout_root,
                                   toolchain_job,
                                   no_unpack=False):
        mach_binary = os.path.join(checkout_root, 'mach')
        mach_binary = os.path.abspath(mach_binary)
        if not os.path.exists(mach_binary):
            raise ValueError("mach not found at %s" % mach_binary)

        # NOTE: Use self.state_dir over the passed-in state_dir, which might be
        # a subdirectory of the actual state directory.
        if not self.state_dir:
            raise ValueError(
                'Need a state directory (e.g. ~/.mozbuild) to download '
                'artifacts')
        python_location = get_mach_virtualenv_binary(state_dir=self.state_dir)
        if not os.path.exists(python_location):
            raise ValueError('python not found at %s' % python_location)

        cmd = [
            python_location, mach_binary, 'artifact', 'toolchain',
            '--bootstrap', '--from-build', toolchain_job
        ]

        if no_unpack:
            cmd += ['--no-unpack']

        subprocess.check_call(cmd, cwd=state_dir)
Пример #2
0
 def check_telemetry_opt_in(self, state_dir):
     # Don't prompt if the user already has a setting for this value.
     if (
         self.mach_context is not None
         and "telemetry" in self.mach_context.settings.build
     ):
         return self.mach_context.settings.build.telemetry
     # We can't prompt the user.
     if self.instance.no_interactive:
         return False
     mach_python = get_mach_virtualenv_binary()
     proc = subprocess.run(
         [mach_python, "-c", "import glean"],
         stdout=subprocess.DEVNULL,
         stderr=subprocess.DEVNULL,
     )
     # If we couldn't install glean in the mach environment, we can't
     # enable telemetry.
     if proc.returncode != 0:
         return False
     choice = self.instance.prompt_yesno(prompt=TELEMETRY_OPT_IN_PROMPT)
     if choice:
         cfg_file = os.environ.get("MACHRC", os.path.join(state_dir, "machrc"))
         if update_or_create_build_telemetry_config(cfg_file):
             print(
                 "\nThanks for enabling build telemetry! You can change this setting at "
                 + "any time by editing the config file `{}`\n".format(cfg_file)
             )
     return choice
Пример #3
0
def create_telemetry_from_environment(settings):
    """Creates and a Telemetry instance based on system details.

    If telemetry isn't enabled, the current interpreter isn't Python 3, or Glean
    can't be imported, then a "mock" telemetry instance is returned that doesn't
    set or record any data. This allows consumers to optimistically set telemetry
    data without needing to specifically handle the case where the current system
    doesn't support it.
    """

    is_mach_virtualenv = mozpack.path.normpath(sys.executable) == mozpack.path.normpath(
        get_mach_virtualenv_binary()
    )

    if not (
        is_applicable_telemetry_environment()
        # Glean is not compatible with Python 2
        and sys.version_info >= (3, 0)
        # If not using the mach virtualenv (e.g.: bootstrap uses native python)
        # then we can't guarantee that the glean package that we import is a
        # compatible version. Therefore, don't use glean.
        and is_mach_virtualenv
    ):
        return NoopTelemetry(False)

    try:
        from glean import Glean
    except ImportError:
        return NoopTelemetry(True)

    from pathlib import Path

    Glean.initialize(
        "mozilla.mach",
        "Unknown",
        is_telemetry_enabled(settings),
        data_dir=Path(get_state_dir()) / "glean",
    )
    return GleanTelemetry()