Skip to content

Commit

Permalink
🧱 Move linter specific args to top level to use them from Qodana CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
hybloid authored and tiulpin committed Apr 25, 2024
1 parent d05dbb1 commit 142fcf3
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 81 deletions.
30 changes: 8 additions & 22 deletions cdnet/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"
"github.com/JetBrains/qodana-cli/v2024/platform"
"github.com/spf13/pflag"
"strconv"
"strings"
)
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 += ";"
Expand Down Expand Up @@ -129,15 +115,15 @@ 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
}

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
Expand Down
66 changes: 33 additions & 33 deletions cdnet/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
Expand All @@ -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(),
},
},
Expand Down Expand Up @@ -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", "", "", ""),
Expand All @@ -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(),
},
},
Expand All @@ -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", "", "", ""),
Expand All @@ -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(),
},
},
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion clang
Submodule clang updated from bb3350 to 0e76a1
22 changes: 11 additions & 11 deletions core/ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions platform/argflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions platform/clioptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions platform/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 142fcf3

Please sign in to comment.