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
def normalize(path): from inferlib import utils # From Javac docs: If a filename contains embedded spaces, # put the whole filename in double quotes quoted_path = path if ' ' in path: quoted_path = '"' + path + '"' return utils.encode(quoted_path)
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_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(sys.executable, 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
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
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
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
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
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