Conversation
…arge translation units
When using `sharpie bind --header <file> --scope <dir>`, the --scope
argument was stored verbatim without path normalization. Since Clang
always reports declaration source locations as absolute paths, a
relative --scope value (e.g. `MyFramework.framework/Headers`) would
never match the absolute filename from `presumedLoc.FileName`,
causing IsInScope() to filter out every declaration and produce zero
output files — even though parsing succeeded.
Additionally, the StartsWith comparison in IsInScope() could produce
false positive matches when one directory name was a prefix of another
(e.g. scope `/tmp/scope` would incorrectly match files in
`/tmp/scopeextra/`).
Finally, when binding a very large number of Objective-C headers
(200+), ClangSharp can throw an ArgumentOutOfRangeException with
parameter name "handle" during AST traversal, due to cursor/type
handle misclassification in its managed wrapper layer. Sharpie caught
this exception but reported the raw, opaque message
("Specified argument was out of the range of valid values"), giving
users no guidance on how to work around the issue.
Changes:
1. Tools.cs: Normalize --scope paths to absolute via Path.GetFullPath()
when parsing CLI arguments, matching the behavior already used by
--framework mode (which calls Path.GetFullPath on SourceFramework
in ResolveFramework()).
2. ObjectiveCBinder.cs (IsInScope): Append a trailing directory
separator to scope directory paths before the StartsWith check,
so that `/tmp/scope/` does not falsely match `/tmp/scopeextra/`.
3. BindingResult.cs (ReportUnexpectedError): Detect the specific
ArgumentOutOfRangeException("handle") pattern from ClangSharp and
report an actionable error message that explains the root cause
(translation unit too complex) and suggests workarounds (bind fewer
headers, use --scope).
4. Tests: Added 5 new test cases:
- Scope_RelativePath: verifies relative --scope paths produce
correct output after normalization
- Scope_FiltersOutOfScopeDeclarations: verifies that only
declarations from in-scope headers are bound
- Scope_PrefixDoesNotFalseMatch: verifies that scope "/foo/bar"
does not match "/foo/barbaz/header.h"
- HandleCrash_ReportsUsefulError: verifies the improved error
message for ClangSharp handle exceptions
- HandleCrash_OtherExceptionsUnchanged: verifies that other
exception types still report their original message
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #5b6ffb2] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #5b6ffb2] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #5b6ffb2] Build passed (Build macOS tests) ✅Pipeline on Agent |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #5b6ffb2] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 156 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. [attempt 5] Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. [attempt 2] Html Report (VSDrops) Download Pipeline on Agent |
When using
sharpie bind --header <file> --scope <dir>, the --scope argument was stored verbatim without path normalization. Since Clang always reports declaration source locations as absolute paths, a relative --scope value (e.g.MyFramework.framework/Headers) would never match the absolute filename frompresumedLoc.FileName, causing IsInScope() to filter out every declaration and produce zero output files — even though parsing succeeded.Additionally, the StartsWith comparison in IsInScope() could produce false positive matches when one directory name was a prefix of another (e.g. scope
/tmp/scopewould incorrectly match files in/tmp/scopeextra/).Finally, when binding a very large number of Objective-C headers (200+), ClangSharp can throw an ArgumentOutOfRangeException with parameter name "handle" during AST traversal, due to cursor/type handle misclassification in its managed wrapper layer. Sharpie caught this exception but reported the raw, opaque message ("Specified argument was out of the range of valid values"), giving users no guidance on how to work around the issue.-> Moved to dotnet/ClangSharp#690Changes:
Tools.cs: Normalize --scope paths to absolute via Path.GetFullPath() when parsing CLI arguments, matching the behavior already used by --framework mode (which calls Path.GetFullPath on SourceFramework in ResolveFramework()).
ObjectiveCBinder.cs (IsInScope): Append a trailing directory separator to scope directory paths before the StartsWith check, so that
/tmp/scope/does not falsely match/tmp/scopeextra/.3. BindingResult.cs (ReportUnexpectedError): Detect the specific ArgumentOutOfRangeException("handle") pattern from ClangSharp and report an actionable error message that explains the root cause (translation unit too complex) and suggests workarounds (bind fewer headers, use --scope).HandleCrash_ReportsUsefulError: verifies the improved error message for ClangSharp handle exceptionsHandleCrash_OtherExceptionsUnchanged: verifies that other exception types still report their original message