Skip to content

Commit

Permalink
Add -scala_gazelle_print_cache_key flag (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj authored Nov 30, 2023
1 parent 9662ee3 commit 7bd32ba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions language/scala/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ const (
scalaGazelleCacheFileFlagName = "scala_gazelle_cache_file"
scalaGazelleDebugProcessFileFlagName = "scala_gazelle_debug_process"
scalaGazelleCacheKeyFlagName = "scala_gazelle_cache_key"
scalaGazellePrintCacheKeyFlagName = "scala_gazelle_print_cache_key"
cpuprofileFileFlagName = "cpuprofile_file"
memprofileFileFlagName = "memprofile_file"
)

// RegisterFlags implements part of the language.Language interface
func (sl *scalaLang) RegisterFlags(flags *flag.FlagSet, cmd string, c *config.Config) {
flags.BoolVar(&sl.debugProcessFlagValue, scalaGazelleDebugProcessFileFlagName, false, "if true, prints the process ID and waits for debugger to attach")
flags.BoolVar(&sl.printCacheKey, scalaGazellePrintCacheKeyFlagName, true, "if a cache key is set, print the version for auditing purposes")
flags.StringVar(&sl.cacheFileFlagValue, scalaGazelleCacheFileFlagName, "", "optional path a cache file (.json or .pb)")
flags.StringVar(&sl.cacheKeyFlagValue, scalaGazelleCacheKeyFlagName, "", "optional string that can be used to bust the cache file")
flags.StringVar(&sl.cpuprofileFlagValue, cpuprofileFileFlagName, "", "optional path a cpuprofile file (.prof)")
Expand Down Expand Up @@ -58,6 +60,9 @@ func (sl *scalaLang) registerConflictResolvers(flags *flag.FlagSet, cmd string,

// CheckFlags implements part of the language.Language interface
func (sl *scalaLang) CheckFlags(flags *flag.FlagSet, c *config.Config) error {
if sl.printCacheKey && sl.cacheKeyFlagValue != "" {
fmt.Printf("scala-gazelle: cache v.%s\n", sl.cacheKeyFlagValue)
}
if sl.debugProcessFlagValue {
fmt.Printf("Debugging session requested (Process ID: %d)\n", os.Getpid())
fmt.Printf("NOTE: binary must be built with debug symbols for this to work (e.g 'bazel run -c dbg //:gazelle')\n")
Expand Down
24 changes: 24 additions & 0 deletions language/scala/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ func TestCacheFlags(t *testing.T) {
}
},
},
"scala_gazelle_print_cache_key_on": {
args: []string{
"-scala_gazelle_cache_key=12345",
"-scala_gazelle_print_cache_key=true",
},
check: func(t *testing.T, tmpDir string, lang *scalaLang) {
if diff := cmp.Diff("12345", lang.cacheKeyFlagValue); diff != "" {
t.Errorf("cacheKeyFlagValue (-want got):\n%s", diff)
}
if diff := cmp.Diff(true, lang.printCacheKey); diff != "" {
t.Errorf("printCacheKey (-want got):\n%s", diff)
}
},
},
"scala_gazelle_print_cache_key_off": {
args: []string{
"-scala_gazelle_print_cache_key=false",
},
check: func(t *testing.T, tmpDir string, lang *scalaLang) {
if diff := cmp.Diff(false, lang.printCacheKey); diff != "" {
t.Errorf("printCacheKey (-want got):\n%s", diff)
}
},
},
"scala_gazelle_cache_key__valid": {
files: []testtools.FileSpec{
{
Expand Down
2 changes: 2 additions & 0 deletions language/scala/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type scalaLang struct {
// debugProcessFlagValue halts processing and prints the PID for attaching a
// delve debugger.
debugProcessFlagValue bool
// optional flag to print the cache key version
printCacheKey bool
// wantProgress is a flag that prints docker style progress messages if enabled
wantProgress bool
// cacheFileFlagValue is the main cache file, if enabled
Expand Down

0 comments on commit 7bd32ba

Please sign in to comment.