def _get_buck_version_uid(self): with Tracing('BuckRepo._get_buck_version_uid'): # Check if the developer has requested that we impersonate some other version. fake_buck_version_file_path = os.path.join(self._buck_dir, ".fakebuckversion") if os.path.exists(fake_buck_version_file_path): with open( fake_buck_version_file_path) as fake_buck_version_file: fake_buck_version = fake_buck_version_file.read().strip() print(textwrap.dedent("""\ ::: Faking buck version %s, despite your buck directory not being that version.""" % fake_buck_version), file=sys.stderr) return fake_buck_version # First try to get the "clean" buck version. If it succeeds, # return it. clean_version = buck_version.get_clean_buck_version( self._buck_dir, allow_dirty=self._is_buck_repo_dirty_override == "1") if clean_version is not None: return clean_version # Otherwise, if there is a .nobuckcheck file, or if there isn't # a .buckversion file, fall back to a "dirty" version. if (self._buck_project.has_no_buck_check or not self._buck_project.buck_version): return buck_version.get_dirty_buck_version(self._buck_dir) if self._has_local_changes(): print(textwrap.dedent("""\ ::: Your buck directory has local modifications, and therefore ::: builds will not be able to use a distributed cache. ::: The following files must be either reverted or committed:""" ), file=sys.stderr) subprocess.call(['git', 'ls-files', '-m'], stdout=sys.stderr, cwd=self._buck_dir) elif os.environ.get('BUCK_CLEAN_REPO_IF_DIRTY') != 'NO': print(textwrap.dedent("""\ ::: Your local buck directory is dirty, and therefore builds will ::: not be able to use a distributed cache."""), file=sys.stderr) if sys.stdout.isatty(): print( "::: Do you want to clean your buck directory? [y/N]", file=sys.stderr) choice = raw_input().lower() if choice == "y": subprocess.call(['git', 'clean', '-fd'], stdout=sys.stderr, cwd=self._buck_dir) raise RestartBuck() return buck_version.get_dirty_buck_version(self._buck_dir)
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()
def _get_buck_version_uid(self): with Tracing('BuckRepo._get_buck_version_uid'): if not self._is_git: return 'N/A' if not self._is_dirty(): return self._get_git_revision() if (self._buck_project.has_no_buck_check or not self._buck_project.buck_version): return self._compute_local_hash() if self._has_local_changes(): print(textwrap.dedent("""\ ::: Your buck directory has local modifications, and therefore ::: builds will not be able to use a distributed cache. ::: The following files must be either reverted or committed:""" ), file=sys.stderr) subprocess.call(['git', 'ls-files', '-m'], stdout=sys.stderr, cwd=self._buck_dir) elif os.environ.get('BUCK_CLEAN_REPO_IF_DIRTY') != 'NO': print(textwrap.dedent("""\ ::: Your local buck directory is dirty, and therefore builds will ::: not be able to use a distributed cache."""), file=sys.stderr) if sys.stdout.isatty(): print( "::: Do you want to clean your buck directory? [y/N]", file=sys.stderr) choice = raw_input().lower() if choice == "y": subprocess.call(['git', 'clean', '-fd'], stdout=sys.stderr, cwd=self._buck_dir) raise RestartBuck() return self._compute_local_hash()