Skip to content

Commit

Permalink
[build.cake] Break up into multiple files and remove obsolete targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Oct 17, 2024
1 parent d044e5d commit 74a8581
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 347 deletions.
321 changes: 1 addition & 320 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#load "build/cake/tests.cake"
#load "build/cake/gps-parameters.cake"
#load "build/cake/dotnet-next.cake"
#load "build/cake/binderate.cake"

using System.Text.RegularExpressions;
using System.Xml;
Expand Down Expand Up @@ -216,36 +217,6 @@ Task("inject-variables")
ReplaceTextInFiles(glob, "{BUILD_TIMESTAMP}", BUILD_TIMESTAMP);
});

Task("check-tools")
.Does(() =>
{
var installedTools = RunProcessWithOutput("dotnet", "tool list -g");
foreach (var toolName in REQUIRED_DOTNET_TOOLS) {
if (installedTools.All(l => l.IndexOf(toolName, StringComparison.OrdinalIgnoreCase) == -1))
throw new Exception ($"Missing dotnet tool: {toolName}");
}
});


Task("tools-update")
.Does
(
() =>
{
/*
dotnet tool uninstall -g Cake.Tool
dotnet tool install -g Cake.Tool
dotnet tool uninstall -g xamarin.androidbinderator.tool
dotnet tool install -g xamarin.androidbinderator.tool
StartProcess("dotnet", "tool uninstall -g Cake.Tool");
StartProcess("dotnet", "tool install -g Cake.Tool");
*/
StartProcess("dotnet", "tool uninstall -g xamarin.androidbinderator.tool");
StartProcess("dotnet", "tool install -g xamarin.androidbinderator.tool");
}
);

// Android X

Task("javadocs")
Expand All @@ -272,295 +243,6 @@ Task("javadocs")
}
});

Task ("binderate")
.IsDependentOn("javadocs-gps")
.IsDependentOn("binderate-config-verify")
.Does (() =>
{
var configFile = MakeAbsolute(new FilePath("./config.json")).FullPath;
var basePath = MakeAbsolute(new DirectoryPath ("./")).FullPath;
// Run the binderator project
var args = new ProcessArgumentBuilder ()
.Append ("binderate")
.Append ("--config-file")
.Append (configFile)
.Append ("--base-path")
.Append (basePath);
DotNetRun (binderator_project, args);
// format the targets file so they are pretty in the package
var targetsFiles = GetFiles("generated/**/*.targets");
var xmlns = (XNamespace)"http://schemas.microsoft.com/developer/msbuild/2003";
foreach (var targets in targetsFiles) {
var xdoc = XDocument.Load(targets.FullPath);
xdoc.Save(targets.FullPath);
}
// different lint.jar files in artifacts causing R8 errors
foreach (var file in GetFiles("./externals/**/lint.jar")) {
Information($"Deleting: {file}");
DeleteFile(file);
foreach (var aar in GetFiles($"{file.GetDirectory()}/../*.aar")) {
Information($"Deleting: lint.jar from {aar}");
using (var zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile(aar.ToString())) {
zipFile.BeginUpdate();
var entry = zipFile.GetEntry("lint.jar");
if (entry != null) {
Information($" Deleting lint.jar from {aar}");
zipFile.Delete(entry);
}
zipFile.CommitUpdate();
}
}
}
});

string version_suffix = "";
string nuget_version_template = $"x.y.z.w{version_suffix}";
JArray binderator_json_array = null;

Task("binderate-config-verify")
.IsDependentOn("binderate-fix")
.Does
(
() =>
{
if (!(binderator_json_array?.Count > 0))
{
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
}
Information("config.json verification...");
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
bool? dependency_only = (bool?) jo["dependencyOnly"];
if ( dependency_only == true)
{
continue;
}
string artifact_version = (string) jo["version"];
string nuget_version = (string) jo["nugetVersion"];
string[] artifact_version_parts = artifact_version.Split(new string[]{ "-" }, StringSplitOptions.RemoveEmptyEntries);
string[] nuget_version_parts = nuget_version.Split(new string[]{ "-" }, StringSplitOptions.RemoveEmptyEntries);
string nuget_version_prefix = nuget_version_parts[0];
string artifact_version_prefix = artifact_version_parts[0];
string nuget_version_suffix = null;
string artifact_version_suffix = null;
if (nuget_version_parts.Length > 1)
{
nuget_version_suffix = nuget_version_parts[1];
}
if (artifact_version_parts.Length > 1)
{
artifact_version_suffix = artifact_version_parts[1];
}
//Information($"groupId = {jo["groupId"]}");
//Information($"artifactId = {jo["artifactId"]}");
//Information($"artifact_version = {artifact_version}");
//Information($"artifact_version_prefix = {artifact_version_prefix}");
//Information($"artifact_version_suffix = {artifact_version_suffix}");
//Information($"nuget_version = {nuget_version}");
//Information($"nuget_version_prefix = {nuget_version_prefix}");
//Information($"nuget_version_suffix = {nuget_version_suffix}");
//Information($"nugetId = {jo["nugetId"]}");
string[] artifact_version_prefix_parts = artifact_version_prefix.Split(new string[]{ "." }, StringSplitOptions.RemoveEmptyEntries);
string[] nuget_version_prefix_parts = nuget_version_prefix.Split(new string[]{ "." }, StringSplitOptions.RemoveEmptyEntries);
string x = nuget_version_prefix_parts[0];
string y = nuget_version_prefix_parts[1];
string z = nuget_version_prefix_parts[2];
string w = null;
if (nuget_version_prefix_parts.Length > 3)
{
w = nuget_version_prefix_parts[3];
}
string nuget_version_new = nuget_version_template;
nuget_version_new = nuget_version_new.Replace("x", x);
nuget_version_new = nuget_version_new.Replace("y", y);
nuget_version_new = nuget_version_new.Replace("z", z);
nuget_version_new = nuget_version_new.Replace("w", w);
if ( ! string.IsNullOrEmpty(nuget_version_suffix) )
{
nuget_version_new += $"-{nuget_version_suffix}";
}
//Information($"nuget_version_new = {nuget_version_new}");
if
(
! nuget_version_new.StartsWith($"{artifact_version_prefix}")
&&
! nuget_version_new.EndsWith($"{artifact_version_suffix}")
)
{
Error("check config.json for nuget id");
Error ($" groupId = {jo["groupId"]}");
Error ($" artifactId = {jo["artifactId"]}");
Error ($" artifact_version = {artifact_version}");
Error ($" nuget_version = {nuget_version}");
Error ($" nuget_version_new = {nuget_version_new}");
Error ($" nugetId = {jo["nugetId"]}");
Warning($" expected : ");
Warning($" nuget_version = {nuget_version_new}");
throw new Exception("check config.json for nuget id");
}
}
return;
}
);

Task("binderate-diff")
.IsDependentOn("binderate")
.Does
(
() =>
{
EnsureDirectoryExists("./output/");
// "git diff master:config.json config.json" > ./output/config.json.diff-from-master.txt"
string process = "git";
string process_args = "diff master:config.json config.json";
IEnumerable<string> redirectedStandardOutput;
ProcessSettings process_settings = new ProcessSettings ()
{
Arguments = process_args,
RedirectStandardOutput = true
};
int exitCodeWithoutArguments = StartProcess(process, process_settings, out redirectedStandardOutput);
System.IO.File.WriteAllLines("./output/config.json.diff-from-master.txt", redirectedStandardOutput.ToArray());
Information("Exit code: {0}", exitCodeWithoutArguments);
}
);

Task("binderate-fix")
.Does
(
() =>
{
if (!(binderator_json_array?.Count > 0))
{
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
}
Warning("config.json fixing missing folder strucutre ...");
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
string groupId = (string) jo["groupId"];
string artifactId = (string) jo["artifactId"];
//Information($" Verifying files for :");
//Information($" group : {groupId}");
//Information($" artifact : {artifactId}");
bool? dependency_only = (bool?) jo["dependencyOnly"];
if ( dependency_only == true)
{
continue;
}
string dir_group = $"source/{groupId}";
if ( ! DirectoryExists(dir_group) )
{
Warning($" Creating {dir_group}");
CreateDirectory(dir_group);
}
string dir_artifact = $"{dir_group}/artifactId";
if ( ! DirectoryExists(dir_group) )
{
Warning($" Creating artifact folder : {dir_artifact}");
CreateDirectory(dir_group);
}
}
return;
}
);


// using System.Threading;
// using Microsoft.Extensions.Logging;
// using Microsoft.Extensions.Logging.Abstractions;

// using NuGet.Protocol.Core.Types;
// using NuGet.Versioning;
// using NuGet.Protocol.Core.Types;

Task("binderate-nuget-check")
.Does
(
() =>
{
if (!(binderator_json_array?.Count > 0))
{
using (StreamReader reader = System.IO.File.OpenText(@"./config.json"))
{
JsonTextReader jtr = new JsonTextReader(reader);
binderator_json_array = (JArray)JToken.ReadFrom(jtr);
}
}
Warning("config.json fixing missing folder structure ...");
foreach(JObject jo in binderator_json_array[0]["artifacts"])
{
string groupId = (string) jo["groupId"];
string artifactId = (string) jo["artifactId"];
string nugetId = (string) jo["nugetId"];
string nugetVersion = (string) jo["nugetVersion"];
Information($" Verifying nuget :");
Information($" nugetId : {nugetId}");
Information($" config.json veriosn : {nugetVersion}");
// ILogger logger = NullLogger.Instance;
// CancellationToken cancellationToken = CancellationToken.None;
// SourceCacheContext cache = new SourceCacheContext();
// SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
// FindPackageByIdResource resource = await repository.GetResourceAsync<FindPackageByIdResource>().Result;
// IEnumerable<NuGetVersion> versions = resource.GetAllVersionsAsync
// (
// nugetId,
// cache,
// logger,
// cancellationToken
// ).Result;
// foreach (NuGetVersion version in versions)
// {
// Information($" Found version {version}");
// }
}
return;
}
);


System.Xml.XmlDocument xmldoc = null;
System.Xml.XmlNamespaceManager ns = null;

Expand Down Expand Up @@ -930,7 +612,6 @@ Task ("ci")

// Builds packages but does not run samples
Task ("ci-build")
.IsDependentOn ("check-tools")
.IsDependentOn ("inject-variables")
.IsDependentOn ("binderate")
.IsDependentOn ("nuget")
Expand Down
47 changes: 47 additions & 0 deletions build/cake/binderate.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Contains tasks for running binderator

// Runs `binderator`
Task ("binderate")
.IsDependentOn ("javadocs-gps")
.Does (() =>
{
var configFile = MakeAbsolute (new FilePath ("./config.json")).FullPath;
var basePath = MakeAbsolute (new DirectoryPath ("./")).FullPath;
// Run the binderator project
var args = new ProcessArgumentBuilder ()
.Append ("binderate")
.Append ("--config-file")
.Append (configFile)
.Append ("--base-path")
.Append (basePath);
DotNetRun (binderator_project, args);
// format the targets file so they are pretty in the package
var targetsFiles = GetFiles ("generated/**/*.targets");
var xmlns = (XNamespace)"http://schemas.microsoft.com/developer/msbuild/2003";
foreach (var targets in targetsFiles) {
var xdoc = XDocument.Load (targets.FullPath);
xdoc.Save (targets.FullPath);
}
// different lint.jar files in artifacts causing R8 errors
foreach (var file in GetFiles ("./externals/**/lint.jar")) {
Information($"Deleting: {file}");
DeleteFile(file);
foreach (var aar in GetFiles ($"{file.GetDirectory ()}/../*.aar")) {
Information ($"Deleting: lint.jar from {aar}");
using (var zipFile = new ICSharpCode.SharpZipLib.Zip.ZipFile (aar.ToString ())) {
zipFile.BeginUpdate ();
var entry = zipFile.GetEntry ("lint.jar");
if (entry != null) {
Information ($" Deleting lint.jar from {aar}");
zipFile.Delete (entry);
}
zipFile.CommitUpdate ();
}
}
}
});
Loading

0 comments on commit 74a8581

Please sign in to comment.