@@ -243,7 +243,7 @@ func executeCommandInLocations(rawExecCmd []string, locs []commandExecLocation,
243243 }
244244
245245 for _ , loc := range locs {
246- if ok , _ := cache .NeedsExecution (context .Background (), loc . Package ); ! ok {
246+ if ok , _ := cache .NeedsExecution (context .Background (), loc ); ! ok {
247247 continue
248248 }
249249
@@ -284,7 +284,7 @@ func executeCommandInLocations(rawExecCmd []string, locs []commandExecLocation,
284284 eg .Go (func () error {
285285 err := cmd .Wait ()
286286 if err == nil {
287- err = cache .MarkExecuted (context .Background (), loc . Package )
287+ err = cache .MarkExecuted (context .Background (), loc )
288288 if err != nil {
289289 log .WithError (err ).Warn ("cannot mark package as executed" )
290290 }
@@ -296,7 +296,7 @@ func executeCommandInLocations(rawExecCmd []string, locs []commandExecLocation,
296296 } else {
297297 err = cmd .Wait ()
298298 if err == nil {
299- err = cache .MarkExecuted (context .Background (), loc . Package )
299+ err = cache .MarkExecuted (context .Background (), loc )
300300 if err != nil {
301301 log .WithError (err ).Warn ("cannot mark package as executed" )
302302 }
@@ -332,25 +332,25 @@ func init() {
332332}
333333
334334type execCache interface {
335- NeedsExecution (ctx context.Context , pkg * leeway. Package ) (bool , error )
336- MarkExecuted (ctx context.Context , pkg * leeway. Package ) error
335+ NeedsExecution (ctx context.Context , loc commandExecLocation ) (bool , error )
336+ MarkExecuted (ctx context.Context , loc commandExecLocation ) error
337337}
338338
339339type noExecCache struct {}
340340
341- func (noExecCache ) MarkExecuted (ctx context.Context , pkg * leeway. Package ) error { return nil }
342- func (noExecCache ) NeedsExecution (ctx context.Context , pkg * leeway. Package ) (bool , error ) {
341+ func (noExecCache ) MarkExecuted (ctx context.Context , loc commandExecLocation ) error { return nil }
342+ func (noExecCache ) NeedsExecution (ctx context.Context , loc commandExecLocation ) (bool , error ) {
343343 return true , nil
344344}
345345
346346type filesystemExecCache string
347347
348- func (c filesystemExecCache ) MarkExecuted (ctx context.Context , pkg * leeway. Package ) error {
348+ func (c filesystemExecCache ) MarkExecuted (ctx context.Context , loc commandExecLocation ) error {
349349 err := os .MkdirAll (string (c ), 0755 )
350350 if err != nil {
351351 return err
352352 }
353- fn , err := c .filename (pkg )
353+ fn , err := c .filename (loc )
354354 if err != nil {
355355 return err
356356 }
@@ -359,20 +359,31 @@ func (c filesystemExecCache) MarkExecuted(ctx context.Context, pkg *leeway.Packa
359359 return err
360360 }
361361 f .Close ()
362- log .WithField ("name" , pkg . FullName ()) .Debug ("marked package as executed" )
362+ log .WithField ("name" , fn ) .Debug ("marked executed" )
363363 return nil
364364}
365365
366- func (c filesystemExecCache ) filename (pkg * leeway.Package ) (string , error ) {
367- v , err := pkg .Version ()
368- if err != nil {
369- return "" , err
366+ func (c filesystemExecCache ) filename (loc commandExecLocation ) (string , error ) {
367+ var id string
368+ if loc .Package != nil {
369+ v , err := loc .Package .Version ()
370+ if err != nil {
371+ return "" , err
372+ }
373+ id = v
374+ } else if loc .Component != nil {
375+ id = leeway .FilesystemSafeName (loc .Component .Name )
376+ } else if loc .Dir != "" {
377+ id = leeway .FilesystemSafeName (loc .Dir )
378+ } else if loc .Name != "" {
379+ id = loc .Name
370380 }
371- return filepath .Join (string (c ), fmt .Sprintf ("%s.executed" , v )), nil
381+
382+ return filepath .Join (string (c ), fmt .Sprintf ("%s.executed" , id )), nil
372383}
373384
374- func (c filesystemExecCache ) NeedsExecution (ctx context.Context , pkg * leeway. Package ) (bool , error ) {
375- fn , err := c .filename (pkg )
385+ func (c filesystemExecCache ) NeedsExecution (ctx context.Context , loc commandExecLocation ) (bool , error ) {
386+ fn , err := c .filename (loc )
376387 if err != nil {
377388 return false , err
378389 }
0 commit comments