def main(argv): # Locate the root of the buck repo. We'll need to be there to # generate the buck version UID. path = os.getcwd() while not os.path.exists(os.path.join(path, '.buckconfig')): path = os.path.dirname(path) if os.path.exists(os.path.join(path, '.git')): # Attempt to create a "clean" version, but fall back to a "dirty" # one if need be. version = buck_version.get_clean_buck_version(path) timestamp = -1 if version is None: version = buck_version.get_dirty_buck_version(path) else: timestamp = buck_version.get_git_revision_timestamp(path) else: # We're building outside a git repo. Check for the special # .buckrelease file created by the release process. try: with open(os.path.join(path, '.buckrelease')) as f: timestamp = int(os.fstat(f.fileno()).st_mtime) version = f.read().strip() except IOError, e: if e.errno == errno.ENOENT: # No .buckrelease file. Do the best that we can. version = '(unknown version)' timestamp = int(time.time()) else: raise e
def main(argv): parser = argparse.ArgumentParser() parser.add_argument("--release-version", help="The buck release version") parser.add_argument( "--release-timestamp", help="The unix timestamp when the release happened" ) args = parser.parse_args(argv[1:]) if bool(args.release_version) != bool(args.release_timestamp): print( "--release-version and --release-timestamp must either both be " "set, or neither can be set" ) sys.exit(1) # Locate the root of the buck repo. We'll need to be there to # generate the buck version UID. path = os.getcwd() while not os.path.exists(os.path.join(path, ".buckconfig")): path = os.path.dirname(path) if args.release_version: version = args.release_version timestamp = args.release_timestamp dirty = False elif os.path.exists(os.path.join(path, ".git")): # Attempt to create a "clean" version, but fall back to a "dirty" # one if need be. version = buck_version.get_clean_buck_version(path) timestamp = -1 if version is None: version = buck_version.get_dirty_buck_version(path) else: timestamp = buck_version.get_git_revision_timestamp(path) dirty = buck_version.is_dirty(path) else: # We're building outside a git repo. Check for the special # .buckrelease file created by the release process. try: with open(os.path.join(path, ".buckrelease")) as f: timestamp = int(os.fstat(f.fileno()).st_mtime) version = f.read().strip() except IOError as e: if e.errno == errno.ENOENT: # No .buckrelease file. Do the best that we can. version = "(unknown version)" timestamp = int(time.time()) else: raise e dirty = False json.dump( {"version": version, "timestamp": timestamp, "is_dirty": dirty}, sys.stdout, sort_keys=True, indent=2, )
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! ::: We hope you know what you are doing...""" % 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 _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 _get_buck_version_uid(self): with Tracing('BuckRepo._get_buck_version_uid'): if self._fake_buck_version: return self._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 return buck_version.get_dirty_buck_version(self.buck_dir)
def main(argv): # Locate the root of the buck repo. We'll need to be there to # generate the buck version UID. path = os.getcwd() while not os.path.exists(os.path.join(path, '.buckconfig')): path = os.path.dirname(path) # Attempt to create a "clean" version, but fall back to a "dirty" # one if need be. version = buck_version.get_clean_buck_version(path) if version is None: version = buck_version.get_dirty_buck_version(path) sys.stdout.write(version)
def _get_buck_version_uid(self): with Tracing('BuckRepo._get_buck_version_uid'): # 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 main(argv): # Locate the root of the buck repo. We'll need to be there to # generate the buck version UID. path = os.getcwd() while not os.path.exists(os.path.join(path, ".buckconfig")): path = os.path.dirname(path) if os.path.exists(os.path.join(path, ".git")): # Attempt to create a "clean" version, but fall back to a "dirty" # one if need be. version = buck_version.get_clean_buck_version(path) timestamp = -1 if version is None: version = buck_version.get_dirty_buck_version(path) else: timestamp = buck_version.get_git_revision_timestamp(path) dirty = buck_version.is_dirty(path) else: # We're building outside a git repo. Check for the special # .buckrelease file created by the release process. try: with open(os.path.join(path, ".buckrelease")) as f: timestamp = int(os.fstat(f.fileno()).st_mtime) version = f.read().strip() except IOError as e: if e.errno == errno.ENOENT: # No .buckrelease file. Do the best that we can. version = "(unknown version)" timestamp = int(time.time()) else: raise e dirty = False json.dump( { "version": version, "timestamp": timestamp, "is_dirty": dirty }, sys.stdout, sort_keys=True, indent=2, )
def main(argv): # Locate the root of the buck repo. We'll need to be there to # generate the buck version UID. path = os.getcwd() while not os.path.exists(os.path.join(path, '.buckconfig')): path = os.path.dirname(path) # Attempt to create a "clean" version, but fall back to a "dirty" # one if need be. version = buck_version.get_clean_buck_version(path) timestamp = -1 if version is None: version = buck_version.get_dirty_buck_version(path) else: timestamp = buck_version.get_git_revision_timestamp(path) json.dump( {'version': version, 'timestamp': timestamp}, sys.stdout, sort_keys=True, indent=2)
def main(argv): # Locate the root of the buck repo. We'll need to be there to # generate the buck version UID. path = os.getcwd() while not os.path.exists(os.path.join(path, '.buckconfig')): path = os.path.dirname(path) # Attempt to create a "clean" version, but fall back to a "dirty" # one if need be. version = buck_version.get_clean_buck_version(path) timestamp = -1 if version is None: version = buck_version.get_dirty_buck_version(path) else: timestamp = buck_version.get_git_revision_timestamp(path) json.dump({ 'version': version, 'timestamp': timestamp }, sys.stdout, sort_keys=True, indent=2)
def main(argv): parser = argparse.ArgumentParser() parser.add_argument("--release-version", help="The buck release version") parser.add_argument("--release-timestamp", help="The unix timestamp when the release happened") parser.add_argument( "--java-version", help="The Java version buck was compiled against", required=True, ) args = parser.parse_args(argv[1:]) if bool(args.release_version) != bool(args.release_timestamp): print("--release-version and --release-timestamp must either both be " "set, or neither can be set") sys.exit(1) # Locate the root of the buck repo. We'll need to be there to # generate the buck version UID. path = os.getcwd() while not os.path.exists(os.path.join(path, ".buckconfig")): path = os.path.dirname(path) if args.release_version: version = args.release_version timestamp = args.release_timestamp dirty = False elif os.path.exists(os.path.join(path, ".git")): # Attempt to create a "clean" version, but fall back to a "dirty" # one if need be. version = buck_version.get_clean_buck_version(path) timestamp = -1 if version is None: version = buck_version.get_dirty_buck_version(path) else: timestamp = buck_version.get_git_revision_timestamp(path) dirty = buck_version.is_dirty(path) else: # We're building outside a git repo. Check for the special # .buckrelease file created by the release process. try: with open(os.path.join(path, ".buckrelease")) as f: timestamp = int(os.fstat(f.fileno()).st_mtime) version = f.read().strip() except IOError as e: if e.errno == errno.ENOENT: # No .buckrelease file. Do the best that we can. version = "(unknown version)" timestamp = int(time.time()) else: raise e dirty = False java_version = (int(args.java_version.split(".")[1]) if "." in args.java_version else int(args.java_version)) json.dump( { "version": version, "timestamp": timestamp, "is_dirty": dirty, "java_version": java_version, }, sys.stdout, sort_keys=True, indent=2, )