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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ here.**

### Fixed

- **C#: the two shared helpers now carry the `// <auto-generated/>` marker (#460).**
`DecimalWire[.<Namespace>].g.cs` and `MetaNetValidation[.<Namespace>].g.cs` were the only
emitted files without it, so a runner with no `GenStateDir` wrote them once and then logged
`refusing to overwrite hand-written file` on every later run, leaving a stale copy (and the
`@precision`/`@scale` input check inside it) behind. A copy already on disk has no marker, so
regenerating alone keeps refusing it: delete the existing `DecimalWire*.g.cs` and
`MetaNetValidation*.g.cs` files, then regenerate. The marker is the only change to the
helpers' text.
- The 1.1.0 entry's handler-code figure of 439 lines retired is corrected to about 460, as
measured in one adopter's pull request.

Expand Down
50 changes: 50 additions & 0 deletions server/csharp/MetaObjects.Codegen.Tests/DecimalWireTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,54 @@ public void Helpers_for_packages_bound_to_different_namespaces_get_distinct_file
Assert.Contains("MetaNetValidation.Acme.Shipping.g.cs", paths);
Compile(files);
}

[Fact]
public void Shared_helpers_carry_the_generated_marker_on_their_first_line()
{
var files = EmitFitness(out _);
var helpers = files.Where(f =>
f.Path.StartsWith("DecimalWire", StringComparison.Ordinal) ||
f.Path.StartsWith("MetaNetValidation", StringComparison.Ordinal)).ToList();
Assert.Contains(helpers, f => f.Path.StartsWith("DecimalWire", StringComparison.Ordinal));
Assert.Contains(helpers, f => f.Path.StartsWith("MetaNetValidation", StringComparison.Ordinal));
foreach (var f in helpers)
Assert.Equal(CodegenRunner.GeneratedMarker, f.Content.Split('\n')[0].Replace("// ", ""));
}

[Fact]
public void Rerun_without_a_state_dir_rewrites_the_helpers_in_every_namespace()
{
// #460: with no GenStateDir the runner falls back to the marker rule, and the helpers
// lacked the marker, so every run after the first refused to overwrite them.
var dir = Path.Combine(Path.GetTempPath(), "mo-helper-marker-" + Guid.NewGuid().ToString("N"));
try
{
var r = new MetaDataLoader().Load([
new InMemoryStringSource(TwoNamespaceModel, id: "billing.json"),
new InMemoryStringSource(SecondNamespaceModel, id: "shipping.json")]);
Assert.Empty(r.Errors);
var config = new GenConfig
{
OutDir = dir,
Namespace = "Acme",
PackageNamespaces = new() { ["acme::billing"] = "Acme.Billing", ["acme::shipping"] = "Acme.Shipping" },
};
string[] helpers =
[
"DecimalWire.Acme.Billing.g.cs", "DecimalWire.Acme.Shipping.g.cs",
"MetaNetValidation.Acme.Billing.g.cs", "MetaNetValidation.Acme.Shipping.g.cs",
];
CodegenRunner.Run(config, r.Root, [new EntityGenerator()]);
foreach (var h in helpers) File.WriteAllText(Path.Combine(dir, h), File.ReadAllText(Path.Combine(dir, h)) + "// stale\n");

var second = CodegenRunner.Run(config, r.Root, [new EntityGenerator()]);
Assert.DoesNotContain(second.Warnings, w => w.Contains("refusing to overwrite", StringComparison.Ordinal));
foreach (var h in helpers)
{
Assert.Contains(second.Files, f => f.Path == h && f.Status == "written");
Assert.DoesNotContain("// stale", File.ReadAllText(Path.Combine(dir, h)), StringComparison.Ordinal);
}
}
finally { try { Directory.Delete(dir, true); } catch { } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ private static void AppendNetConverterAttribute(StringBuilder sb, MetaField fiel
// the namespace swap. It lives HERE (not read from the HelperRuntime resource) so an
// ejected EntityGenerator stays self-contained, the way the MetaNetValidation text is.
private const string DecimalWireSourceTemplate = """
// <auto-generated/>
// DecimalWire — the wire form of a field.decimal (ADR-0019 Amendments 1 and 2, W1-W4).
//
// Output follows the project's `wire.decimals` setting (Amendment 2). Under `native`, the
Expand Down Expand Up @@ -1417,6 +1418,7 @@ private static void AppendDecimalConverterAttribute(StringBuilder sb, MetaField
private static EmittedFile EmitNetValidationFile(string ns, string fileName)
{
var sb = new StringBuilder();
sb.AppendLine("// <auto-generated/>");
sb.AppendLine("// Generated by MetaObjects entity-generator. Do not edit by hand.");
sb.AppendLine("#nullable enable");
sb.AppendLine("using System;");
Expand Down
1 change: 1 addition & 0 deletions server/csharp/MetaObjects.Codegen/Runtime/DecimalWire.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// <auto-generated/>
// DecimalWire — the wire form of a field.decimal (ADR-0019 Amendments 1 and 2, W1-W4).
//
// Output follows the project's `wire.decimals` setting (Amendment 2). Under `native`, the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// <auto-generated/>
// DecimalWire — the wire form of a field.decimal (ADR-0019 Amendments 1 and 2, W1-W4).
//
// Output follows the project's `wire.decimals` setting (Amendment 2). Under `native`, the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// <auto-generated/>
// Generated by MetaObjects entity-generator. Do not edit by hand.
#nullable enable
using System;
Expand Down
Loading