Exemple #1
0
 def _check_for_ant(self):
     ant = which('ant')
     if not ant:
         message = "You do not have ant on your $PATH. Cannot build Buck."
         if sys.platform == "darwin":
             message += "\nTry running 'brew install ant'."
         raise BuckToolException(message)
     return ant
Exemple #2
0
    def _checkout_and_clean(self, revision, branch):
        with Tracing('BuckRepo._checkout_and_clean'):
            if not self._revision_exists(revision):
                print(textwrap.dedent("""\
                    Required revision {0} is not
                    available in the local repository.
                    Buck is fetching updates from git. You can disable this by creating
                    a '.nobuckcheck' file in your repository, but this might lead to
                    strange bugs or build failures.""".format(revision)),
                      file=sys.stderr)
                git_command = ['git', 'fetch']
                git_command.extend(['--all'] if not branch else ['origin', branch])
                try:
                    subprocess.check_call(
                        git_command,
                        stdout=sys.stderr,
                        cwd=self._buck_dir)
                except subprocess.CalledProcessError:
                    raise BuckToolException(textwrap.dedent("""\
                          Failed to fetch Buck updates from git."""))

            current_revision = self._get_git_revision()

            if current_revision != revision:
                print(textwrap.dedent("""\
                    Buck is at {0}, but should be {1}.
                    Buck is updating itself. To disable this, add a '.nobuckcheck'
                    file to your project root. In general, you should only disable
                    this if you are developing Buck.""".format(
                    current_revision, revision)),
                    file=sys.stderr)

                try:
                    subprocess.check_call(
                        ['git', 'checkout', '--quiet', revision],
                        cwd=self._buck_dir)
                except subprocess.CalledProcessError:
                    raise BuckToolException(textwrap.dedent("""\
                          Failed to update Buck to revision {0}.""".format(revision)))
                if os.path.exists(self._build_success_file):
                    os.remove(self._build_success_file)

                ant = self._check_for_ant()
                self._run_ant_clean(ant)
                raise RestartBuck()
Exemple #3
0
 def _print_ant_failure_and_exit(self, ant_log_path):
     print(textwrap.dedent("""\
             ::: 'ant' failed in the buck repo at '{0}',
             ::: and 'buck' is not properly built. It will be unusable
             ::: until the error is corrected. You can check the logs
             ::: at {1} to figure out what broke.""".format(
         self._buck_dir, ant_log_path)),
           file=sys.stderr)
     if self._is_git:
         raise BuckToolException(
             textwrap.dedent("""\
             ::: It is possible that running this command will fix it:
             ::: git -C "{0}" clean -xfd""".format(self._buck_dir)))
     else:
         raise BuckToolException(
             textwrap.dedent("""\
             ::: It is possible that running this command will fix it:
             ::: rm -rf "{0}"/build""".format(self._buck_dir)))
Exemple #4
0
def get_java_path(required_java_version):
    java_home_path = os.getenv("JAVA_HOME")
    if java_home_path:
        # Though we try to respect JAVA_HOME, if the path looks like the wrong version of Java, try
        # to use a known location of the JDK for the right version instead.
        suspected_java_version = _get_suspected_java_version_from_java_path(
            java_home_path)
        if suspected_java_version and suspected_java_version != required_java_version:
            message = (
                'Warning: JAVA_HOME is set to "{}", which looks like a Java {} path, '
                + "but Buck requires Java {}.").format(java_home_path,
                                                       suspected_java_version,
                                                       required_java_version)
            if os.getenv("BUCK_RESPECT_JAVA_HOME") != "1":
                message += " Ignoring JAVA_HOME. Set BUCK_RESPECT_JAVA_HOME to 1 to disable this behavior."
                java_home_path = None
            logging.warning(message)
    if java_home_path is None:
        # Default to a known location of the JDK for the right version of Java, regardless of what
        # version of Java is on the PATH.
        java_base_path = _get_known_java_path_for_version(
            required_java_version)
        java_path = None
        if java_base_path:
            java_path = _get_java_exec(java_base_path)
            if not os.path.isfile(java_path):
                java_path = None
        if not java_path:
            java_path = which("java")
        if java_path is None:
            raise BuckToolException("Could not find Java executable. \
Make sure it is on PATH or JAVA_HOME is set.")
    else:
        java_path = _get_java_exec(java_home_path)
        if not os.path.isfile(java_path):
            message = textwrap.dedent("""
            Could not find Java executable under JAVA_HOME at: '{}'.
            Please make sure your JAVA_HOME environment variable is set correctly.
            Then restart buck (buck kill) and try again.
            """).format(java_path)
            raise BuckToolException(message)
    return java_path