Ejemplo n.º 1
0
def main(argv, reporter):
    # Change environment at startup to ensure we don't have any other threads
    # running yet.
    # We set BUCK_ROOT_BUILD_ID to ensure that if we're called in a nested fashion
    # from, say, a genrule, we do not reuse the UUID, and logs do not end up with
    # confusing / incorrect data
    # TODO: remove ability to inject BUCK_BUILD_ID completely. It mostly causes
    #       problems, and is not a generally useful feature for users.
    if "BUCK_BUILD_ID" in os.environ and "BUCK_ROOT_BUILD_ID" not in os.environ:
        build_id = os.environ["BUCK_BUILD_ID"]
    else:
        build_id = str(uuid.uuid4())
    if "BUCK_ROOT_BUILD_ID" not in os.environ:
        os.environ["BUCK_ROOT_BUILD_ID"] = build_id

    java_version_status_queue = Queue(maxsize=1)

    def get_repo(p):
        # Try to detect if we're running a PEX by checking if we were invoked
        # via a zip file.
        if zipfile.is_zipfile(argv[0]):
            from buck_package import BuckPackage

            return BuckPackage(p, reporter)
        else:
            from buck_repo import BuckRepo

            return BuckRepo(THIS_DIR, p, reporter)

    def kill_buck(reporter):
        buck_repo = get_repo(BuckProject.from_current_dir())
        buck_repo.kill_buckd()
        return ExitCode.SUCCESS

    # Execute wrapper specific commands
    wrapper_specific_commands = [("kill", kill_buck), ("killall", killall_buck)]
    if "--help" not in argv and "-h" not in argv:
        for command_str, command_fcn in wrapper_specific_commands:
            if len(argv) > 1 and argv[1] == command_str:
                return ExitCodeCallable(command_fcn(reporter))

    install_signal_handlers()
    try:
        tracing_dir = None
        reporter.build_id = build_id
        with Tracing("main"):
            with BuckProject.from_current_dir() as project:
                tracing_dir = os.path.join(project.get_buck_out_log_dir(), "traces")
                with get_repo(project) as buck_repo:
                    required_java_version = buck_repo.get_buck_compiled_java_version()
                    java_path = get_java_path(required_java_version)
                    _try_to_verify_java_version_off_thread(
                        java_version_status_queue, java_path, required_java_version
                    )

                    return buck_repo.launch_buck(build_id, os.getcwd(), java_path, argv)
    finally:
        if tracing_dir:
            Tracing.write_to_dir(tracing_dir, build_id)
        _emit_java_version_warnings_if_any(java_version_status_queue)
Ejemplo n.º 2
0
def main(argv, reporter):
    # Change environment at startup to ensure we don't have any other threads
    # running yet.
    # We set BUCK_ROOT_BUILD_ID to ensure that if we're called in a nested fashion
    # from, say, a genrule, we do not reuse the UUID, and logs do not end up with
    # confusing / incorrect data
    # TODO: remove ability to inject BUCK_BUILD_ID completely. It mostly causes
    #       problems, and is not a generally useful feature for users.
    if "BUCK_BUILD_ID" in os.environ and "BUCK_ROOT_BUILD_ID" not in os.environ:
        build_id = os.environ["BUCK_BUILD_ID"]
    else:
        build_id = str(uuid.uuid4())
    if "BUCK_ROOT_BUILD_ID" not in os.environ:
        os.environ["BUCK_ROOT_BUILD_ID"] = build_id

    java_version_status_queue = Queue(maxsize=1)

    def get_repo(p):
        # Try to detect if we're running a PEX by checking if we were invoked
        # via a zip file.
        if zipfile.is_zipfile(argv[0]):
            from buck_package import BuckPackage

            return BuckPackage(p, reporter)
        else:
            from buck_repo import BuckRepo

            return BuckRepo(THIS_DIR, p, reporter)

    # If 'killall' is the second argument, shut down all the buckd processes
    if argv[1:] == ["killall"]:
        return killall_buck(reporter)

    install_signal_handlers()
    try:
        tracing_dir = None
        reporter.build_id = build_id
        with Tracing("main"):
            with BuckProject.from_current_dir() as project:
                tracing_dir = os.path.join(project.get_buck_out_log_dir(), "traces")
                with get_repo(project) as buck_repo:
                    required_java_version = buck_repo.get_buck_compiled_java_version()
                    java_path = get_java_path(required_java_version)
                    _try_to_verify_java_version_off_thread(
                        java_version_status_queue, java_path, required_java_version
                    )

                    # If 'kill' is the second argument, shut down the buckd
                    # process
                    if argv[1:] == ["kill"]:
                        buck_repo.kill_buckd()
                        return ExitCode.SUCCESS
                    return buck_repo.launch_buck(build_id, java_path, argv)
    finally:
        if tracing_dir:
            Tracing.write_to_dir(tracing_dir, build_id)
        _emit_java_version_warnings_if_any(java_version_status_queue)
Ejemplo n.º 3
0
 def test_java_home_for_wrong_version_ignored(self):
     os.environ["JAVA_HOME"] = (
         "/Library/Java/JavaVirtualMachines/jdk-" +
         str(JAVA_VERSION_THAT_OBVIOUSLY_CANT_EXIST_LOCALLY + 1) +
         ".jdk/Contents/Home")
     self.assertEquals(
         get_java_path(
             JAVA_VERSION_THAT_OBVIOUSLY_CANT_EXIST_LOCALLY).lower(),
         which("java").lower(),
     )
Ejemplo n.º 4
0
 def test_without_java_home(self):
     self.assertEquals(
         get_java_path(
             JAVA_VERSION_THAT_OBVIOUSLY_CANT_EXIST_LOCALLY).lower(),
         which("java").lower(),
     )
Ejemplo n.º 5
0
 def test_with_java_home_valid(self):
     os.environ["JAVA_HOME"] = self.java_home
     self.assertEqual(
         get_java_path(ANY_JAVA_VERSION).lower(),
         os.path.join(self.java_home, "bin", self.java_exec).lower(),
     )
Ejemplo n.º 6
0
def main(argv, reporter):
    # Change environment at startup to ensure we don't have any other threads
    # running yet.
    # We set BUCK_ROOT_BUILD_ID to ensure that if we're called in a nested fashion
    # from, say, a genrule, we do not reuse the UUID, and logs do not end up with
    # confusing / incorrect data
    # TODO: remove ability to inject BUCK_BUILD_ID completely. It mostly causes
    #       problems, and is not a generally useful feature for users.
    if "BUCK_BUILD_ID" in os.environ and "BUCK_ROOT_BUILD_ID" not in os.environ:
        build_id = os.environ["BUCK_BUILD_ID"]
    else:
        build_id = str(uuid.uuid4())
    if "BUCK_ROOT_BUILD_ID" not in os.environ:
        os.environ["BUCK_ROOT_BUILD_ID"] = build_id

    java_version_status_queue = Queue(maxsize=1)

    def get_repo(p):
        # Try to detect if we're running a PEX by checking if we were invoked
        # via a zip file.
        if zipfile.is_zipfile(argv[0]):
            from buck_package import BuckPackage

            return BuckPackage(p, reporter)
        else:
            from buck_repo import BuckRepo

            return BuckRepo(THIS_DIR, p, reporter)

    # If 'killall' is the second argument, shut down all the buckd processes
    if argv[1:] == ["killall"]:
        return killall_buck(reporter)

    install_signal_handlers()
    try:
        tracing_dir = None
        reporter.build_id = build_id
        with Tracing("main"):
            with BuckProject.from_current_dir() as project:
                tracing_dir = os.path.join(project.get_buck_out_log_dir(),
                                           "traces")
                with get_repo(project) as buck_repo:
                    required_java_version = buck_repo.get_buck_compiled_java_version(
                    )
                    java_path = get_java_path(required_java_version)
                    _try_to_verify_java_version_off_thread(
                        java_version_status_queue, java_path,
                        required_java_version)

                    def has_kill_argument():
                        if argv[1:] == ["kill"]:
                            return True
                        if (len(argv) > 3 and argv[3:] == ["kill"]
                                and argv[1] == "--isolation_prefix"):
                            return True
                        return False

                    # If 'kill' is the second argument, or immediately follows the
                    # isolation prefix argument, shut down the buckd process
                    if has_kill_argument():
                        buck_repo.kill_buckd()
                        return ExitCode.SUCCESS
                    return buck_repo.launch_buck(build_id, java_path, argv)
    finally:
        if tracing_dir:
            Tracing.write_to_dir(tracing_dir, build_id)
        _emit_java_version_warnings_if_any(java_version_status_queue)