From 38570a88c5fc8112b84030a3f34f34734327f795 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Sun, 2 Jul 2023 11:26:17 +0300 Subject: [PATCH] cxgo: Allow overriding glob configs. --- cmd/cxgo/main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/cxgo/main.go b/cmd/cxgo/main.go index abf271f..2118430 100644 --- a/cmd/cxgo/main.go +++ b/cmd/cxgo/main.go @@ -239,7 +239,12 @@ func run(cmd *cobra.Command, args []string) error { } c.SysInclude[i] = filepath.Join(c.Root, c.SysInclude[i]) } + seen := make(map[string]struct{}) processFile := func(f *File) error { + if _, ok := seen[f.Name]; ok { + return fmt.Errorf("ducplicate entry for file: %q", f.Name) + } + seen[f.Name] = struct{}{} if f.Content != "" { data := []byte(f.Content) if fdata, err := format.Source(data); err == nil { @@ -320,6 +325,7 @@ func run(cmd *cobra.Command, args []string) error { } for _, f := range c.Files { if f.Disabled { + seen[f.Name] = struct{}{} continue } if strings.Contains(f.Name, "*") { @@ -332,6 +338,9 @@ func run(cmd *cobra.Command, args []string) error { if err != nil { return fmt.Errorf("%s: %w", path, err) } + if _, ok := seen[rel]; ok { + continue + } f2 := *f f2.Name = rel if err := processFile(&f2); err != nil {