microsoft / infersharp

Infer# is an interprocedural and scalable static code analyzer for C#. Via the capabilities of Facebook's Infer, this tool detects null dereferences, resource leaks, and thread-safety violations. It also performs taint flow tracking to detect critical security vulnerabilities like SQL injections.
MIT License
727 stars 28 forks source link

Getting warning "Nothing to compile. Try cleaning the build first." #213

Closed IvanFeric closed 1 year ago

IvanFeric commented 1 year ago

After watching the video about Infersharp from .NET Conf 2022, I decided to try it out. After installing the Visual Studio extension and choosing my solution folder, I get the warning "Nothing to compile. Try cleaning the build first." It doesn't matter if I clean the solution or not, I'm always getting the same thing. Here's the complete log:

[683][      debug] Sqlite write daemon: starting up
[683][      debug] Sqlite write daemon: set up complete, waiting for connections
[683][environment] CWD = /root/infersharp
[683][environment] Read configuration in /root/infersharp/.inferconfig
[683][environment] Project root = /root/infersharp
[683][environment] INFER_ARGS =   @/tmp/args.tmp.df8520
[683][environment] command line arguments:   infer run --no-progress-bar --cfg-json
[683][environment]                           infer-staging/cfg.json --tenv-json
[683][environment]                           infer-staging/tenv.json
[683][environment] Could not retrieve available memory (possibly not on Linux)
[683][environment] Active checkers: self-in-block (C/C++/ObjC), parameter-not-null-checked (C/C++/ObjC), starvation (C/C++/ObjC, Java), siof (C/C++/ObjC), dotnet-resource-leak (C#/.Net), racerd (C/C++/ObjC, C#/.Net, Java), pulse (C/C++/ObjC, C#/.Net, Erlang, Hack, Java), liveness (C/C++/ObjC), inefficient-keyset-iterator (Java), fragment-retains-view (Java)
[683][environment] Scheduler: file
[683][environment] Cores used: 4
[683][environment] Infer version v1.1.0-37d326c1c
[683][environment] Copyright 2009 - present Facebook. All Rights Reserved.
[683][environment] 
[683][   progress] Capturing using JSON mode...
[683][      debug] Tenv.store: global tenv has size 264171816 bytes.
[683][      debug] Tenv.store: canonicalized tenv has size 208454880 bytes.
[683][      debug] GC stats for capture:
[683][      debug]   minor_words: 2.85185e+08
[683][      debug]   promoted_words: 1.13943e+08
[683][      debug]   major_words: 1.17216e+08
[683][      debug]   minor_collections: 278
[683][      debug]   major_collections: 10
[683][      debug]   compactions: 0
[683][      debug]   top_heap_words: 116751872
[683][      debug]   
[683][  user warn] Nothing to compile. Try cleaning the build first.
[683][   progress] There was nothing to analyze.
[683][      debug] GC stats for report:
[683][      debug]   minor_words: 3868
[683][      debug]   promoted_words: 0
[683][      debug]   major_words: 0
[683][      debug]   minor_collections: 0
[683][      debug]   major_collections: 0
[683][      debug]   compactions: 0
[683][      debug]   top_heap_words: 116751872
[683][      debug]   
[683][      debug] GC stats for main_process_full:
[683][      debug]   minor_words: 2.87175e+08
[683][      debug]   promoted_words: 1.14349e+08
[683][      debug]   major_words: 1.17649e+08
[683][      debug]   minor_collections: 285
[683][      debug]   major_collections: 10
[683][      debug]   compactions: 0
[683][      debug]   top_heap_words: 116751872
[683][      debug]   
[684][      debug] Detected 0 spec overwrittes.
[684][      debug] Sqlite write daemon: terminating
[683][     result] 
  No issues found  

To add more details about the solution - it is a .NET 7 solution that contains ASP.NET API, Blazor WASM, Console App, 3 Razor control projects, and 9 class library projects. It is using Directory.Packages.props file in the root folder to define the versions of dependency packages. I pointed the Infersharp to the solution folder, but I'm getting the same error even if I point it to the ASP.NET API project, its bin folder, or even its bin/Debug/net7.0 folder. I'm using WSL 2.0 that I had installed prior to trying out the Infersharp. I'm using Visual Studio 2022 Community edition.

Is there something that I need to do additionally to make it work?

matjin commented 1 year ago

Can you confirm that you output both dlls and pdbs as separate files present in the bin/Debug/net7.0 folder, and that the cfg.json file is present in the ~/infersharp folder of the infersharp WSL distribution? Just run something like wsl ~ -d infersharp1.4 ls ~/infersharp from command prompt.

IvanFeric commented 1 year ago

@matjin, I just checked and I can confirm that there are both dlls and pdbs in the bin folder. However, the cfg.json file is not present in the infersharp WSL distribution. Running the command you suggested, I'm getting this folder contents:

Cilsil  Examples  infer  infer-out  infer-staging  run_infersharp.sh
matjin commented 1 year ago

Oh, it should be actually:

wsl ~ -d infersharp1.4 ls ~/infersharp/infer-staging

Can you confirm that the cfg.json and tenv.json files are in there?

Basically, the extension is executing this script:

https://github.com/microsoft/infersharp/blob/main/run_infersharp.sh

In particular, we need to make sure that the cfg.json and tenv.json are present in the ~/infersharp/infer-staging directory (based on your logs, I suspect they are), and also make sure that we are running a clean analysis by removing the old infer-out/ folder.

To do this: Can you navigate to the ~/infersharp folder of your infersharp1.4 WSL distro (just say wsl ~ -d infersharp1.4; cd infersharp), clear the infer-out/ folder (just do rm -rf infer-out/ from ~/infersharp) and then do infer run --cfg-json infer-staging/cfg.json --tenv-json infer-staging/tenv.json ?

IvanFeric commented 1 year ago

I tried it out and I'm getting the same Nothing to compile. Try cleaning the build first. message. I can see that the /infer-staging folder contains both cfg.json and tenv.json files. It also contains all of the .dll and .pdb files related to my projects as well as .dll files (no .pdbs) for external dependencies and Microsoft-related libraries.

matjin commented 1 year ago

Can you try running on our Examples? Just build the project first, and then run the extension/go through this exercise in WSL. This will help us figure out whether the issue is specific to your project or your system.

IvanFeric commented 1 year ago

I just tried it out - built the solution first, then ran the plugin and got the same result. After that, I tried removing the infer-out folder and running the infersharp from the command line but I'm still getting the same result.

matjin commented 1 year ago

OK. In that case it definitely sounds like we have a setup/installation problem. Would you mind rerunning this experiment with Examples/ in Docker? https://github.com/microsoft/infersharp/blob/main/RUNNING_IN_DOCKER.md

IvanFeric commented 1 year ago

I ran it from Docker and it does work with the examples folder. However, one thing that I noticed from the start is that this is a different version than the one from Visual Studio extensions. The output from Docker has a line Infer version v1.1.0-7f5c21d32, while when running from Visual Studio it is Infer version v1.1.0-37d326c1c. The Visual Studio extension is mentioning version 1.41, not the 1.4 that I pulled from mcr.microsoft.com/infersharp repository.

matjin commented 1 year ago

It's possible there is a slight discrepancy between the infer binaries in Docker vs the WSL distribution, but it should be fairly inconsequential in practice. We'll look out for this issue in future release updates.

Good to hear that Examples/ works in Docker. Did you try your project in Docker as well? You can generate the SARIF file and then read it in your main OS, or you could probably read the SARIF output in Docker as well -- this would overcome the main functional gap between the Docker experience and the VS extension

IvanFeric commented 1 year ago

I didn't try it with Docker because I don't want to use it that way. I want it to be convenient with a click of a button for everyone on the team. That's why I used the VS extension approach from the start.

I will reevaluate the Infersharp when the VS extension gets the next update then.

Thanks for your effort!

matjin commented 12 months ago

Hello, just wanted to follow up on this:

Looked into this issue again https://github.com/microsoft/infersharp/issues/219 and determined that what you are likely facing is the versioning of WSL: it's on WSL 1 not 2. If you adjust this, then the pipeline should work for you.