From 142fcf37049b2697b27721dae0f92ad7e5b47f8c Mon Sep 17 00:00:00 2001 From: Dima Golovinov Date: Thu, 25 Apr 2024 17:05:25 +0200 Subject: [PATCH] :bricks: Move linter specific args to top level to use them from Qodana CLI --- cdnet/options.go | 30 +++++-------------- cdnet/options_test.go | 66 +++++++++++++++++++++--------------------- clang | 2 +- core/ide.go | 22 +++++++------- platform/argflags.go | 15 ++++++---- platform/clioptions.go | 2 -- platform/options.go | 12 ++++---- 7 files changed, 68 insertions(+), 81 deletions(-) diff --git a/cdnet/options.go b/cdnet/options.go index 5b962806..a131a524 100644 --- a/cdnet/options.go +++ b/cdnet/options.go @@ -19,7 +19,6 @@ package main import ( "fmt" "github.com/JetBrains/qodana-cli/v2024/platform" - "github.com/spf13/pflag" "strconv" "strings" ) @@ -29,13 +28,8 @@ type LocalOptions struct { } type CltOptions struct { - Solution string - Project string - Configuration string - Platform string - NoBuild bool - MountInfo *platform.MountInfo - LinterInfo *platform.LinterInfo + MountInfo *platform.MountInfo + LinterInfo *platform.LinterInfo } func (o *CltOptions) GetMountInfo() *platform.MountInfo { @@ -51,14 +45,6 @@ func (o *CltOptions) GetInfo(_ *platform.QodanaOptions) *platform.LinterInfo { return o.LinterInfo } -func (o *CltOptions) AddFlags(flags *pflag.FlagSet) { - flags.StringVar(&o.Solution, "solution", "", "Relative path to solution file") - flags.StringVar(&o.Project, "project", "", "Relative path to project file") - flags.StringVar(&o.Configuration, "configuration", "", "Build configuration") - flags.StringVar(&o.Platform, "platform", "", "Build platform") - flags.BoolVar(&o.NoBuild, "no-build", false, "Do not build the project before analysis") -} - func (o *LocalOptions) GetCltOptions() *CltOptions { if v, ok := o.LinterSpecific.(*CltOptions); ok { return v @@ -84,22 +70,22 @@ func (o *CltOptions) computeCdnetArgs(opts *platform.QodanaOptions, options *Loc } props += p } - if options.GetCltOptions().Configuration != "" { + if options.CdnetConfiguration != "" { if props != "" { props += ";" } - props += "Configuration=" + options.GetCltOptions().Configuration + props += "Configuration=" + options.CdnetConfiguration } else if yaml.DotNet.Configuration != "" { if props != "" { props += ";" } props += "Configuration=" + yaml.DotNet.Configuration } - if options.GetCltOptions().Platform != "" { + if options.CdnetPlatform != "" { if props != "" { props += ";" } - props += "Platform=" + options.GetCltOptions().Platform + props += "Platform=" + options.CdnetPlatform } else if yaml.DotNet.Platform != "" { if props != "" { props += ";" @@ -129,7 +115,7 @@ func (o *CltOptions) computeCdnetArgs(opts *platform.QodanaOptions, options *Loc if options.NoStatistics { args = append(args, "--telemetry-optout") } - if options.GetCltOptions().NoBuild { + if options.CdnetNoBuild { args = append(args, "--no-build") } return args, nil @@ -137,7 +123,7 @@ func (o *CltOptions) computeCdnetArgs(opts *platform.QodanaOptions, options *Loc func getSolutionOrProject(options *LocalOptions, yaml platform.QodanaYaml) string { var target = "" - paths := [4]string{options.GetCltOptions().Solution, options.GetCltOptions().Project, yaml.DotNet.Solution, yaml.DotNet.Project} + paths := [4]string{options.CdnetSolution, options.CdnetProject, yaml.DotNet.Solution, yaml.DotNet.Project} for _, path := range paths { if path != "" { target = path diff --git a/cdnet/options_test.go b/cdnet/options_test.go index 349a5606..9f6957a0 100644 --- a/cdnet/options_test.go +++ b/cdnet/options_test.go @@ -59,10 +59,10 @@ func TestComputeCdnetArgs(t *testing.T) { { name: "project specified", options: &platform.QodanaOptions{ - Property: []string{}, - ResultsDir: "", + Property: []string{}, + ResultsDir: "", + CdnetProject: "project", LinterSpecific: &CltOptions{ - Project: "project", MountInfo: getTooling(), }, }, @@ -86,10 +86,10 @@ func TestComputeCdnetArgs(t *testing.T) { { name: "solution specified", options: &platform.QodanaOptions{ - Property: []string{}, - ResultsDir: "", + Property: []string{}, + ResultsDir: "", + CdnetSolution: "solution", LinterSpecific: &CltOptions{ - Solution: "solution", MountInfo: getTooling(), }, }, @@ -126,11 +126,11 @@ func TestComputeCdnetArgs(t *testing.T) { { name: "configuration specified", options: &platform.QodanaOptions{ - Property: []string{}, - ResultsDir: "", + Property: []string{}, + ResultsDir: "", + CdnetConfiguration: "cfg", LinterSpecific: &CltOptions{ - Configuration: "cfg", - MountInfo: getTooling(), + MountInfo: getTooling(), }, }, yaml: createDefaultYaml("solution", "", "", ""), @@ -153,10 +153,10 @@ func TestComputeCdnetArgs(t *testing.T) { { name: "platform specified", options: &platform.QodanaOptions{ - Property: []string{}, - ResultsDir: "", + Property: []string{}, + ResultsDir: "", + CdnetPlatform: "x64", LinterSpecific: &CltOptions{ - Platform: "x64", MountInfo: getTooling(), }, }, @@ -167,12 +167,12 @@ func TestComputeCdnetArgs(t *testing.T) { { name: "many options", options: &platform.QodanaOptions{ - Property: []string{"prop1=val1", "prop2=val2"}, - ResultsDir: "", + Property: []string{"prop1=val1", "prop2=val2"}, + ResultsDir: "", + CdnetPlatform: "x64", + CdnetConfiguration: "Debug", LinterSpecific: &CltOptions{ - Platform: "x64", - Configuration: "Debug", - MountInfo: getTooling(), + MountInfo: getTooling(), }, }, yaml: createDefaultYaml("solution", "", "", ""), @@ -182,10 +182,10 @@ func TestComputeCdnetArgs(t *testing.T) { { name: "no-build", options: &platform.QodanaOptions{ - Property: []string{}, - ResultsDir: "", + Property: []string{}, + ResultsDir: "", + CdnetNoBuild: true, LinterSpecific: &CltOptions{ - NoBuild: true, MountInfo: getTooling(), }, }, @@ -258,8 +258,8 @@ func TestGetArgsThirdPartyLinters(t *testing.T) { { name: "(cdnet) solution", options: &platform.QodanaOptions{ - Solution: "solution.sln", - Linter: platform.DockerImageMap[platform.QDNETC], + CdnetSolution: "solution.sln", + Linter: platform.DockerImageMap[platform.QDNETC], }, expected: []string{ "--solution", "solution.sln", @@ -268,8 +268,8 @@ func TestGetArgsThirdPartyLinters(t *testing.T) { { name: "(cdnet) project", options: &platform.QodanaOptions{ - Project: "project.csproj", - Linter: platform.DockerImageMap[platform.QDNETC], + CdnetProject: "project.csproj", + Linter: platform.DockerImageMap[platform.QDNETC], }, expected: []string{ "--project", "project.csproj", @@ -278,8 +278,8 @@ func TestGetArgsThirdPartyLinters(t *testing.T) { { name: "(cdnet) configuration", options: &platform.QodanaOptions{ - Configuration: "Debug", - Linter: platform.DockerImageMap[platform.QDNETC], + CdnetConfiguration: "Debug", + Linter: platform.DockerImageMap[platform.QDNETC], }, expected: []string{ "--configuration", "Debug", @@ -288,8 +288,8 @@ func TestGetArgsThirdPartyLinters(t *testing.T) { { name: "(cdnet) platform", options: &platform.QodanaOptions{ - Platform: "x64", - Linter: platform.DockerImageMap[platform.QDNETC], + CdnetPlatform: "x64", + Linter: platform.DockerImageMap[platform.QDNETC], }, expected: []string{ "--platform", "x64", @@ -298,8 +298,8 @@ func TestGetArgsThirdPartyLinters(t *testing.T) { { name: "(cdnet) no build", options: &platform.QodanaOptions{ - NoBuild: true, - Linter: platform.DockerImageMap[platform.QDNETC], + CdnetNoBuild: true, + Linter: platform.DockerImageMap[platform.QDNETC], }, expected: []string{ "--no-build", @@ -308,8 +308,8 @@ func TestGetArgsThirdPartyLinters(t *testing.T) { { name: "(clang) compile commands", options: &platform.QodanaOptions{ - CompileCommands: "compile_commands.json", - Linter: platform.DockerImageMap[platform.QDCL], + ClangCompileCommands: "compile_commands.json", + Linter: platform.DockerImageMap[platform.QDCL], }, expected: []string{ "--compile-commands", "compile_commands.json", diff --git a/clang b/clang index bb3350bb..0e76a1b8 160000 --- a/clang +++ b/clang @@ -1 +1 @@ -Subproject commit bb3350bb0118a42a00314d96590014e8903ff584 +Subproject commit 0e76a1b860ba2956392e26a9fb71a0e4b046c983 diff --git a/core/ide.go b/core/ide.go index 0a58ae47..a6c5f26f 100644 --- a/core/ide.go +++ b/core/ide.go @@ -155,25 +155,25 @@ func GetIdeArgs(opts *QodanaOptions) []string { } if prod == platform.QDNETC { // cdnet options - if opts.Solution != "" { - arguments = append(arguments, "--solution", platform.QuoteForWindows(opts.Solution)) + if opts.CdnetSolution != "" { + arguments = append(arguments, "--solution", platform.QuoteForWindows(opts.CdnetSolution)) } - if opts.Project != "" { - arguments = append(arguments, "--project", platform.QuoteForWindows(opts.Project)) + if opts.CdnetProject != "" { + arguments = append(arguments, "--project", platform.QuoteForWindows(opts.CdnetProject)) } - if opts.Configuration != "" { - arguments = append(arguments, "--configuration", opts.Configuration) + if opts.CdnetConfiguration != "" { + arguments = append(arguments, "--configuration", opts.CdnetConfiguration) } - if opts.Platform != "" { - arguments = append(arguments, "--platform", opts.Platform) + if opts.CdnetPlatform != "" { + arguments = append(arguments, "--platform", opts.CdnetPlatform) } - if opts.NoBuild { + if opts.CdnetNoBuild { arguments = append(arguments, "--no-build") } } else { // clang options - if opts.CompileCommands != "" { - arguments = append(arguments, "--compile-commands", platform.QuoteForWindows(opts.CompileCommands)) + if opts.ClangCompileCommands != "" { + arguments = append(arguments, "--compile-commands", platform.QuoteForWindows(opts.ClangCompileCommands)) } if opts.ClangArgs != "" { arguments = append(arguments, "--clang-args", opts.ClangArgs) diff --git a/platform/argflags.go b/platform/argflags.go index be8dfab5..8782db42 100644 --- a/platform/argflags.go +++ b/platform/argflags.go @@ -76,12 +76,15 @@ func ComputeFlags(cmd *cobra.Command, options *QodanaOptions) error { flags.BoolVar(&options.ForceDiffMode, "force-diff-analysis-mode", false, "Override the default run-scenario for diff runs to always use the restart-based approach") flags.IntVar(&options.JvmDebugPort, "jvm-debug-port", -1, "Enable JVM remote debug under given port") - if options.LinterSpecific != nil { - if linterSpecific, ok := options.LinterSpecific.(ThirdPartyOptions); ok { - linterSpecific.AddFlags(flags) - } - flags.BoolVar(&options.NoStatistics, "no-statistics", false, "Disable sending anonymous statistics") - } + + flags.BoolVar(&options.NoStatistics, "no-statistics", false, "[qodana-clang/qodana-dotner]Disable sending anonymous statistics") + flags.StringVar(&options.ClangCompileCommands, "compile-commands", "./build/compile_commands.json", "[qodana-clang specific] Path to compile_commands.json") + flags.StringVar(&options.ClangArgs, "clang-args", "", "[qodana-clang specific] Additional arguments for clang") + flags.StringVar(&options.CdnetSolution, "solution", "", "[qodana-cdnet specific] Relative path to solution file") + flags.StringVar(&options.CdnetProject, "project", "", "[qodana-cdnet specific] Relative path to project file") + flags.StringVar(&options.CdnetConfiguration, "configuration", "", "[qodana-cdnet specific] Build configuration") + flags.StringVar(&options.CdnetPlatform, "platform", "", "[qodana-cdnet specific] Build platform") + flags.BoolVar(&options.CdnetNoBuild, "no-build", false, "[qodana-cdnet specific] Do not build the project before analysis") if !IsContainer() { flags.StringArrayVarP(&options.Env, "env", "e", []string{}, "Only for container runs. Define additional environment variables for the Qodana container (you can use the flag multiple times). CLI is not reading full host environment variables and does not pass it to the Qodana container for security reasons") diff --git a/platform/clioptions.go b/platform/clioptions.go index 8bf72499..438bce5e 100644 --- a/platform/clioptions.go +++ b/platform/clioptions.go @@ -17,13 +17,11 @@ package platform import ( - "github.com/spf13/pflag" "regexp" ) // ThirdPartyOptions is used to customize the CLI options for a specific linter. type ThirdPartyOptions interface { - AddFlags(flags *pflag.FlagSet) GetMountInfo() *MountInfo MountTools(tempPath string, mountPath string, o *QodanaOptions) (map[string]string, error) GetInfo(o *QodanaOptions) *LinterInfo diff --git a/platform/options.go b/platform/options.go index 82b0563a..d2049964 100644 --- a/platform/options.go +++ b/platform/options.go @@ -78,12 +78,12 @@ type QodanaOptions struct { LicensePlan string ProjectIdHash string NoStatistics bool // thirdparty common option - Solution string // cdnet specific options - Project string - Configuration string - Platform string - NoBuild bool - CompileCommands string // clang specific options + CdnetSolution string // cdnet specific options + CdnetProject string + CdnetConfiguration string + CdnetPlatform string + CdnetNoBuild bool + ClangCompileCommands string // clang specific options ClangArgs string AnalysisTimeoutMs int AnalysisTimeoutExitCode int