infer icon indicating copy to clipboard operation
infer copied to clipboard

Confuse how to integrate Infer into our Gitlab CI

Open sencho opened this issue 9 years ago • 25 comments

I am confused how to integrate Infer into our Gitlab CI pipeline at static analysis stage:

  • To slow I use this command follow the wiki,but still scan whole project 1700+ files when CI Runner checkout the branch every time。
infer --reactive --continue -- xcodebuild -workspace xxx.xcworkspace -scheme xxx -sdk iphonesimulator10.2 -configuration Debug build
  • Can seperate two phases? I just want to analyze the commit files ,but Infer must compile first,and use command infer -- <command> Suppose our CI pipeline include build,test,pre-production,production 4 phase. Assuming there are two jobs in the build phase, the first job is build, the second is static analysis, , and infer - <command> combine two jobs, and make the build phase become slow.

  • Can not set the threshold, analyze the results and throw error so that the pipeline to stop

Please give me a suggestion how to integrate infer into our CI process correctly,thanks!

sencho avatar Mar 01 '17 10:03 sencho

@sencho is your build incremental, or does CI compile everything every time it runs?

cristianoc avatar Mar 06 '17 08:03 cristianoc

compile everything every time it runs,but I think Infer waste too much time to complete.

sencho avatar Mar 06 '17 08:03 sencho

@cristianoc ,I have another question if the two builds are in different CI Runner, how can i ensure that two of the infer-out file contents are synchronized? Should I cache the infer-out folder content or ignore it?

sencho avatar Mar 06 '17 08:03 sencho

OK then the best that can be done is to split the work into two parts:

  1. together with the build, run the Infer capture phase only infer -a capture -- ...build command...
  2. separately, find out what files you want to run the analysis on, and only analyze those files: infer -reactive --changed-files-index index.txt -- analyze where index.txt contains a list of files to analyze, with relative path from the root of the project. So if your project looks like this
 src/foo.c
 src/bar.c

then an example index.txt can be

src/foo.c

Typically, you will want index.txt to contain the set of files modified in the current commit.

cristianoc avatar Mar 06 '17 08:03 cristianoc

@sencho since CI builds all the files every time, each CI Runner should have its own infer-out, so no synchronization. Unless I am missing some specific use you have in mind.

cristianoc avatar Mar 06 '17 08:03 cristianoc

@cristianoc Can I use a regular expression to match the file name what I want to analyze?

Well, before that, I have to complete a complete analysis, right? Check if the infer-out directory exists .if it exists, then run incremental analysis, if not exist run full analysis.

sencho avatar Mar 06 '17 09:03 sencho

@sencho index.txt must be an explicit list of files. You can use a regular expression in a script that generates index.txt.

With the process I've described above in points 1. and 2. there's no need to run a previous analysis: each analysis will be completely separate.

But, notice that step 1., the capture, must run on all the files, every time.

cristianoc avatar Mar 06 '17 09:03 cristianoc

@cristianoc ,The third question is that Facebook is using Phabricator to Code Review, but we are using Gitlab Code Review. When Infer completes the analysis, does the result insert the code into the code's comment to block CI progress?

sencho avatar Mar 06 '17 09:03 sencho

Yes the analysis at FB inserts comments into the code review tool, but it does not block progress. It appears together with the other comments, written by programmers, as part of code review.

cristianoc avatar Mar 06 '17 09:03 cristianoc

image

@cristianoc I've seen a presentation on the Infer team online, which has a slideshow introducing the process. When Infer analyzes the problematic code, it is commented on the code through the review tool's API. The code reviewer will ask for the development Repair again after submission, and then run an Infer analysis, until these is no problematic code then you can merge the code, right?

sencho avatar Mar 06 '17 09:03 sencho

The reviewers decide when to accept the code. The static analysis is one of the inputs they use to decide. For example, the issue reported by Infer could be relevant and addressed immediately, or might not be relevant, or might be better addressed in a separate commit.

cristianoc avatar Mar 06 '17 09:03 cristianoc

This is one way of deploying in CI. Feel free to use whatever works best for you, and let us know what's your experience.

cristianoc avatar Mar 06 '17 09:03 cristianoc

@cristianoc Could you talk about the time spent and analysis strategy used by Facebook iOS App to give us a reference, when to use incremental analysis, when to use the full analysis in a CI process.I think I will share my practice here for everyone, if I succeed.

sencho avatar Mar 06 '17 09:03 sencho

@sencho CI on iOS uses always incremental analysis, by giving the list of files that are modified in the current commit (step 2).

edited: added modified

cristianoc avatar Mar 06 '17 09:03 cristianoc

@cristianoc Thanks a lot for your help!

sencho avatar Mar 06 '17 10:03 sencho

@sencho looking forward to hear about your experience. If all works well, a great outcome would be a short guide to help others with CI integration.

cristianoc avatar Mar 06 '17 10:03 cristianoc

@cristianoc ,only infer capture phase spend 28 minutes for 1800+ files(iOS project) ,it is really unacceptable.If the speed is faster, I can implement in every push, instead of merge request.How can i save time?

sencho avatar Mar 07 '17 07:03 sencho

@sencho if you run the same build command, but without Infer, how long does it take?

cristianoc avatar Mar 07 '17 07:03 cristianoc

@cristianoc it takes in 3 minutes without infer

sencho avatar Mar 07 '17 08:03 sencho

Whether the performance of the machine will affect the speed?my mac's cup 2.7 GHz Intel Core i5,8G RAM,SSD

sencho avatar Mar 07 '17 08:03 sencho