Skip to content

Commit d0cb59f

Browse files
committed
The build tool will now also create the documentation for the created package with the help of doxygen
1 parent d351953 commit d0cb59f

4 files changed

Lines changed: 166 additions & 3 deletions

File tree

.nuke/build.schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"type": "boolean",
1111
"description": "Indicates to continue a previously failed build attempt"
1212
},
13+
"DoxygenBin": {
14+
"type": "string",
15+
"description": "The path of the doxygen bin directory (Default: C:\\Program Files\\doxygen\\bin)"
16+
},
1317
"Help": {
1418
"type": "boolean",
1519
"description": "Shows the help text for this build assembly"
@@ -35,6 +39,10 @@
3539
"VSCode"
3640
]
3741
},
42+
"NoDocs": {
43+
"type": "boolean",
44+
"description": "Sets that no docs should be created"
45+
},
3846
"NoLogo": {
3947
"type": "boolean",
4048
"description": "Disables displaying the NUKE logo"
@@ -65,6 +73,7 @@
6573
"type": "string",
6674
"enum": [
6775
"Compile",
76+
"Docs",
6877
"Info",
6978
"Pack",
7079
"Restore"
@@ -82,6 +91,7 @@
8291
"type": "string",
8392
"enum": [
8493
"Compile",
94+
"Docs",
8595
"Info",
8696
"Pack",
8797
"Restore"

src/build/Build.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
using System.IO;
2+
using Serilog;
13
using Nuke.Common;
24
using Nuke.Common.IO;
35
using Nuke.Common.ProjectModel;
46
using Nuke.Common.Tools.DotNet;
5-
using Serilog;
67

78
namespace BuildTool
89
{
@@ -13,13 +14,21 @@ class Build : NukeBuild
1314
[Parameter("Version of the package")]
1415
public readonly string Version = "0.0.0";
1516

17+
[Parameter("The path of the doxygen bin directory (Default: C:\\Program Files\\doxygen\\bin)")]
18+
public readonly string DoxygenBin = "C:\\Program Files\\doxygen\\bin";
19+
20+
[Parameter("Sets that no docs should be created")]
21+
public readonly bool NoDocs = false;
22+
1623
[Solution]
1724
public readonly Solution Solution;
1825

1926
// Allways set config to release, because build is intended for creating ready to ship packages
2027
private readonly Configuration _configuration = Configuration.Release;
2128

2229
private static AbsolutePath _packages => RootDirectory / "nuget" / "packages";
30+
private static AbsolutePath _doxygenWorkingDir => RootDirectory / "doxygen";
31+
private static AbsolutePath _doxyfile => _doxygenWorkingDir / "Doxyfile";
2332

2433
Target Info => _ => _
2534
.Unlisted()
@@ -54,6 +63,7 @@ class Build : NukeBuild
5463
Target Pack => _ => _
5564
.DependsOn(Info)
5665
.DependsOn(Compile)
66+
.Triggers(Docs)
5767
.Executes(() =>
5868
{
5969
DotNetTasks.DotNetPack(s => s
@@ -64,7 +74,43 @@ class Build : NukeBuild
6474
.SetVersion(Version)
6575
.SetFileVersion(Version)
6676
.SetAssemblyVersion(Version)
67-
.SetProperty("PackageReleaseNotes", "https://github.com/basicx-StrgV/WGet.NET/releases/tag/" + Version));
77+
.SetProperty("PackageReleaseNotes", $"https://github.com/basicx-StrgV/WGet.NET/releases/tag/{Version}"));
6878
});
79+
80+
Target Docs => _ => _
81+
.OnlyWhenDynamic(() => !NoDocs)
82+
.Executes(() =>
83+
{
84+
if (!Directory.Exists(DoxygenBin))
85+
{
86+
Assert.Fail($"The doxygen bin directory does not exist ({DoxygenBin})");
87+
}
88+
89+
if (!Directory.Exists(_doxygenWorkingDir))
90+
{
91+
Assert.Fail($"The doxygen process working directory does not exist ({_doxygenWorkingDir})");
92+
}
93+
94+
string doxygenExe = DoxygenBin + Path.DirectorySeparatorChar + "doxygen.exe";
95+
96+
if (!File.Exists(doxygenExe))
97+
{
98+
Assert.Fail($"The doxygen executable does not exist ({doxygenExe})");
99+
}
100+
101+
if (!File.Exists(_doxyfile))
102+
{
103+
Assert.Fail($"The doxyfile does not exist ({_doxyfile})");
104+
}
105+
106+
DoxygenHandler doxygen = new DoxygenHandler(_doxyfile, doxygenExe, _doxygenWorkingDir);
107+
108+
bool result = doxygen.GenerateDocs(Version);
109+
110+
if (!result)
111+
{
112+
Assert.Fail("Failed to generate docs");
113+
}
114+
});
69115
}
70116
}

src/build/DoxygenHandler.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using Serilog;
2+
using System;
3+
using System.IO;
4+
using System.Diagnostics;
5+
6+
namespace BuildTool
7+
{
8+
public class DoxygenHandler
9+
{
10+
private readonly string _doxyfile;
11+
private readonly string _doxygen;
12+
private readonly string _workingDir;
13+
14+
public DoxygenHandler(string doxyfile, string doxygen, string workingDir)
15+
{
16+
_doxyfile = doxyfile;
17+
_doxygen = doxygen;
18+
_workingDir = workingDir;
19+
}
20+
21+
public bool GenerateDocs(string projectVersion)
22+
{
23+
try
24+
{
25+
Log.Information("Updating doxyfile");
26+
27+
if (!UpdateDoxyfile(projectVersion))
28+
{
29+
Log.Error("Failed to update the doxyfile");
30+
return false;
31+
}
32+
33+
Log.Information("Executing doxygen");
34+
35+
int exitCode = ExecuteDoxygen();
36+
37+
if (exitCode != 0)
38+
{
39+
Log.Error("The doxygen process failed with the exit code \"{exitCode}\"", exitCode);
40+
return false;
41+
}
42+
}
43+
catch (Exception e)
44+
{
45+
Log.Error("Exception thrown on docs generation: {ex}", e);
46+
return false;
47+
}
48+
49+
return true;
50+
}
51+
52+
private bool UpdateDoxyfile(string projectVersion)
53+
{
54+
string[] doxyfileContent = File.ReadAllLines(_doxyfile);
55+
56+
for (int i = 0; i < doxyfileContent.Length; i++)
57+
{
58+
if (doxyfileContent[i].Trim().StartsWith("PROJECT_NUMBER"))
59+
{
60+
doxyfileContent[i] = $"PROJECT_NUMBER = {projectVersion}";
61+
62+
File.WriteAllLines(_doxyfile, doxyfileContent);
63+
64+
return true;
65+
}
66+
}
67+
68+
return false;
69+
}
70+
71+
private int ExecuteDoxygen()
72+
{
73+
ProcessStartInfo startInfo = new ProcessStartInfo()
74+
{
75+
FileName = _doxygen,
76+
Arguments = $"\"{_doxyfile}\"",
77+
WorkingDirectory = _workingDir,
78+
CreateNoWindow = true,
79+
WindowStyle = ProcessWindowStyle.Hidden,
80+
UseShellExecute = false,
81+
RedirectStandardOutput = true,
82+
};
83+
84+
Process doxygenProc = new Process();
85+
doxygenProc.StartInfo = startInfo;
86+
87+
doxygenProc.Start();
88+
89+
using (StreamReader output = doxygenProc.StandardOutput)
90+
{
91+
// Log the doxygen output
92+
Log.Information(output.ReadLine());
93+
}
94+
95+
// Wait for process exit with a timeout of 10 min
96+
doxygenProc.WaitForExit(600000);
97+
98+
if (!doxygenProc.HasExited)
99+
{
100+
// Kill the process if it has not exited at this point
101+
doxygenProc.Kill();
102+
}
103+
104+
return doxygenProc.ExitCode;
105+
}
106+
}
107+
}

src/build/_build.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6-
<RootNamespace></RootNamespace>
6+
<RootNamespace>BuildTool</RootNamespace>
77
<NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>
88
<NukeRootDirectory>..\..</NukeRootDirectory>
99
<NukeScriptDirectory>..</NukeScriptDirectory>

0 commit comments

Comments
 (0)