Skip to content

feat add repostitory information to the source info of twin#527

Merged
PTKu merged 5 commits into
devfrom
feat-add-repostitory-information-to-the-source-info-of-twin
Jun 3, 2026
Merged

feat add repostitory information to the source info of twin#527
PTKu merged 5 commits into
devfrom
feat-add-repostitory-information-to-the-source-info-of-twin

Conversation

@PTKu

@PTKu PTKu commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Generated twins now carry source provenance: each transpiled type's SourceFileAttribute path is repo-root-relative when the project sits in a git repository with an origin remote, otherwise src-relative (apax fallback / legacy).
  • Adds two assembly-level attributes — SourceRepository(url, commit, branch) (repo mode) and SourceLibrary(name, version) (apax mode). Exactly one is emitted per assembly, and its presence discriminates how the per-type path is rooted.
  • Detection uses LibGit2Sharp (innermost .git, so submodules resolve to their own repo; remote URL normalized to canonical credential-free https). Mode is selectable via ixc --source-origin auto|apax|off (default auto).
  • This repo has no CHANGELOG, so the description below is derived from commits + diff stat. Built strict-TDD (red→green→refactor); CompilerTests, CsTests, ixc.Tests and ConnectorTests all pass, and the three modes were verified end-to-end with a real ixc run.

Changes from CHANGELOG

No CHANGELOG.md in this repository — section omitted; see Commits and Diff stat.

Commits

feat

  • ace5c5c8 feat(provenance): add SourceRepository/SourceLibrary attrs + git URL normalizer
  • 6e91763f feat(provenance): add SourceOrigin model and resolution providers
  • 7e80145d feat(provenance): root per-type SourceFile path via resolved SourceOrigin
  • 0a13fb8c feat(provenance): emit assembly-level source-origin attribute
  • 0f872d42 feat(provenance): add --source-origin option and wire auto-detection default

Diff stat

 .../ICompilerOptions.cs                            |   8 ++
 .../src/AXSharp.Compiler/AXSharp.Compiler.csproj   |   3 +-
 .../src/AXSharp.Compiler/AXSharpConfig.cs          |  15 ++++
 .../src/AXSharp.Compiler/AXSharpProject.cs         |  40 ++++++++-
 .../SourceOrigin/ApaxSourceOriginProvider.cs       |  22 +++++
 .../SourceOrigin/GitSourceOriginProvider.cs        |  50 +++++++++++
 .../SourceOrigin/GitUrlNormalizer.cs               |  56 ++++++++++++
 .../SourceOrigin/ISourceOriginProvider.cs          |  18 ++++
 .../SourceOrigin/NoSourceOriginProvider.cs         |  18 ++++
 .../AXSharp.Compiler/SourceOrigin/SourceOrigin.cs  |  82 +++++++++++++++++
 .../SourceOrigin/SourceOriginEmitter.cs            |  36 ++++++++
 .../SourceOrigin/SourceOriginProviderFactory.cs    |  25 ++++++
 .../Helpers/SourceFileAttributeHelper.cs           |   7 +-
 .../Onliner/CsOnlinerSourceBuilder.cs              |  10 +--
 .../Plain/CsPlainSourceBuilder.cs                  |   6 +-
 src/AXSharp.compiler/src/ixc/Options.cs            |   4 +
 src/AXSharp.compiler/src/ixd/Options.cs            |   2 +
 src/AXSharp.compiler/src/ixr/Options.cs            |   2 +
 .../AssemblyAttributesEmissionTests.cs             | 100 +++++++++++++++++++++
 .../Cs/CompilerTestOptions.cs                      |   4 +
 .../SourceFileAttributeRepositoryModeTests.cs      |  88 ++++++++++++++++++
 .../AXSharp.CompilerTests.csproj                   |   1 +
 .../AXSharp.CompilerTests/CompilerTestOptions.cs   |   3 +
 .../AXSharp.CompilerTests/GitUrlNormalizerTests.cs |  45 ++++++++++
 .../SourceOrigin/ApaxSourceOriginProviderTests.cs  |  49 ++++++++++
 .../SourceOrigin/GitSourceOriginProviderTests.cs   |  83 +++++++++++++++++
 .../SourceOrigin/NoSourceOriginProviderTests.cs    |  34 +++++++
 .../SourceOriginProviderFactoryTests.cs            |  40 +++++++++
 .../SourceOrigin/TempAxProjectFixture.cs           |  45 ++++++++++
 .../tests/AXSharp.ixc.Tests/CliProgramTest.cs      |  11 ++-
… and 8 more files (3× integration AXSharp.config.json; SourceFileAttribute.cs;
SourceLibraryAttribute.cs + SourceRepositoryAttribute.cs + their two tests)
 38 files changed, 1056 insertions(+), 21 deletions(-)

Test plan

  • dotnet build of the compiler solution succeeds (LibGit2Sharp restores across target RIDs)
  • dotnet test green for AXSharp.CompilerTests, AXSharp.Compiler.CsTests, AXSharp.ixc.Tests, AXSharp.ConnectorTests
  • dotnet ixc regenerates a twin without errors on a git-tracked apax project → emits [assembly: AXSharp.Connector.SourceRepository(...)] + repo-root-relative SourceFileAttribute paths
  • dotnet ixc --source-origin apax → emits [assembly: AXSharp.Connector.SourceLibrary(name, version)] + src-relative paths
  • dotnet ixc --source-origin off → no assembly attribute file, src-relative paths (legacy output unchanged)

Generated by /pr-description-update. Last regenerated: 2026-06-02.

PTKu added 5 commits June 2, 2026 17:20
…normalizer

Increment 1 of repository-aware source provenance (TDD red->green).

- AXSharp.Connector.SourceRepositoryAttribute(url, commit, branch) and
  SourceLibraryAttribute(name, version), both [assembly]-scoped, single-use.
- AXSharp.Compiler.GitUrlNormalizer: SSH/scp/https remote -> canonical
  credential-free https, strips port/.git/trailing slash; blank -> empty;
  unrecognized input returned verbatim.
Increment 2 of repository-aware source provenance (TDD red->green).

- SourceOrigin + SourceOriginMode (Repository|Library|None) carrying the
  per-type path base folder plus repo/package identity.
- ISourceOriginProvider seam with ApaxSourceOriginProvider (apax name/version,
  src-rooted), NoSourceOriginProvider (legacy, no emission) and
  GitSourceOriginProvider (LibGit2Sharp; innermost repo + origin remote ->
  normalized https url, HEAD sha, branch/empty on detached; falls back to apax
  when no repo or no usable remote).
- Reference LibGit2Sharp (already pinned centrally) from the compiler and the
  compiler test project; temp-repo integration tests for the git provider.
…igin

Increment 3 of repository-aware source provenance (TDD red->green).

- AXSharpProject exposes a lazily-resolved SourceOrigin via an injectable
  ISourceOriginProvider (defaults to apax-mode for now; auto-detection is wired
  with the CLI option in a later increment).
- SourceFileAttributeHelper relativizes against SourceOrigin.BaseFolder instead
  of AxProject.SrcFolder, so repository mode yields repo-root-relative paths and
  apax mode keeps src-relative paths.
- Onliner/Plain builder call sites pass Project.SourceOrigin.

Existing src-relative goldens stay green; new tests cover repo-rooted emission.
Increment 4 of repository-aware source provenance (TDD red->green).

- SourceOriginEmitter renders the single [assembly: ...] declaration:
  SourceRepository(url, commit, branch) in repository mode, SourceLibrary(name,
  version) in library mode, nothing in None mode.
- AXSharpProject.Generate writes it once to .g/AssemblyAttributes.g.cs (picked
  up by the existing .g/** compile glob), after the per-file/Configurations
  emission. None mode writes no file (legacy behavior preserved).
…default

Increment 5 of repository-aware source provenance (TDD red->green).

- ICompilerOptions.SourceOrigin (auto|apax|off) implemented across ixc/ixr/ixd
  options, AXSharpConfig (persisted + OverridesFromCli) and test options.
- ixc gains --source-origin (default auto).
- SourceOriginProviderFactory maps the value to a provider; AXSharpProject uses
  it when no provider is injected (auto => git detection in real builds).
- Test options default to "off" (legacy: src-relative, no assembly attribute) so
  existing goldens/integration comparisons stay deterministic and repo-independent;
  provenance behavior is covered by explicit-provider tests. CLI generation tests
  bumped +1 file for the emitted .g/AssemblyAttributes.g.cs.
- SourceFileAttribute doc clarified: path base is repo-root in repository mode,
  otherwise src-folder (discriminated by the assembly-level attribute).
@PTKu PTKu merged commit 5b34378 into dev Jun 3, 2026
2 checks passed
@PTKu PTKu deleted the feat-add-repostitory-information-to-the-source-info-of-twin branch June 3, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant