Skip to content

Commit 395303f

Browse files
committed
fix source generation race condition breaking builds
1 parent a8251cd commit 395303f

File tree

9 files changed

+278
-151
lines changed

9 files changed

+278
-151
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,4 @@ ASALocalRun/
329329
# MFractors (Xamarin productivity tool) working folder
330330
.mfractor/
331331
coverage
332+
CoverageReport
Lines changed: 5 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,10 @@
1-
using System.Text.Json;
2-
using System.Text.Json.Serialization;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
35
using System.Text.RegularExpressions;
46

5-
namespace HeaderParser;
6-
7-
class Program
8-
{
9-
static int Main(string[] args)
10-
{
11-
if (args.Length < 2)
12-
{
13-
Console.Error.WriteLine("Usage: HeaderParser <include-dir> <output-json>");
14-
Console.Error.WriteLine("Example: HeaderParser secp256k1/include Secp256k1.Net/Generated/secp256k1-api.json");
15-
return 1;
16-
}
17-
18-
var includeDir = args[0];
19-
var outputPath = args[1];
20-
21-
if (!Directory.Exists(includeDir))
22-
{
23-
Console.Error.WriteLine($"Error: Include directory not found: {includeDir}");
24-
return 1;
25-
}
26-
27-
var parser = new Secp256k1HeaderParser();
28-
var api = parser.ParseDirectory(includeDir);
29-
30-
var options = new JsonSerializerOptions
31-
{
32-
WriteIndented = true,
33-
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
34-
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
35-
};
36-
37-
var json = JsonSerializer.Serialize(api, options);
38-
39-
var outputDir = Path.GetDirectoryName(outputPath);
40-
if (!string.IsNullOrEmpty(outputDir) && !Directory.Exists(outputDir))
41-
{
42-
Directory.CreateDirectory(outputDir);
43-
}
44-
45-
File.WriteAllText(outputPath, json);
46-
47-
Console.WriteLine($"Generated {outputPath}");
48-
Console.WriteLine($" Functions: {api.Functions.Count}");
49-
Console.WriteLine($" Structs: {api.Structs.Count}");
50-
Console.WriteLine($" Function pointer types: {api.FunctionPointerTypes.Count}");
51-
Console.WriteLine($" Constants: {api.Constants.Count}");
52-
Console.WriteLine($" Global pointers: {api.GlobalPointers.Count}");
53-
54-
return 0;
55-
}
56-
}
57-
58-
public class Secp256k1Api
59-
{
60-
public string Version { get; set; } = "0.7.0";
61-
public string GeneratedAt { get; set; } = DateTime.UtcNow.ToString("O");
62-
public List<string> Headers { get; set; } = new();
63-
public List<StructDef> Structs { get; set; } = new();
64-
public List<FunctionPointerType> FunctionPointerTypes { get; set; } = new();
65-
public List<FunctionDef> Functions { get; set; } = new();
66-
public List<ConstantDef> Constants { get; set; } = new();
67-
public List<GlobalPointer> GlobalPointers { get; set; } = new();
68-
}
69-
70-
public class StructDef
71-
{
72-
public string Name { get; set; } = "";
73-
public int Size { get; set; }
74-
public string? Description { get; set; }
75-
}
76-
77-
public class FunctionPointerType
78-
{
79-
public string Name { get; set; } = "";
80-
public string ReturnType { get; set; } = "";
81-
public List<ParameterDef> Parameters { get; set; } = new();
82-
public string? Description { get; set; }
83-
}
84-
85-
public class FunctionDef
86-
{
87-
public string Name { get; set; } = "";
88-
public string ReturnType { get; set; } = "";
89-
public bool WarnUnusedResult { get; set; }
90-
public bool Deprecated { get; set; }
91-
public string? DeprecatedMessage { get; set; }
92-
public List<ParameterDef> Parameters { get; set; } = new();
93-
public string? Description { get; set; }
94-
public string? ReturnDescription { get; set; }
95-
public string? SourceHeader { get; set; }
96-
}
97-
98-
public class ParameterDef
99-
{
100-
public string Name { get; set; } = "";
101-
public string Type { get; set; } = "";
102-
public string? Direction { get; set; }
103-
public bool Nonnull { get; set; }
104-
public string? Description { get; set; }
105-
}
106-
107-
public class ConstantDef
108-
{
109-
public string Name { get; set; } = "";
110-
public string Value { get; set; } = "";
111-
public long? NumericValue { get; set; }
112-
public string? Description { get; set; }
113-
}
114-
115-
public class GlobalPointer
116-
{
117-
public string Name { get; set; } = "";
118-
public string Type { get; set; } = "";
119-
public bool IsConst { get; set; }
120-
public string? Description { get; set; }
121-
}
7+
namespace Secp256k1Net.InteropGen;
1228

1239
public partial class Secp256k1HeaderParser
12410
{

Secp256k1.Net.InteropGen/Models.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace Secp256k1Net.InteropGen;
45

56
public class Secp256k1Api
67
{
7-
public string Version { get; set; } = "";
8-
public string GeneratedAt { get; set; } = "";
8+
public string Version { get; set; } = "0.7.0";
9+
public string GeneratedAt { get; set; } = DateTime.UtcNow.ToString("O");
910
public List<string> Headers { get; set; } = new();
1011
public List<StructDef> Structs { get; set; } = new();
1112
public List<FunctionPointerType> FunctionPointerTypes { get; set; } = new();

0 commit comments

Comments
 (0)