Skip to content

Commit

Permalink
[C#] Test package override support compiles.
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Bradac <nate.bradac@weareadaptive.com>

We've updated the C# generation tasks to include a schema that uses
explicit package names on `types` blocks.

We found processing this schema produces some build errors (albeit not
affecting the exit code):

```
> Task :generateCSharpTestCodecs
[Error] explicit-package-test-schema.xml:17:49: cvc-complex-type.3.2.2: Attribute 'package' is not allowed to appear in element 'types'.
[Error] explicit-package-test-schema.xml:30:37: cvc-complex-type.3.2.2: Attribute 'package' is not allowed to appear in element 'types'.

> Task :generateCSharpTestDtos
[Error] explicit-package-test-schema.xml:17:49: cvc-complex-type.3.2.2: Attribute 'package' is not allowed to appear in element 'types'.
[Error] explicit-package-test-schema.xml:30:37: cvc-complex-type.3.2.2: Attribute 'package' is not allowed to appear in element 'types'.
```

Therefore, we've put the new generation under tasks that don't validate
against an XSD. We considered creating a new version of the XSD that
properly describes what we support; however, the licence on the XSD
seems prohibitive.
  • Loading branch information
ZachBray committed Nov 15, 2024
1 parent 4a31cc0 commit ea52edd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ csharp/sbe-generated/since-deprecated
csharp/sbe-generated/order_check
csharp/sbe-generated/mktdata/*.cs
csharp/sbe-generated/uk_co_real_logic_sbe_benchmarks_fix
csharp/sbe-generated/test_message_schema
csharp/sbe-tests/*.sbe
csharp/nuget/
csharp/csharp.sln.DotSettings.user
Expand Down
33 changes: 30 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,8 @@ tasks.register('generateCSharpTestCodecs', JavaExec) {
'sbe.target.language': 'uk.co.real_logic.sbe.generation.csharp.CSharp',
'sbe.xinclude.aware': 'true',
'sbe.validation.xsd': validationXsdPath,
'sbe.generate.precedence.checks': 'true')
'sbe.generate.precedence.checks': 'true',
'sbe.types.package.override': 'true')
args = ['sbe-tool/src/test/resources/FixBinary.xml',
'sbe-tool/src/test/resources/issue435.xml',
'sbe-tool/src/test/resources/issue483.xml',
Expand All @@ -912,15 +913,41 @@ tasks.register('generateCSharpTestDtos', JavaExec) {
'sbe.output.dir': 'csharp/sbe-generated',
'sbe.target.language': 'uk.co.real_logic.sbe.generation.csharp.CSharpDtos',
'sbe.xinclude.aware': 'true',
'sbe.validation.xsd': validationXsdPath)
'sbe.validation.xsd': validationXsdPath,
'sbe.types.package.override': 'true')
args = ['sbe-samples/src/main/resources/example-extension-schema.xml']
}

tasks.register('generateCSharpExplicitPackageOverrideCodecs', JavaExec) {
mainClass.set('uk.co.real_logic.sbe.SbeTool')
classpath = project(':sbe-tool').sourceSets.main.runtimeClasspath
systemProperties(
'sbe.output.dir': 'csharp/sbe-generated',
'sbe.target.language': 'uk.co.real_logic.sbe.generation.csharp.CSharp',
'sbe.xinclude.aware': 'true',
'sbe.generate.precedence.checks': 'true',
'sbe.types.package.override': 'true')
args = ['sbe-tool/src/test/resources/explicit-package-test-schema.xml']
}

tasks.register('generateCSharpExplicitPackageOverrideDtos', JavaExec) {
mainClass.set('uk.co.real_logic.sbe.SbeTool')
classpath = project(':sbe-tool').sourceSets.main.runtimeClasspath
systemProperties(
'sbe.output.dir': 'csharp/sbe-generated',
'sbe.target.language': 'uk.co.real_logic.sbe.generation.csharp.CSharpDtos',
'sbe.xinclude.aware': 'true',
'sbe.types.package.override': 'true')
args = ['sbe-tool/src/test/resources/explicit-package-test-schema.xml']
}

tasks.register('generateCSharpCodecs') {
description = 'Generate csharp codecs'
dependsOn 'generateCSharpTestCodecs',
'generateCSharpTestDtos',
'generateCSharpCodecsWithXIncludes'
'generateCSharpCodecsWithXIncludes',
'generateCSharpExplicitPackageOverrideCodecs',
'generateCSharpExplicitPackageOverrideDtos'
}

tasks.register('generateJavaIrCodecs', JavaExec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import uk.co.real_logic.sbe.generation.TargetCodeGenerator;
import uk.co.real_logic.sbe.ir.Ir;

import static uk.co.real_logic.sbe.SbeTool.TYPES_PACKAGE_OVERRIDE;

/**
* {@link CodeGenerator} factory for CSharp DTOs.
*/
Expand All @@ -30,6 +32,11 @@ public class CSharpDtos implements TargetCodeGenerator
*/
public CodeGenerator newInstance(final Ir ir, final String outputDir)
{
return new CSharpDtoGenerator(ir, false, new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace()));
final boolean shouldSupportTypesPackageNames = Boolean.getBoolean(TYPES_PACKAGE_OVERRIDE);
return new CSharpDtoGenerator(
ir,
shouldSupportTypesPackageNames,
new CSharpNamespaceOutputManager(outputDir, ir.applicableNamespace())
);
}
}

0 comments on commit ea52edd

Please sign in to comment.