Ejemplo n.º 1
0
def _get_java_version(java_path):
    """
    Returns a Java version string (e.g. "7", "8").

    Information is provided by java tool and parsing is based on
    http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
    """
    java_version = check_output([java_path, "-version"],
                                stderr=subprocess.STDOUT).decode("utf-8")
    # extract java version from a string like 'java version "1.8.0_144"' or
    # 'openjdk version "11.0.1" 2018-10-16'
    match = re.search('(java|openjdk) version "(?P<version>.+)"', java_version)
    if not match:
        return None
    return get_java_major_version(match.group("version"))
Ejemplo n.º 2
0
def _get_java_version(java_path):
    """
    Returns a Java version string (e.g. "7", "8").

    Information is provided by java tool and parsing is based on
    http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
    """
    java_version = check_output(
        [java_path, "-version"], stderr=subprocess.STDOUT
    ).decode("utf-8")
    # extract java version from a string like 'java version "1.8.0_144"' or
    # 'openjdk version "11.0.1" 2018-10-16'
    match = re.search('(java|openjdk) version "(?P<version>.+)"', java_version)
    if not match:
        return None
    return get_java_major_version(match.group("version"))
Ejemplo n.º 3
0
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

    json.dump(
        {
            "version": version,
            "timestamp": timestamp,
            "is_dirty": dirty,
            "java_version": java_version.get_java_major_version(args.java_version),
        },
        sys.stdout,
        sort_keys=True,
        indent=2,
    )
Ejemplo n.º 4
0
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()
    candidate_paths = []
    vcs_module = None
    while vcs_module is None and os.path.dirname(path) != path:
        while not os.path.exists(os.path.join(path, ".buckconfig")):
            path = os.path.dirname(path)
        for vcs_dir, module in SUPPORTED_VCS.items():
            if os.path.exists(os.path.join(path, vcs_dir)):
                vcs_module = module
                break
        else:
            candidate_paths.append(path)
            path = os.path.dirname(path)

    if vcs_module is None:
        path = candidate_paths[0]

    if args.release_version:
        version = args.release_version
        timestamp = args.release_timestamp
        dirty = False
    elif vcs_module is not None:
        # Attempt to create a "clean" version, but fall back to a "dirty"
        # one if need be.
        version = vcs_module.get_clean_buck_version(path)
        timestamp = -1
        if version is None:
            version = vcs_module.get_dirty_buck_version(path)
        else:
            timestamp = vcs_module.get_vcs_revision_timestamp(path)
        dirty = vcs_module.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,
            "java_version": java_version.get_java_major_version(
                args.java_version),
        },
        sys.stdout,
        sort_keys=True,
        indent=2,
    )