-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As the scope of `update-config.csx` has grown, it has become more and more painful that it isn't in an actual project editable in an IDE, making it harder to update or debug. As it shares code with `binderator`, like reading and writing `config.json`, move the functionality into `binderator`. To help facilitate running this functionality, add new targets to `cake` for the various operations: * `update-config` Updates config.json to the latest versions found in Maven. * `bump-config` Increments the NuGet patch version of all packages in config.json. * `sort-config` Sorts config.json file using the canonical sort. * `published-config` Shows which NuGet package versions in config.json have been published to NuGet.org. Note these run the in-tree version of `binderator`, there is no need to install the .NET Global tool version to run these targets.
- Loading branch information
Showing
28 changed files
with
813 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Contains tasks for updating/modifying the config.json used by binderator | ||
|
||
var binderator_project = "util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Xamarin.AndroidBinderator.Tool.csproj"; | ||
var gps_config = "https://raw.githubusercontent.com/xamarin/GooglePlayServicesComponents/main/config.json"; | ||
|
||
// Updates config.json to the latest versions found in Maven | ||
Task ("update-config") | ||
.Does (() => | ||
{ | ||
var args = new ProcessArgumentBuilder () | ||
.Append ("update") | ||
.Append ("--config-file") | ||
.Append ("config.json") | ||
.Append ("--dependency-file") | ||
.Append (gps_config); | ||
DotNetRun (binderator_project, args); | ||
}); | ||
|
||
// Increments the NuGet patch version of all packages in config.json | ||
Task ("bump-config") | ||
.Does (() => | ||
{ | ||
var args = new ProcessArgumentBuilder () | ||
.Append ("bump") | ||
.Append ("--config-file") | ||
.Append ("config.json"); | ||
DotNetRun (binderator_project, args); | ||
}); | ||
|
||
// Sorts config.json file using the canonical sort | ||
Task ("sort-config") | ||
.Does (() => | ||
{ | ||
var args = new ProcessArgumentBuilder () | ||
.Append ("sort") | ||
.Append ("--config-file") | ||
.Append ("config.json"); | ||
DotNetRun (binderator_project, args); | ||
}); | ||
|
||
// Shows which NuGet package versions in config.json have been published to NuGet.org | ||
Task ("published-config") | ||
.Does (() => | ||
{ | ||
var args = new ProcessArgumentBuilder () | ||
.Append ("published") | ||
.Append ("--config-file") | ||
.Append ("config.json"); | ||
DotNetRun (binderator_project, args); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<Project> | ||
<!-- This Directory.Build.props is to prevent the one in the root from being used, | ||
which is tuned for building bindings packages. --> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....AndroidBinderator/Xamarin.AndroidBinderator.Tests/Xamarin.AndroidBinderator.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/BinderateCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.CommandLine; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using AndroidBinderator; | ||
using Newtonsoft.Json; | ||
|
||
namespace Xamarin.AndroidBinderator.Tool; | ||
|
||
static class BinderateCommand | ||
{ | ||
public static Command Build () | ||
{ | ||
var binderate_command = new Command ("binderate", "Run the binderator process."); | ||
|
||
var config_file_option = new Option<string []> (["--config-file", "-c", "-config="], "JSON config file(s)") { AllowMultipleArgumentsPerToken = true, IsRequired = true }; | ||
var base_dir_option = new Option<string?> (["--base-path", "-b", "-basepath="], "Default base path"); | ||
|
||
binderate_command.Add (config_file_option); | ||
binderate_command.Add (base_dir_option); | ||
|
||
binderate_command.SetHandler ( | ||
RunBinderateVerb, | ||
config_file_option, base_dir_option | ||
); | ||
|
||
return binderate_command; | ||
} | ||
|
||
public static async Task RunBinderateVerb (string [] configFiles, string? basePath) | ||
{ | ||
Console.WriteLine ("Arguments:"); | ||
|
||
foreach (var c in configFiles) | ||
Console.WriteLine ($"- Config File: {c}"); | ||
Console.WriteLine ($"- Default Base Path: {basePath}"); | ||
Console.WriteLine (); | ||
|
||
basePath ??= "AppDomain.CurrentDomain.BaseDirectory"; | ||
|
||
try { | ||
foreach (var config in configFiles) { | ||
var cfgs = JsonConvert.DeserializeObject<List<BindingConfig>> (File.ReadAllText (config)); | ||
|
||
foreach (var c in cfgs ?? []) { | ||
if (string.IsNullOrEmpty (c.BasePath)) | ||
c.BasePath = basePath; | ||
|
||
await Engine.BinderateAsync (c); | ||
} | ||
} | ||
} catch (AggregateException exc_a) { | ||
var sb = new StringBuilder (); | ||
|
||
sb.AppendLine (); | ||
sb.AppendLine ($"Dependency errors : {exc_a.InnerExceptions.Count}"); | ||
|
||
var i = 1; | ||
|
||
foreach (var exc in exc_a.InnerExceptions) { | ||
sb.AppendLine ($"{i}"); | ||
sb.AppendLine ($" {exc.ToString ()}"); | ||
i++; | ||
} | ||
|
||
Trace.WriteLine (sb.ToString ()); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/BumpCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.CommandLine; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AndroidBinderator; | ||
|
||
namespace Xamarin.AndroidBinderator.Tool; | ||
|
||
static class BumpCommand | ||
{ | ||
public static Command Build () | ||
{ | ||
var update_command = new Command ("bump", "Increments the NuGet patch version of all packages in a config.json file."); | ||
|
||
var config_file_option = new Option<string> (["--config-file", "-c", "-config="], "JSON config file") { IsRequired = true }; | ||
|
||
update_command.Add (config_file_option); | ||
|
||
update_command.SetHandler ( | ||
RunBumpCommand, | ||
config_file_option | ||
); | ||
|
||
return update_command; | ||
} | ||
|
||
static async Task RunBumpCommand (string configFile) | ||
{ | ||
var config = await BindingConfig.Load (configFile); | ||
|
||
foreach (var art in config.MavenArtifacts) { | ||
var version = ""; | ||
var release = ""; | ||
var revision = 0; | ||
|
||
var str = art.NugetVersion ?? string.Empty; | ||
|
||
if (str.Contains ('-')) { | ||
release = str.Substring (str.IndexOf ('-')); | ||
str = str.Substring (0, str.LastIndexOf ('-')); | ||
} | ||
|
||
var period_count = str.Count (c => c == '.'); | ||
|
||
if (period_count == 2) { | ||
version = str; | ||
revision = 1; | ||
} else if (period_count == 3) { | ||
version = str.Substring (0, str.LastIndexOf ('.')); | ||
revision = int.Parse (str.Substring (str.LastIndexOf ('.') + 1)); | ||
revision++; | ||
} | ||
|
||
art.NugetVersion = $"{version}.{revision}{release}"; | ||
} | ||
|
||
config.Save (configFile); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/LegacyCommandLine.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Mono.Options; | ||
|
||
namespace Xamarin.AndroidBinderator.Tool; | ||
|
||
class LegacyCommandLine | ||
{ | ||
public static async Task Run (string [] args) | ||
{ | ||
var configs = new List<string> (); | ||
string? basePath = null; | ||
var shouldShowHelp = false; | ||
|
||
// thses are the available options, not that they set the variables | ||
var options = new OptionSet { | ||
{ "c|config=", "JSON Config File.", configs.Add }, | ||
{ "b|basepath=", "Default Base Path.", (string b) => basePath= b }, | ||
{ "h|help", "show this message and exit", h => shouldShowHelp = h != null }, | ||
}; | ||
|
||
List<string> extra; | ||
|
||
try { | ||
// parse the command line | ||
extra = options.Parse (args); | ||
} catch (OptionException e) { | ||
// output some error message | ||
Console.Write ("android-binderator: "); | ||
Console.WriteLine (e.Message); | ||
Console.WriteLine ("Try `android-binderator --help' for more information."); | ||
return; | ||
} | ||
|
||
if (shouldShowHelp) { | ||
options.WriteOptionDescriptions (Console.Out); | ||
return; | ||
} | ||
|
||
await BinderateCommand.RunBinderateVerb (configs.ToArray (), basePath); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/PublishedCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.CommandLine; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AndroidBinderator; | ||
|
||
namespace Xamarin.AndroidBinderator.Tool; | ||
|
||
static class PublishedCommand | ||
{ | ||
public static Command Build () | ||
{ | ||
var update_command = new Command ("published", "Shows which NuGet package versions in a config.json have been published to NuGet.org."); | ||
|
||
var config_file_option = new Option<string> (["--config-file", "-c", "-config="], "JSON config file") { IsRequired = true }; | ||
|
||
update_command.Add (config_file_option); | ||
|
||
update_command.SetHandler ( | ||
RunPublishedCommand, | ||
config_file_option | ||
); | ||
|
||
return update_command; | ||
} | ||
|
||
static async Task RunPublishedCommand (string configFile) | ||
{ | ||
var config = await BindingConfig.Load (configFile); | ||
|
||
var column1 = "Package".PadRight (58); | ||
var column2 = "Version".PadRight (17); | ||
var column3 = "Status".PadRight (15); | ||
|
||
Console.WriteLine ($"| {column1} | {column2} | {column3} |"); | ||
Console.WriteLine ("|------------------------------------------------------------|-------------------|-----------------|"); | ||
|
||
foreach (var art in config.MavenArtifacts.Where (a => !a.DependencyOnly)) { | ||
if (art.NugetPackageId is null || art.NugetVersion is null) | ||
continue; | ||
|
||
var status = (await ConfigUpdater.DoesNuGetPackageAlreadyExist (art.NugetPackageId, art.NugetVersion)) ? "Published" : "Not Published"; | ||
Console.WriteLine ($"| {art.NugetPackageId.PadRight (58)} | {art.NugetVersion.PadRight (17)} | {status.PadRight (15)} |"); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Commands/SortCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.CommandLine; | ||
using System.Threading.Tasks; | ||
using AndroidBinderator; | ||
|
||
namespace Xamarin.AndroidBinderator.Tool; | ||
|
||
static class SortCommand | ||
{ | ||
public static Command Build () | ||
{ | ||
var update_command = new Command ("sort", "Sorts a config.json file using the canonical sort."); | ||
|
||
var config_file_option = new Option<string> (["--config-file", "-c", "-config="], "JSON config file") { IsRequired = true }; | ||
|
||
update_command.Add (config_file_option); | ||
|
||
update_command.SetHandler ( | ||
RunSortCommand, | ||
config_file_option | ||
); | ||
|
||
return update_command; | ||
} | ||
|
||
static async Task RunSortCommand (string configFile) | ||
{ | ||
// BindingConfig.Load automatically sorts the file, so we just need to write the file back to disk | ||
var config = await BindingConfig.Load (configFile); | ||
|
||
config.Save (configFile); | ||
} | ||
} |
Oops, something went wrong.