From 661de290e7158bcb1e3376dc1499d59386f201db Mon Sep 17 00:00:00 2001 From: Ryan Rhee Date: Tue, 22 Nov 2016 23:57:17 -0800 Subject: [PATCH] [componentkit] Gate analytics behind flag Reviewed By: dulmarod Differential Revision: D4217464 fbshipit-source-id: e11d172 --- infer/src/base/Config.ml | 8 ++++++++ infer/src/base/Config.mli | 1 + .../build_systems/build_integration_tests.py | 16 ++++++++++++++-- .../componentkit/TestComponentKitAnalytics.mm | 15 +++++++++++++++ .../componentkit_analytics_report.json | 1 + ...ort.json => componentkit_imports_report.json} | 0 6 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 infer/tests/build_systems/codetoanalyze/componentkit/TestComponentKitAnalytics.mm create mode 100644 infer/tests/build_systems/expected_outputs/componentkit_analytics_report.json rename infer/tests/build_systems/expected_outputs/{componentkit_report.json => componentkit_imports_report.json} (100%) diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 0e119c41b..f47210bb5 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -701,6 +701,13 @@ and cluster = CLOpt.mk_path_opt ~deprecated:["cluster"] ~long:"cluster" ~meta:"file" "Specify a .cluster file to be analyzed" +and compute_analytics = + CLOpt.mk_bool ~long:"compute-analytics" + ~default:false + ~exes:CLOpt.[Toplevel;Clang] + "Emit analytics as info-level issues, like component kit line count and \ + component kit file cyclomatic complexity" + (** Continue the capture for reactive mode: If a procedure was changed beforehand, keep the changed marking. *) and continue = @@ -1417,6 +1424,7 @@ and checkers_repeated_calls = !checkers_repeated_calls and clang_biniou_file = !clang_biniou_file and clang_include_to_override = !clang_include_to_override and cluster_cmdline = !cluster +and compute_analytics = !compute_analytics and continue_capture = !continue and copy_propagation = !copy_propagation and crashcontext = !crashcontext diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 4bc0f5e87..d1dcb526e 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -163,6 +163,7 @@ val clang_frontend_do_capture : bool val clang_frontend_do_lint : bool val clang_include_to_override : string option val cluster_cmdline : string option +val compute_analytics : bool val continue_capture : bool val copy_propagation : bool val crashcontext : bool diff --git a/infer/tests/build_systems/build_integration_tests.py b/infer/tests/build_systems/build_integration_tests.py index c1fb9ef67..042d6ff60 100755 --- a/infer/tests/build_systems/build_integration_tests.py +++ b/infer/tests/build_systems/build_integration_tests.py @@ -62,7 +62,8 @@ EXPECTED_OUTPUTS_DIR = os.path.join(SCRIPT_DIR, 'expected_outputs') ALL_TESTS = [ 'cmake', - 'componentkit', + 'componentkit_analytics', + 'componentkit_imports', 'delete', 'fail', 'gradle', @@ -471,8 +472,19 @@ class BuildIntegrationTest(unittest.TestCase): 'infer_args': reactive_args}, {'compile': ['analyze']}]) + def test_clang_component_kit_analytics(self): + test('componentkit_analytics', + 'component quality analyzer emits analytics info when flag is ' + 'enabled', + os.path.join(CODETOANALYZE_DIR, 'componentkit'), + [{'compile': ['clang', '-x', 'objective-c++', '-std=c++11', '-c', + '-fblocks', 'TestComponentKitAnalytics.mm'], + 'infer_args': ['--cxx', '--no-filtering', '-a', 'linters', + '--compute-analytics']}]) + def test_clang_component_kit_imports(self): - test('componentkit', 'component quality analyzer skips imports', + test('componentkit_imports', + 'component quality analyzer skips imports', os.path.join(CODETOANALYZE_DIR, 'componentkit'), [{'compile': ['clang', '-x', 'objective-c++', '-std=c++11', '-c', '-fblocks', 'TestIgnoreImports.mm'], diff --git a/infer/tests/build_systems/codetoanalyze/componentkit/TestComponentKitAnalytics.mm b/infer/tests/build_systems/codetoanalyze/componentkit/TestComponentKitAnalytics.mm new file mode 100644 index 000000000..89abd2a02 --- /dev/null +++ b/infer/tests/build_systems/codetoanalyze/componentkit/TestComponentKitAnalytics.mm @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#include "../../../codetoanalyze/objcpp/linters/componentkit/FakeComponentKitHeader.h" + +@interface SomeClass : CKCompositeComponent +@end +@implementation SomeClass +@end diff --git a/infer/tests/build_systems/expected_outputs/componentkit_analytics_report.json b/infer/tests/build_systems/expected_outputs/componentkit_analytics_report.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/infer/tests/build_systems/expected_outputs/componentkit_analytics_report.json @@ -0,0 +1 @@ +[] diff --git a/infer/tests/build_systems/expected_outputs/componentkit_report.json b/infer/tests/build_systems/expected_outputs/componentkit_imports_report.json similarity index 100% rename from infer/tests/build_systems/expected_outputs/componentkit_report.json rename to infer/tests/build_systems/expected_outputs/componentkit_imports_report.json