Summary: New, experimental for now, integration with buck on Java using the `#infer-java-capture` flavor. Reviewed By: artempyanykh Differential Revision: D22187748 fbshipit-source-id: 62cdafe6bmaster
parent
270918fea7
commit
697f9c0a47
@ -0,0 +1,39 @@
|
||||
(*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*)
|
||||
|
||||
open! IStd
|
||||
module F = Format
|
||||
module L = Logging
|
||||
|
||||
let capture build_cmd =
|
||||
let prog, buck_cmd = (List.hd_exn build_cmd, List.tl_exn build_cmd) in
|
||||
L.progress "Querying buck for java flavor capture targets...@." ;
|
||||
let time0 = Mtime_clock.counter () in
|
||||
let BuckFlavors.{command; rev_not_targets; targets} =
|
||||
BuckFlavors.add_flavors_to_buck_arguments JavaFlavor ~extra_flavors:[] buck_cmd
|
||||
in
|
||||
L.progress "Found %d java flavor capture targets in %a.@." (List.length targets) Mtime.Span.pp
|
||||
(Mtime_clock.count time0) ;
|
||||
let all_args = List.rev_append rev_not_targets targets in
|
||||
let build_report_file =
|
||||
Filename.temp_file ~in_dir:(ResultsDir.get_path Temporary) "buck_build_report" ".json"
|
||||
in
|
||||
let updated_buck_cmd =
|
||||
(* make buck tell us where in buck-out are the capture directories for merging *)
|
||||
(prog :: command :: "--build-report" :: build_report_file :: Buck.config JavaFlavor)
|
||||
@ List.rev_append Config.buck_build_args_no_inline (Buck.store_args_in_file all_args)
|
||||
in
|
||||
L.(debug Capture Quiet)
|
||||
"Processed buck command '%a'@." (Pp.seq F.pp_print_string) updated_buck_cmd ;
|
||||
if List.is_empty targets then L.external_warning "WARNING: found no buck targets to analyze.@."
|
||||
else
|
||||
let time0 = Mtime_clock.counter () in
|
||||
Buck.wrap_buck_call ~label:"build" updated_buck_cmd |> ignore ;
|
||||
BuckGenrule.infer_deps_of_build_report build_report_file ;
|
||||
L.progress "Java flavor capture took %a.@." Mtime.Span.pp (Mtime_clock.count time0) ;
|
||||
ResultsDir.RunState.set_merge_capture true ;
|
||||
()
|
@ -0,0 +1,11 @@
|
||||
(*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*)
|
||||
|
||||
open! IStd
|
||||
|
||||
val capture : string list -> unit
|
||||
(** do java capture using flavors with the given buck command line *)
|
@ -0,0 +1,6 @@
|
||||
[project]
|
||||
ignore = .git, .ml, .mli
|
||||
|
||||
[java]
|
||||
source_level = 8
|
||||
target_level = 8
|
@ -0,0 +1 @@
|
||||
../../../../.buckversion
|
@ -0,0 +1,21 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
TESTS_DIR = ../..
|
||||
ROOT_DIR = $(TESTS_DIR)/../..
|
||||
|
||||
BUCK_TARGET = //module2:module2
|
||||
CLEAN_EXTRA = buck-out
|
||||
SOURCES = $(shell find . -name '*.java')
|
||||
|
||||
INFERPRINT_OPTIONS = --issues-tests
|
||||
INFER_OPTIONS = --buck-java-flavor --debug-exceptions
|
||||
|
||||
include $(TESTS_DIR)/infer.make
|
||||
|
||||
$(INFER_OUT)/report.json: $(MAKEFILE_LIST) $(SOURCES)
|
||||
$(QUIET) $(REMOVE_DIR) buck-out && \
|
||||
$(call silent_on_success,Testing java flavor integration in $(TEST_REL_DIR),\
|
||||
$(INFER_BIN) --results-dir $(@D) $(INFER_OPTIONS) -- buck build --no-cache $(BUCK_TARGET))
|
@ -0,0 +1,7 @@
|
||||
java_library(
|
||||
name='annotations',
|
||||
srcs=['ThreadSafe.java'],
|
||||
visibility=[
|
||||
'PUBLIC'
|
||||
],
|
||||
)
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
package genrulecapture.annotations;
|
||||
|
||||
public @interface ThreadSafe {}
|
@ -0,0 +1,2 @@
|
||||
module2/Class2.java, genrulecapture.module2.Class2.get():int, 22, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [<Read trace>,call to int Class1.get(),access to `this.c.x`,<Write trace>,call to void Class1.set(int),access to `this.c.x`]
|
||||
module2/Class2.java, genrulecapture.module2.Class2.set(int):void, 18, THREAD_SAFETY_VIOLATION, no_bucket, WARNING, [call to void Class1.set(int),access to `this.c.x`]
|
@ -0,0 +1,10 @@
|
||||
java_library(
|
||||
name='module1',
|
||||
srcs=glob(["*.java"]),
|
||||
deps=[
|
||||
'//annotations:annotations',
|
||||
],
|
||||
visibility=[
|
||||
'PUBLIC'
|
||||
],
|
||||
)
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package genrulecapture.module1;
|
||||
|
||||
public class Class1 {
|
||||
int x;
|
||||
|
||||
public void set(int d) {
|
||||
x = d;
|
||||
}
|
||||
|
||||
public int get() {
|
||||
return x;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
java_library(
|
||||
name='module2',
|
||||
srcs=glob(["*.java"]),
|
||||
deps=[
|
||||
'//module1:module1',
|
||||
'//annotations:annotations',
|
||||
'//module3:module3',
|
||||
]
|
||||
)
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package genrulecapture.module2;
|
||||
|
||||
import genrulecapture.annotations.ThreadSafe;
|
||||
import genrulecapture.module1.Class1;
|
||||
|
||||
@ThreadSafe
|
||||
public class Class2 {
|
||||
Class1 c;
|
||||
|
||||
void set(int x) {
|
||||
c.set(x);
|
||||
}
|
||||
|
||||
int get() {
|
||||
return c.get();
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
cxx_library(
|
||||
name = 'module3',
|
||||
visibility = [
|
||||
'PUBLIC',
|
||||
],
|
||||
srcs = [
|
||||
'some_c_code.c',
|
||||
],
|
||||
)
|
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void some_c_func() {
|
||||
int* s = NULL;
|
||||
*s = 42;
|
||||
}
|
Loading…
Reference in new issue