[config] Default project_root to initial working dir

Reviewed By: akotulski

Differential Revision: D4110725

fbshipit-source-id: 6939112
master
Josh Berdine 9 years ago committed by Facebook Github Bot
parent ea696ff96d
commit 2ce94632d2

@ -49,23 +49,6 @@ class VersionAction(argparse._VersionAction):
option_string) option_string)
def get_pwd():
pwd = os.getenv('PWD')
if pwd is not None:
try:
# Compare whether 'PWD' and '.' point to same place
# Approach is borrowed from llvm implementation of
# llvm::sys::fs::current_path (implemented in Path.inc file)
pwd_stat = os.stat(pwd)
dot_stat = os.stat('.')
if pwd_stat.st_dev == dot_stat.st_dev and \
pwd_stat.st_ino == dot_stat.st_ino:
return pwd
except OSError:
# fallthrough to default case
pass
return os.getcwd()
base_parser = argparse.ArgumentParser(add_help=False) base_parser = argparse.ArgumentParser(add_help=False)
base_group = base_parser.add_argument_group('global arguments') base_group = base_parser.add_argument_group('global arguments')
base_group.add_argument('-o', '--out', metavar='<directory>', base_group.add_argument('-o', '--out', metavar='<directory>',
@ -122,12 +105,6 @@ infer_group.add_argument('-l', '--load-average', metavar='<float>', type=float,
infer_group.add_argument('--buck', action='store_true', dest='buck', infer_group.add_argument('--buck', action='store_true', dest='buck',
help='To use when run with buck') help='To use when run with buck')
infer_group.add_argument('-pr', '--project_root',
dest='project_root',
default=get_pwd(),
help='Location of the project root '
'(default is current directory)')
infer_group.add_argument('--absolute-paths', infer_group.add_argument('--absolute-paths',
action='store_true', action='store_true',
default=False, default=False,
@ -236,14 +213,11 @@ class AnalyzerWrapper(object):
exit_status = os.EX_OK exit_status = os.EX_OK
if self.javac is not None and self.args.buck: if self.javac is not None and self.args.buck:
infer_options += ['-project_root', utils.decode(os.getcwd()), infer_options += ['-java']
'-java']
if self.javac.args.classpath is not None: if self.javac.args.classpath is not None:
for path in self.javac.args.classpath.split(os.pathsep): for path in self.javac.args.classpath.split(os.pathsep):
if os.path.isfile(path): if os.path.isfile(path):
infer_options += ['-ziplib', os.path.abspath(path)] infer_options += ['-ziplib', os.path.abspath(path)]
elif self.args.project_root:
infer_options += ['-project_root', self.args.project_root]
infer_options = map(utils.decode_or_not, infer_options) infer_options = map(utils.decode_or_not, infer_options)
infer_options_str = ' '.join(infer_options) infer_options_str = ' '.join(infer_options)

@ -213,8 +213,6 @@ class BuckAnalyzer:
def capture_with_compilation_database(self): def capture_with_compilation_database(self):
buck_args = self.cmd buck_args = self.cmd
cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')] cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')]
if self.args.project_root:
cmd += ['--project-root', self.args.project_root]
cmd += ['--'] cmd += ['--']
cmd += buck_args cmd += buck_args
return subprocess.check_call(cmd) return subprocess.check_call(cmd)

@ -31,8 +31,6 @@ class ClangCompilationDatabase:
def capture(self): def capture(self):
args = self.cmd args = self.cmd
cmd = [utils.get_cmd_in_bin_dir('InferBuckCompilationDatabase')] 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]] cmd += ['--clang-compilation-database', args[1]]
print(cmd) print(cmd)
return subprocess.check_call(cmd) return subprocess.check_call(cmd)

@ -307,9 +307,6 @@ class AnalyzerWithFrontendWrapper(analyze.AnalyzerWrapper):
infer_cmd = [utils.get_cmd_in_bin_dir('InferJava')] infer_cmd = [utils.get_cmd_in_bin_dir('InferJava')]
infer_cmd += ['-classpath', self._create_frontend_classpath()] infer_cmd += ['-classpath', self._create_frontend_classpath()]
if not self.args.absolute_paths:
infer_cmd += ['-project_root', self.args.project_root]
infer_cmd += [ infer_cmd += [
'-results_dir', self.args.infer_out, '-results_dir', self.args.infer_out,
'-verbose_out', self.javac.verbose_out, '-verbose_out', self.javac.verbose_out,

@ -121,13 +121,10 @@ let crashcontext_epilogue ~in_buck_mode =
infer-out/ directory, but instead it is buck-out/, which contains the infer-out/ directory, but instead it is buck-out/, which contains the
infer output directories for every buck target. *) infer output directories for every buck target. *)
let root_summaries_dir = if in_buck_mode then begin let root_summaries_dir = if in_buck_mode then begin
let project_root = match Config.project_root with
| Some root -> root
| None -> Filename.dirname Config.results_dir in
let buck_out = match Config.buck_out with let buck_out = match Config.buck_out with
| Some dir -> dir | Some dir -> dir
| None -> "buck-out" in | None -> "buck-out" in
project_root // buck_out Config.project_root // buck_out
end end
else Config.results_dir in else Config.results_dir in
collect_all_summaries collect_all_summaries

@ -65,8 +65,6 @@ let () =
(if not Config.reactive_mode then [] else (if not Config.reactive_mode then [] else
["--reactive"]) @ ["--reactive"]) @
"--out" :: Config.results_dir :: "--out" :: Config.results_dir ::
(match Config.project_root with None -> [] | Some pr ->
["--project_root"; pr]) @
(match Config.xcode_developer_dir with None -> [] | Some d -> (match Config.xcode_developer_dir with None -> [] | Some d ->
["--xcode-developer-dir"; d]) @ ["--xcode-developer-dir"; d]) @
(if Config.rest = [] then [] else (if Config.rest = [] then [] else

@ -20,12 +20,7 @@ let use_multilinks = true
is used to determine whether a captured directory needs to be merged. *) is used to determine whether a captured directory needs to be merged. *)
let check_timestamp_of_symlinks = true let check_timestamp_of_symlinks = true
let buck_out () = let buck_out () = Filename.concat Config.project_root "buck-out"
match Config.project_root with
| Some root ->
Filename.concat root "buck-out"
| None ->
Filename.concat (Filename.dirname Config.results_dir) "buck-out"
let infer_deps () = Filename.concat Config.results_dir Config.buck_infer_deps_file_name let infer_deps () = Filename.concat Config.results_dir Config.buck_infer_deps_file_name

@ -425,9 +425,8 @@ let inferconfig_home =
~exes:all_exes ~meta:"dir" "Path to the .inferconfig file" ~exes:all_exes ~meta:"dir" "Path to the .inferconfig file"
and project_root = and project_root =
CLOpt.mk_string_opt ~deprecated:["project_root"; "-project_root"] ~long:"project-root" ~short:"pr" CLOpt.mk_string ~deprecated:["project_root"; "-project_root"] ~long:"project-root" ~short:"pr"
?default:CLOpt.(match current_exe with Print | Toplevel | StatsAggregator | Clang -> ~default:init_work_dir
Some init_work_dir | _ -> None)
~f:resolve ~f:resolve
~exes:CLOpt.[Analyze;Clang;Java;Print;Toplevel] ~exes:CLOpt.[Analyze;Clang;Java;Print;Toplevel]
~meta:"dir" "Specify the root directory of the project" ~meta:"dir" "Specify the root directory of the project"
@ -442,9 +441,9 @@ let inferconfig_home = !inferconfig_home
and project_root = !project_root and project_root = !project_root
let inferconfig_path = let inferconfig_path =
match inferconfig_home, project_root with match inferconfig_home with
| Some dir, _ | _, Some dir -> dir // inferconfig_file | Some dir -> dir // inferconfig_file
| None, None -> inferconfig_file | None -> project_root // inferconfig_file
(* Proceed to declare and parse the remaining options *) (* Proceed to declare and parse the remaining options *)

@ -229,7 +229,7 @@ val print_types : bool
val print_using_diff : bool val print_using_diff : bool
val procs_csv : outfile option val procs_csv : outfile option
val procs_xml : outfile option val procs_xml : outfile option
val project_root : string option val project_root : string
val quandary : bool val quandary : bool
val quiet : bool val quiet : bool
val reactive_mode : bool val reactive_mode : bool

@ -68,17 +68,10 @@ let source_file_to_string fname =
| Relative path | Relative path
| Absolute path -> path | Absolute path -> path
exception No_project_root
let project_root () =
match Config.project_root with
| None -> L.err "No --project-root option passed@."; raise No_project_root
| Some path -> path
(* Checking if the path exists may be needed only in some cases, hence the flag check_exists *) (* Checking if the path exists may be needed only in some cases, hence the flag check_exists *)
let source_file_to_abs_path fname = let source_file_to_abs_path fname =
match fname with match fname with
| Relative path -> Filename.concat (project_root()) path | Relative path -> Filename.concat Config.project_root path
| Absolute path -> path | Absolute path -> path
let inode_equal sf1 sf2 = let inode_equal sf1 sf2 =
@ -89,7 +82,7 @@ let inode_equal sf1 sf2 =
let source_file_to_rel_path fname = let source_file_to_rel_path fname =
match fname with match fname with
| Relative path -> path | Relative path -> path
| Absolute path -> filename_to_relative (project_root ()) path | Absolute path -> filename_to_relative Config.project_root path
(** string encoding of a source file (including path) as a single filename *) (** string encoding of a source file (including path) as a single filename *)
let source_file_encoding source_file = let source_file_encoding source_file =

@ -669,10 +669,7 @@ struct
let get_rel_file_path file_opt = let get_rel_file_path file_opt =
match file_opt with match file_opt with
| Some file -> | Some file ->
(match Config.project_root with DB.source_file_to_rel_path (DB.rel_source_file_from_abs_path Config.project_root file)
| Some root ->
DB.source_file_to_rel_path (DB.rel_source_file_from_abs_path root file)
| None -> file)
| None -> "" | None -> ""
let is_cpp_translation translation_unit_context = let is_cpp_translation translation_unit_context =

@ -20,14 +20,11 @@ let source_file_from_path path =
(failwithf (failwithf
"ERROR: Path %s is relative. Please pass an absolute path in the -c argument.@." "ERROR: Path %s is relative. Please pass an absolute path in the -c argument.@."
path); path);
match Config.project_root with try
| Some root -> DB.rel_source_file_from_abs_path Config.project_root path
(try with Failure _ ->
DB.rel_source_file_from_abs_path root path Logging.err_debug "ERROR: %s should be a prefix of %s.@." Config.project_root path;
with Failure _ -> DB.source_file_from_string path
Logging.err_debug "ERROR: %s should be a prefix of %s.@." root path;
DB.source_file_from_string path)
| None -> DB.source_file_from_string path
let choose_sloc_to_update_curr_file trans_unit_ctx sloc1 sloc2 = let choose_sloc_to_update_curr_file trans_unit_ctx sloc1 sloc2 =
match sloc2.Clang_ast_t.sl_file with match sloc2.Clang_ast_t.sl_file with
@ -70,18 +67,15 @@ let clang_to_sil_location trans_unit_ctx clang_loc procdesc_opt =
Location.{line; col; file; nLOC} Location.{line; col; file; nLOC}
let file_in_project file = let file_in_project file =
match Config.project_root with let real_root = real_path Config.project_root in
| Some root -> let real_file = real_path file in
let real_root = real_path root in let file_in_project = string_is_prefix real_root real_file in
let real_file = real_path file in let paths = Config.skip_translation_headers in
let file_in_project = string_is_prefix real_root real_file in let file_should_be_skipped =
let paths = Config.skip_translation_headers in IList.exists
let file_should_be_skipped = (fun path -> string_is_prefix (Filename.concat real_root path) real_file)
IList.exists paths in
(fun path -> string_is_prefix (Filename.concat real_root path) real_file) file_in_project && not (file_should_be_skipped)
paths in
file_in_project && not (file_should_be_skipped)
| None -> false
let should_do_frontend_check trans_unit_ctx (loc_start, _) = let should_do_frontend_check trans_unit_ctx (loc_start, _) =
match loc_start.Clang_ast_t.sl_file with match loc_start.Clang_ast_t.sl_file with

@ -76,9 +76,7 @@ let java_source_file_from_path path =
if Filename.is_relative path then if Filename.is_relative path then
failwith "Expect absolute path for java source files" failwith "Expect absolute path for java source files"
else else
match Config.project_root with DB.rel_source_file_from_abs_path Config.project_root path
| None -> DB.abs_source_file_from_path path
| Some project_root -> DB.rel_source_file_from_abs_path project_root path
(** Add the android.jar containing bytecode at the beginning of the class path *) (** Add the android.jar containing bytecode at the beginning of the class path *)

Loading…
Cancel
Save