Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct formatting looks like it missed gofmt (the Exclude field is misaligned vs the rest of the struct). Please run gofmt on this file so the formatting is consistent and minimizes diffs/churn going forward.

Suggested change
Exclude []string `json:"exclude,omitempty"`
Exclude []string `json:"exclude,omitempty"`

Copilot uses AI. Check for mistakes.
SuppressWarnings []string `json:"suppressWarnings,omitempty"`
}

type Config struct {
Expand Down
8 changes: 8 additions & 0 deletions internal/packager/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions internal/packager/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions internal/unity/cscrsp.go
Original file line number Diff line number Diff line change
@@ -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)
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteCscRsp unconditionally overwrites csc.rsp if it already exists. For git-unity/archive Unity packages (or raw sources that already include a csc.rsp), this can clobber existing compiler response directives. Consider detecting an existing file and either merging/appending the -nowarn directive or skipping with a clear error/message so existing settings aren’t lost silently.

Suggested change
return os.WriteFile(filepath.Join(dir, "csc.rsp"), []byte(content), 0644)
path := filepath.Join(dir, "csc.rsp")
f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return err
}
defer f.Close()
_, err = f.WriteString(content)
return err

Copilot uses AI. Check for mistakes.
}

// 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() {
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteCscRspForAsmdefs currently swallows any filepath.Walk error by returning nil when err != nil. That can silently skip parts of the tree and report success even though csc.rsp files weren't written. Return err when it is non-nil so callers can fail fast and surface filesystem issues.

Suggested change
if err != nil || info.IsDir() {
if err != nil {
return err
}
if info.IsDir() {

Copilot uses AI. Check for mistakes.
return nil
}
if strings.HasSuffix(path, ".asmdef") {
dir := filepath.Dir(path)
if err := WriteCscRsp(dir, warnings); err != nil {
return err
}
}
return nil
})
}
100 changes: 100 additions & 0 deletions internal/unity/cscrsp_test.go
Original file line number Diff line number Diff line change
@@ -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"))
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.ReadFile error is ignored here (data, _ := ...). If the file read fails, the assertion error will be misleading. Please check err and t.Fatalf like the other tests in this package.

Suggested change
data, _ := os.ReadFile(filepath.Join(dir, "csc.rsp"))
data, err := os.ReadFile(filepath.Join(dir, "csc.rsp"))
if err != nil {
t.Fatalf("reading csc.rsp: %v", err)
}

Copilot uses AI. Check for mistakes.
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)
Comment on lines +60 to +61
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test setup ignores errors from os.MkdirAll. If directory creation fails, later assertions will fail in a harder-to-debug way. Please handle these errors (e.g., if err := os.MkdirAll(...); err != nil { t.Fatal(...) }).

Suggested change
os.MkdirAll(runtimeDir, 0755)
os.MkdirAll(editorDir, 0755)
if err := os.MkdirAll(runtimeDir, 0755); err != nil {
t.Fatalf("failed to create runtimeDir: %v", err)
}
if err := os.MkdirAll(editorDir, 0755); err != nil {
t.Fatalf("failed to create editorDir: %v", err)
}

Copilot uses AI. Check for mistakes.

os.WriteFile(filepath.Join(runtimeDir, "com.example.runtime.asmdef"), []byte("{}"), 0644)
os.WriteFile(filepath.Join(editorDir, "com.example.editor.asmdef"), []byte("{}"), 0644)

Comment on lines +63 to +65
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test setup ignores errors from os.WriteFile when creating the .asmdef fixtures. Please check the returned errors so failures are reported clearly and the test doesn't proceed with missing/partial inputs.

Copilot uses AI. Check for mistakes.
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)

Comment on lines +89 to +91
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test setup ignores the error from os.WriteFile here. Please check it and fail the test if writing the .asmdef fixture fails, to avoid false/unclear failures later in the test.

Copilot uses AI. Check for mistakes.
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")
}
}
Loading