Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use nilaway for a Golang project involved conditional compilation? #154

Open
hxiaodon opened this issue Dec 20, 2023 · 1 comment
Assignees
Labels
driver help wanted Extra attention is needed

Comments

@hxiaodon
Copy link

hxiaodon commented Dec 20, 2023

I tried running nilaway cmd for our internal project, but it failed with the following error

internal/app/xxx/domain/task.go:244:18: undefined: settings.XXXXX

settings.XXXXX is indeed defined in a source file with "//go:build $flagname" statement declared at the first line

The golangci-lint has the build-flag option while nilaway's analyzer deprecated it

user% ./nilaway --help
nilaway: Run NilAway on this package to report any possible flows of nil values to erroneous sites that our system can detect

Usage: nilaway [-flag] [package]


Flags:
  -V	print version and exit
  -all
    	no effect (deprecated)
  -c int
    	display offending line with this many lines of context (default -1)
  -cpuprofile string
    	write CPU profile to this file
  -debug string
    	debug flags, any subset of "fpstv"
  -exclude-errors-in-files string
    	A comma-separated list of file prefixes to exclude from error reporting. This takes precedence over include-errors-in-files.
  -exclude-file-docstrings value
    	Comma-separated list of docstrings to exclude from analysis
  -exclude-pkgs value
    	Comma-separated list of packages to exclude from analysis
  -fix
    	apply all suggested fixes
  -flags
    	print analyzer flags in JSON
  -include-errors-in-files string
    	A comma-separated list of file prefixes to report errors, default is current working directory. (default "/Users/tiger/Downloads/working/nilaway")
  -include-pkgs value
    	Comma-separated list of packages to analyze
  -json
    	emit JSON output
  -memprofile string
    	write memory profile to this file
  -pretty-print value
    	Pretty print the error messages
  -source
    	no effect (deprecated)
  -tags string
    	no effect (deprecated)
  -test
    	indicates whether test files should be analyzed, too (default true)
  -trace string
    	write trace log to this file
  -v	no effect (deprecated)

Any suggestion for this issue? Thanks~

@sonalmahajan15 sonalmahajan15 added the needs triaging Requires triaging by the maintainers label Jan 4, 2024
@yuxincs
Copy link
Contributor

yuxincs commented Jan 17, 2024

We are using the singlechecker package from x/tools package: https://pkg.go.dev/golang.org/x/tools/go/analysis/singlechecker, and the flags you see there are not directly related to NilAway (populated by the singlechecker linter driver).

Here it seems that the singlechecker does not have proper support for build tags and we have very little control over that since singlechecker takes the entire main function entry away and handles the package loading logic (other than writing our own linter driver of course). There has been golang/go#61324 that tries to implement an importable checker driver API, which would provide some flexibilities to configure the package loader. We are waiting for that to be available.

In the meantime, we can also hack around to see if it's possible to fix this (feel free to do so yourself and send a PR 😃 ). I'm keeping this issue open to track this.

@yuxincs yuxincs added help wanted Extra attention is needed driver and removed needs triaging Requires triaging by the maintainers labels Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
driver help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants