Add suppressWarnings option for per-package csc.rsp generation#4
Add suppressWarnings option for per-package csc.rsp generation#4
Conversation
Generates csc.rsp files with -nowarn directives next to .asmdef files. For git-raw/archive-raw packages, placed next to the generated asmdef. For git-unity/archive-unity packages, discovers all existing asmdefs and places csc.rsp next to each one. Example config: "suppressWarnings": ["0618", "0649"] Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a per-package suppressWarnings configuration option to generate Unity csc.rsp files containing -nowarn directives, and wires it into git/archive packaging flows so warning suppressions can be applied per generated/copied .asmdef.
Changes:
- Introduces
internal/unityhelpers to writecsc.rspand to discover.asmdeffiles and placecsc.rspalongside them. - Adds
suppressWarningstoconfig.PackageSpecand integratescsc.rspgeneration intogitandarchivepackager paths. - Adds unit tests covering
csc.rspcontent and multi-asmdef placement behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/unity/cscrsp.go | New helpers for writing csc.rsp and walking for .asmdef files. |
| internal/unity/cscrsp_test.go | New unit tests for csc.rsp creation and placement. |
| internal/packager/git.go | Hooks suppressWarnings into git packaging flows. |
| internal/packager/archive.go | Hooks suppressWarnings into archive packaging flows. |
| internal/config/config.go | Adds suppressWarnings to the package spec JSON schema. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| os.MkdirAll(runtimeDir, 0755) | ||
| os.MkdirAll(editorDir, 0755) |
There was a problem hiding this comment.
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(...) }).
| 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) | |
| } |
| os.WriteFile(filepath.Join(runtimeDir, "com.example.runtime.asmdef"), []byte("{}"), 0644) | ||
| os.WriteFile(filepath.Join(editorDir, "com.example.editor.asmdef"), []byte("{}"), 0644) | ||
|
|
There was a problem hiding this comment.
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.
| dir := t.TempDir() | ||
| os.WriteFile(filepath.Join(dir, "test.asmdef"), []byte("{}"), 0644) | ||
|
|
There was a problem hiding this comment.
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.
| return nil | ||
| } | ||
| content := "-nowarn:" + strings.Join(warnings, ",") + "\n" | ||
| return os.WriteFile(filepath.Join(dir, "csc.rsp"), []byte(content), 0644) |
There was a problem hiding this comment.
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.
| 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 |
| return nil | ||
| } | ||
| return filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error { | ||
| if err != nil || info.IsDir() { |
There was a problem hiding this comment.
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.
| if err != nil || info.IsDir() { | |
| if err != nil { | |
| return err | |
| } | |
| if info.IsDir() { |
| NuGetVersion string `json:"nugetVersion,omitempty"` | ||
| NuGetFramework string `json:"nugetFramework,omitempty"` | ||
| Exclude []string `json:"exclude,omitempty"` | ||
| Exclude []string `json:"exclude,omitempty"` |
There was a problem hiding this comment.
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.
| Exclude []string `json:"exclude,omitempty"` | |
| Exclude []string `json:"exclude,omitempty"` |
| t.Fatalf("WriteCscRsp: %v", err) | ||
| } | ||
|
|
||
| data, _ := os.ReadFile(filepath.Join(dir, "csc.rsp")) |
There was a problem hiding this comment.
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.
| 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) | |
| } |
Summary
suppressWarningsconfig field generatescsc.rspfiles with-nowarndirectives.asmdeffiles (git-unity, archive-unity): discovers all asmdefs and placescsc.rspnext to each.asmdef(git-raw, archive-raw): placescsc.rspnext to the generated asmdef inRuntime/suppressWarningsis empty or omittedExample usage:
{ "name": "com.google.protobuf", "type": "git-raw", "suppressWarnings": ["0618", "0649"] }Test plan
TestWriteCscRsp— single and multiple warnings, empty list produces no fileTestWriteCscRspForAsmdefs— discovers multiple asmdefs, places csc.rsp next to each🤖 Generated with Claude Code