Ejemplo n.º 1
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = ['--buck', '--jobs', '1']

    if args.java_jar_compiler is not None:
        infer_options += [
            '--java-jar-compiler',
            args.java_jar_compiler,
        ]

    temp_files = []

    try:
        infer_command = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # Create a script to be called by buck
    infer_script_path = os.path.join(os.getcwd(), INFER_SCRIPT_NAME)
    if os.path.exists(infer_script_path):
        raise Exception('{} already exists. Exiting'.format(infer_script_path))
    with open(infer_script_path, 'w') as infer_script:
        logging.info('Creating %s' % infer_script_path)
        infer_script.write(
            utils.encode(INFER_SCRIPT.format(infer_command=infer_command)))

    st = os.stat(infer_script_path)
    os.chmod(infer_script_path, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script_path]
    return temp_files, infer_script_path
Ejemplo n.º 2
0
 def capture(self):
     args = self.cmd
     cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')]
     if self.args.project_root:
         cmd += ['--project-root', self.args.project_root]
     cmd += ['--clang-compilation-database', args[1]]
     print(cmd)
     return subprocess.check_call(cmd)
Ejemplo n.º 3
0
 def capture_with_compilation_database(self):
     buck_args = self.cmd
     cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')]
     for arg in buck_args:
         cmd += ['--Xbuck'] + [arg]
     if self.args.project_root:
         cmd += ['--project-root'] + [self.args.project_root]
     return subprocess.check_call(cmd)
Ejemplo n.º 4
0
Archivo: buck.py Proyecto: HKingz/infer
 def capture_with_compilation_database(self):
     buck_args = self.cmd
     cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')]
     for arg in buck_args:
         cmd += ['--Xbuck'] + [arg]
     if self.args.project_root:
         cmd += ['--project-root'] + [self.args.project_root]
     return subprocess.check_call(cmd)
Ejemplo n.º 5
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = [
        '--buck',
        '--incremental',
        '--analyzer',
        args.analyzer,
    ]

    if args.debug:
        infer_options.append('--debug')

    if args.no_filtering:
        infer_options.append('--no-filtering')

    if args.debug_exceptions:
        infer_options += ['--debug-exceptions', '--no-filtering']

    # Create a temporary directory as a cache for jar files.
    infer_cache_dir = os.path.join(args.infer_out, 'cache')
    if not os.path.isdir(infer_cache_dir):
        os.mkdir(infer_cache_dir)
    infer_options.append('--infer_cache')
    infer_options.append(infer_cache_dir)
    temp_files = [infer_cache_dir]

    try:
        infer = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # Disable the use of buckd as this scripts modifies .buckconfig.local
    logging.info('Disabling buckd: export NO_BUCKD=1')
    os.environ['NO_BUCKD'] = '1'

    # make sure INFER_ANALYSIS is set when buck is called
    logging.info('Setup Infer analysis mode for Buck: export INFER_ANALYSIS=1')
    os.environ['INFER_ANALYSIS'] = '1'

    # Create a script to be called by buck
    infer_script = None
    with tempfile.NamedTemporaryFile(delete=False,
                                     prefix='infer_',
                                     suffix='.py',
                                     dir='.') as infer_script:
        logging.info('Creating %s' % infer_script.name)
        infer_script.file.write(
            INFER_SCRIPT.format(sys.executable, infer).encode())

    st = os.stat(infer_script.name)
    os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script.name]
    return temp_files, infer_script.name
Ejemplo n.º 6
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = [
        '--buck',
        '--incremental',
        '--analyzer', args.analyzer,
    ]

    if args.debug:
        infer_options.append('--debug')

    if args.no_filtering:
        infer_options.append('--no-filtering')

    if args.debug_exceptions:
        infer_options += ['--debug-exceptions', '--no-filtering']

    # Create a temporary directory as a cache for jar files.
    infer_cache_dir = os.path.join(args.infer_out, 'cache')
    if not os.path.isdir(infer_cache_dir):
       os.mkdir(infer_cache_dir)
    infer_options.append('--infer_cache')
    infer_options.append(infer_cache_dir)
    temp_files = [infer_cache_dir]

    try:
        infer = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # Disable the use of buckd as this scripts modifies .buckconfig.local
    logging.info('Disabling buckd: export NO_BUCKD=1')
    os.environ['NO_BUCKD'] = '1'

    # make sure INFER_ANALYSIS is set when buck is called
    logging.info('Setup Infer analysis mode for Buck: export INFER_ANALYSIS=1')
    os.environ['INFER_ANALYSIS'] = '1'

    # Create a script to be called by buck
    infer_script = None
    with tempfile.NamedTemporaryFile(delete=False,
                                     prefix='infer_',
                                     suffix='.py',
                                     dir='.') as infer_script:
        logging.info('Creating %s' % infer_script.name)
        infer_script.file.write(
            INFER_SCRIPT.format(sys.executable, infer).encode())

    st = os.stat(infer_script.name)
    os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script.name]
    return temp_files, infer_script.name
Ejemplo n.º 7
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = ['--buck']

    if args.java_jar_compiler is not None:
        infer_options += [
            '--java-jar-compiler',
            args.java_jar_compiler,
        ]

    temp_files = []
    if USE_INFER_CACHE:
        # Create a temporary directory as a cache for jar files.
        infer_cache_dir = os.path.join(args.infer_out, 'cache')
        if not os.path.isdir(infer_cache_dir):
            os.mkdir(infer_cache_dir)
        infer_options += ['--infer-cache', infer_cache_dir]
        temp_files += [infer_cache_dir]

    try:
        infer_command = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # make sure INFER_ANALYSIS is set when buck is called
    logging.info('Setup Infer analysis mode for Buck: export INFER_ANALYSIS=1')
    os.environ['INFER_ANALYSIS'] = '1'

    # disable the Buck daemon as changes in the Buck config
    # may be missed otherwise
    os.environ['NO_BUCKD'] = '1'

    # Create a script to be called by buck
    infer_script = None
    with tempfile.NamedTemporaryFile(delete=False,
                                     prefix='infer_',
                                     suffix='.py',
                                     dir='.') as infer_script:
        logging.info('Creating %s' % infer_script.name)
        infer_script.file.write(
            utils.encode(
                INFER_SCRIPT.format(python_executable=sys.executable,
                                    infer_command=infer_command)))

    st = os.stat(infer_script.name)
    os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script.name]
    return temp_files, infer_script.name
Ejemplo n.º 8
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = ['--buck']

    if args.java_jar_compiler is not None:
        infer_options += [
            '--java-jar-compiler',
            args.java_jar_compiler,
        ]

    temp_files = []
    if USE_INFER_CACHE:
        # Create a temporary directory as a cache for jar files.
        infer_cache_dir = os.path.join(args.infer_out, 'cache')
        if not os.path.isdir(infer_cache_dir):
            os.mkdir(infer_cache_dir)
        infer_options += ['--infer-cache', infer_cache_dir]
        temp_files += [infer_cache_dir]

    try:
        infer_command = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # make sure INFER_ANALYSIS is set when buck is called
    logging.info('Setup Infer analysis mode for Buck: export INFER_ANALYSIS=1')
    os.environ['INFER_ANALYSIS'] = '1'

    # disable the Buck daemon as changes in the Buck config
    # may be missed otherwise
    os.environ['NO_BUCKD'] = '1'

    # Create a script to be called by buck
    infer_script = None
    with tempfile.NamedTemporaryFile(delete=False,
                                     prefix='infer_',
                                     suffix='.py',
                                     dir='.') as infer_script:
        logging.info('Creating %s' % infer_script.name)
        infer_script.file.write(
            utils.encode(INFER_SCRIPT.format(
                python_executable=sys.executable,
                infer_command=infer_command)))

    st = os.stat(infer_script.name)
    os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script.name]
    return temp_files, infer_script.name
Ejemplo n.º 9
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = ["--buck", "--analyzer", args.analyzer]

    if args.debug:
        infer_options.append("--debug")

    if args.no_filtering:
        infer_options.append("--no-filtering")

    if args.debug_exceptions:
        infer_options += ["--debug-exceptions", "--no-filtering"]

    # Create a temporary directory as a cache for jar files.
    infer_cache_dir = os.path.join(args.infer_out, "cache")
    if not os.path.isdir(infer_cache_dir):
        os.mkdir(infer_cache_dir)
    infer_options += ["--infer_cache", infer_cache_dir]
    temp_files = [infer_cache_dir]

    try:
        infer = [utils.get_cmd_in_bin_dir("infer")] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error("Could not find infer")
        raise e

    # Disable the use of buckd as this scripts modifies .buckconfig.local
    logging.info("Disabling buckd: export NO_BUCKD=1")
    os.environ["NO_BUCKD"] = "1"

    # make sure INFER_ANALYSIS is set when buck is called
    logging.info("Setup Infer analysis mode for Buck: export INFER_ANALYSIS=1")
    os.environ["INFER_ANALYSIS"] = "1"

    # Create a script to be called by buck
    infer_script = None
    with tempfile.NamedTemporaryFile(delete=False, prefix="infer_", suffix=".py", dir=".") as infer_script:
        logging.info("Creating %s" % infer_script.name)
        infer_script.file.write(utils.encode(INFER_SCRIPT.format(sys.executable, infer)))

    st = os.stat(infer_script.name)
    os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script.name]
    return temp_files, infer_script.name
Ejemplo n.º 10
0
Archivo: buck.py Proyecto: haches/infer
 def capture_without_flavors(self):
     # BuckAnalyze is a special case, and we run the analysis from here
     capture_cmd = [utils.get_cmd_in_bin_dir('BuckAnalyze')]
     if self.args.infer_out is not None:
         capture_cmd += ['--out', self.args.infer_out]
     if self.args.debug:
         capture_cmd.append('-g')
     if self.args.no_filtering:
         capture_cmd.append('--no-filtering')
     if self.args.verbose:
         capture_cmd.append('--verbose')
     if self.args.no_cache:
         capture_cmd.append('--no-cache')
     if self.args.print_harness:
         capture_cmd.append('--print-harness')
     capture_cmd += self.cmd[2:]  # TODO: make extraction of targets smarter
     capture_cmd += ['--analyzer', self.args.analyzer]
     subprocess.check_call(capture_cmd)
     return os.EX_OK
Ejemplo n.º 11
0
 def capture_without_flavors(self):
     # BuckAnalyze is a special case, and we run the analysis from here
     capture_cmd = [utils.get_cmd_in_bin_dir('BuckAnalyze')]
     if self.args.infer_out is not None:
         capture_cmd += ['--out', self.args.infer_out]
     if self.args.debug:
         capture_cmd.append('-g')
     if self.args.no_filtering:
         capture_cmd.append('--no-filtering')
     if self.args.verbose:
         capture_cmd.append('--verbose')
     if self.args.no_cache:
         capture_cmd.append('--no-cache')
     if self.args.print_harness:
         capture_cmd.append('--print-harness')
     capture_cmd += self.cmd[2:]  # TODO: make extraction of targets smarter
     capture_cmd += ['--analyzer', self.args.analyzer]
     subprocess.check_call(capture_cmd)
     return os.EX_OK
Ejemplo n.º 12
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = ['--buck', '--jobs', '1']

    if args.java_jar_compiler is not None:
        infer_options += [
            '--java-jar-compiler',
            args.java_jar_compiler,
        ]

    temp_files = []

    try:
        infer_command = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # Create a script to be called by buck
    infer_script = None
    with tempfile.NamedTemporaryFile(delete=False,
                                     prefix='infer_',
                                     suffix='.py',
                                     dir='.') as infer_script:
        logging.info('Creating %s' % infer_script.name)
        infer_script.file.write(
            utils.encode(
                INFER_SCRIPT.format(python_executable=sys.executable,
                                    infer_command=infer_command)))

    st = os.stat(infer_script.name)
    os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script.name]
    return temp_files, infer_script.name
Ejemplo n.º 13
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = ['--buck', '--jobs', '1']

    if args.java_jar_compiler is not None:
        infer_options += [
            '--java-jar-compiler',
            args.java_jar_compiler,
        ]

    temp_files = []

    try:
        infer_command = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # Create a script to be called by buck
    infer_script_path = os.path.join(os.getcwd(), INFER_SCRIPT_NAME)
    if os.path.exists(infer_script_path):
        raise Exception('{} already exists. Exiting'.format(infer_script_path))
    with open(infer_script_path, 'w') as infer_script:
        logging.info('Creating %s' % infer_script_path)
        infer_script.write(
            utils.encode(INFER_SCRIPT.format(
                python_executable=sys.executable,
                infer_command=infer_command)))

    st = os.stat(infer_script_path)
    os.chmod(infer_script_path, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script_path]
    return temp_files, infer_script_path
Ejemplo n.º 14
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = [
        '--buck',
        '--analyzer',
        args.analyzer,
    ]

    if args.java_jar_compiler is not None:
        infer_options += [
            '--java-jar-compiler',
            args.java_jar_compiler,
        ]

    if args.debug:
        infer_options.append('--debug')

    if args.no_filtering:
        infer_options.append('--no-filtering')

    if args.debug_exceptions:
        infer_options += ['--debug-exceptions', '--no-filtering']

    # Create a temporary directory as a cache for jar files.
    infer_cache_dir = os.path.join(args.infer_out, 'cache')
    if not os.path.isdir(infer_cache_dir):
        os.mkdir(infer_cache_dir)
    infer_options += ['--infer_cache', infer_cache_dir]
    temp_files = [infer_cache_dir]

    try:
        infer_command = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # make sure INFER_ANALYSIS is set when buck is called
    logging.info('Setup Infer analysis mode for Buck: export INFER_ANALYSIS=1')
    os.environ['INFER_ANALYSIS'] = '1'

    # Export the Infer command as environment variables
    os.environ['INFER_JAVA_BUCK_OPTIONS'] = json.dumps(infer_command)
    os.environ['INFER_RULE_KEY'] = utils.infer_key(args.analyzer)

    # Create a script to be called by buck
    infer_script = None
    with tempfile.NamedTemporaryFile(delete=False,
                                     prefix='infer_',
                                     suffix='.py',
                                     dir='.') as infer_script:
        logging.info('Creating %s' % infer_script.name)
        infer_script.file.write(
            utils.encode(
                INFER_SCRIPT.format(python_executable=sys.executable,
                                    infer_command=infer_command)))

    st = os.stat(infer_script.name)
    os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script.name]
    return temp_files, infer_script.name
Ejemplo n.º 15
0
 def capture_with_compilation_database(self):
     buck_args = self.cmd
     cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')]
     cmd += ['--']
     cmd += buck_args
     return subprocess.check_call(cmd)
Ejemplo n.º 16
0
def prepare_build(args):
    """Creates script that redirects javac calls to infer and a local buck
    configuration that tells buck to use that script.
    """

    infer_options = [
        '--buck',
        '--analyzer', args.analyzer,
    ]

    if args.java_jar_compiler is not None:
        infer_options += [
            '--java-jar-compiler',
            args.java_jar_compiler,
        ]

    if args.debug:
        infer_options.append('--debug')

    if args.no_filtering:
        infer_options.append('--no-filtering')

    if args.debug_exceptions:
        infer_options += ['--debug-exceptions', '--no-filtering']

    # Create a temporary directory as a cache for jar files.
    infer_cache_dir = os.path.join(args.infer_out, 'cache')
    if not os.path.isdir(infer_cache_dir):
        os.mkdir(infer_cache_dir)
    infer_options += ['--infer_cache', infer_cache_dir]
    temp_files = [infer_cache_dir]

    try:
        infer_command = [utils.get_cmd_in_bin_dir('infer')] + infer_options
    except subprocess.CalledProcessError as e:
        logging.error('Could not find infer')
        raise e

    # make sure INFER_ANALYSIS is set when buck is called
    logging.info('Setup Infer analysis mode for Buck: export INFER_ANALYSIS=1')
    os.environ['INFER_ANALYSIS'] = '1'

    # Export the Infer command as environment variables
    os.environ['INFER_JAVA_BUCK_OPTIONS'] = json.dumps(infer_command)
    os.environ['INFER_RULE_KEY'] = utils.infer_key(args.analyzer)

    # Create a script to be called by buck
    infer_script = None
    with tempfile.NamedTemporaryFile(delete=False,
                                     prefix='infer_',
                                     suffix='.py',
                                     dir='.') as infer_script:
        logging.info('Creating %s' % infer_script.name)
        infer_script.file.write(
            utils.encode(INFER_SCRIPT.format(
                python_executable=sys.executable,
                infer_command=infer_command)))

    st = os.stat(infer_script.name)
    os.chmod(infer_script.name, st.st_mode | stat.S_IEXEC)

    temp_files += [infer_script.name]
    return temp_files, infer_script.name