diff --git a/internal/config/config.go b/internal/config/config.go index 3d78be9..285cf09 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -27,7 +27,8 @@ type PackageSpec struct { NuGetID string `json:"nugetId,omitempty"` NuGetVersion string `json:"nugetVersion,omitempty"` NuGetFramework string `json:"nugetFramework,omitempty"` - Exclude []string `json:"exclude,omitempty"` + Exclude []string `json:"exclude,omitempty"` + SuppressWarnings []string `json:"suppressWarnings,omitempty"` } type Config struct { diff --git a/internal/packager/archive.go b/internal/packager/archive.go index 6c3c37e..b488ac1 100644 --- a/internal/packager/archive.go +++ b/internal/packager/archive.go @@ -42,6 +42,10 @@ func (p *Packager) processArchive(spec config.PackageSpec) error { if err := CopyFiltered(srcDir, destDir, spec.Exclude); err != nil { return fmt.Errorf("copying archive package %q: %w", spec.Name, err) } + + if err := unity.WriteCscRspForAsmdefs(destDir, spec.SuppressWarnings); err != nil { + return fmt.Errorf("writing csc.rsp for %q: %w", spec.Name, err) + } } else { // Raw package — copy into Runtime/, generate package.json + asmdef (like git-raw) runtimeDir := filepath.Join(destDir, "Runtime") @@ -67,6 +71,10 @@ func (p *Packager) processArchive(spec config.PackageSpec) error { if err := unity.WriteAsmDef(runtimeDir, spec.Name+".asmdef", asmdef); err != nil { return fmt.Errorf("writing asmdef for %q: %w", spec.Name, err) } + + if err := unity.WriteCscRsp(runtimeDir, spec.SuppressWarnings); err != nil { + return fmt.Errorf("writing csc.rsp for %q: %w", spec.Name, err) + } } if err := GenerateMetaFiles(destDir, spec.Name); err != nil { diff --git a/internal/packager/git.go b/internal/packager/git.go index a956df3..e0295ff 100644 --- a/internal/packager/git.go +++ b/internal/packager/git.go @@ -32,6 +32,10 @@ func (p *Packager) processGitUnity(spec config.PackageSpec) error { return fmt.Errorf("copying git-unity package %q: %w", spec.Name, err) } + if err := unity.WriteCscRspForAsmdefs(destDir, spec.SuppressWarnings); err != nil { + return fmt.Errorf("writing csc.rsp for %q: %w", spec.Name, err) + } + if err := GenerateMetaFiles(destDir, spec.Name); err != nil { return fmt.Errorf("generating meta files for %q: %w", spec.Name, err) } @@ -80,6 +84,10 @@ func (p *Packager) processGitRaw(spec config.PackageSpec) error { return fmt.Errorf("writing asmdef for %q: %w", spec.Name, err) } + if err := unity.WriteCscRsp(runtimeDir, spec.SuppressWarnings); err != nil { + return fmt.Errorf("writing csc.rsp for %q: %w", spec.Name, err) + } + // Generate meta files for everything if err := GenerateMetaFiles(destDir, spec.Name); err != nil { return fmt.Errorf("generating meta files for %q: %w", spec.Name, err) diff --git a/internal/unity/cscrsp.go b/internal/unity/cscrsp.go new file mode 100644 index 0000000..76a6d88 --- /dev/null +++ b/internal/unity/cscrsp.go @@ -0,0 +1,38 @@ +package unity + +import ( + "os" + "path/filepath" + "strings" +) + +// WriteCscRsp writes a csc.rsp file with -nowarn directives for the given warning codes. +// The file is placed at the given path (typically next to an .asmdef file). +func WriteCscRsp(dir string, warnings []string) error { + if len(warnings) == 0 { + return nil + } + content := "-nowarn:" + strings.Join(warnings, ",") + "\n" + return os.WriteFile(filepath.Join(dir, "csc.rsp"), []byte(content), 0644) +} + +// WriteCscRspForAsmdefs finds all .asmdef files under rootDir and writes a csc.rsp +// next to each one. This is used for packages that already contain their own .asmdef +// files (git-unity and archive-unity). +func WriteCscRspForAsmdefs(rootDir string, warnings []string) error { + if len(warnings) == 0 { + return nil + } + return filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error { + if err != nil || info.IsDir() { + return nil + } + if strings.HasSuffix(path, ".asmdef") { + dir := filepath.Dir(path) + if err := WriteCscRsp(dir, warnings); err != nil { + return err + } + } + return nil + }) +} diff --git a/internal/unity/cscrsp_test.go b/internal/unity/cscrsp_test.go new file mode 100644 index 0000000..0f1afce --- /dev/null +++ b/internal/unity/cscrsp_test.go @@ -0,0 +1,100 @@ +package unity + +import ( + "os" + "path/filepath" + "testing" +) + +func TestWriteCscRsp(t *testing.T) { + dir := t.TempDir() + + if err := WriteCscRsp(dir, []string{"0618", "0649"}); err != nil { + t.Fatalf("WriteCscRsp: %v", err) + } + + data, err := os.ReadFile(filepath.Join(dir, "csc.rsp")) + if err != nil { + t.Fatalf("reading csc.rsp: %v", err) + } + + expected := "-nowarn:0618,0649\n" + if string(data) != expected { + t.Errorf("csc.rsp content: got %q, want %q", string(data), expected) + } +} + +func TestWriteCscRsp_SingleWarning(t *testing.T) { + dir := t.TempDir() + + if err := WriteCscRsp(dir, []string{"0618"}); err != nil { + t.Fatalf("WriteCscRsp: %v", err) + } + + data, _ := os.ReadFile(filepath.Join(dir, "csc.rsp")) + expected := "-nowarn:0618\n" + if string(data) != expected { + t.Errorf("csc.rsp content: got %q, want %q", string(data), expected) + } +} + +func TestWriteCscRsp_Empty(t *testing.T) { + dir := t.TempDir() + + if err := WriteCscRsp(dir, nil); err != nil { + t.Fatalf("WriteCscRsp: %v", err) + } + + // Should not create file + if _, err := os.Stat(filepath.Join(dir, "csc.rsp")); !os.IsNotExist(err) { + t.Error("csc.rsp should not be created when no warnings specified") + } +} + +func TestWriteCscRspForAsmdefs(t *testing.T) { + dir := t.TempDir() + + // Create multiple asmdef files in different directories + runtimeDir := filepath.Join(dir, "Runtime") + editorDir := filepath.Join(dir, "Editor") + os.MkdirAll(runtimeDir, 0755) + os.MkdirAll(editorDir, 0755) + + os.WriteFile(filepath.Join(runtimeDir, "com.example.runtime.asmdef"), []byte("{}"), 0644) + os.WriteFile(filepath.Join(editorDir, "com.example.editor.asmdef"), []byte("{}"), 0644) + + if err := WriteCscRspForAsmdefs(dir, []string{"0618"}); err != nil { + t.Fatalf("WriteCscRspForAsmdefs: %v", err) + } + + // Both directories should have csc.rsp + for _, d := range []string{runtimeDir, editorDir} { + data, err := os.ReadFile(filepath.Join(d, "csc.rsp")) + if err != nil { + t.Errorf("csc.rsp not found in %s: %v", d, err) + continue + } + if string(data) != "-nowarn:0618\n" { + t.Errorf("csc.rsp in %s: got %q", d, string(data)) + } + } + + // Root dir should NOT have csc.rsp (no asmdef there) + if _, err := os.Stat(filepath.Join(dir, "csc.rsp")); !os.IsNotExist(err) { + t.Error("root dir should not have csc.rsp") + } +} + +func TestWriteCscRspForAsmdefs_Empty(t *testing.T) { + dir := t.TempDir() + os.WriteFile(filepath.Join(dir, "test.asmdef"), []byte("{}"), 0644) + + if err := WriteCscRspForAsmdefs(dir, nil); err != nil { + t.Fatalf("WriteCscRspForAsmdefs: %v", err) + } + + // No csc.rsp should be created + if _, err := os.Stat(filepath.Join(dir, "csc.rsp")); !os.IsNotExist(err) { + t.Error("csc.rsp should not be created when no warnings specified") + } +}