Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build.cake] Break up into multiple files and remove obsolete targets. #1017

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
899 changes: 12 additions & 887 deletions build.cake

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions build/cake/binderate.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Contains tasks for running binderator

var binderator_project = "util/Xamarin.AndroidBinderator/Xamarin.AndroidBinderator.Tool/Xamarin.AndroidBinderator.Tool.csproj";

// 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 ();
}
}
}
});
105 changes: 105 additions & 0 deletions build/cake/build-and-package.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Contains tasks for building and packaging projects

// Builds the NuGet packages
Task ("nuget")
.IsDependentOn ("libs")
.Does (() =>
{
var settings = new DotNetMSBuildSettings ()
.SetConfiguration (CONFIGURATION)
.EnableBinaryLogger ($"./output/nuget.{CONFIGURATION}.binlog")
.WithProperty ("NoBuild", "true")
.WithProperty ("PackageOutputPath", MakeAbsolute ((DirectoryPath)"./output/").FullPath)
.WithTarget ("Pack");

DotNetBuild (
"./generated/AndroidX.sln",
new DotNetBuildSettings { MSBuildSettings = settings }
);
});

// Builds the .csproj projects
Task ("libs")
.IsDependentOn("metadata-verify")
.IsDependentOn ("libs-native")
.Does(() =>
{
var settings = new DotNetMSBuildSettings ()
.SetConfiguration (CONFIGURATION)
.EnableBinaryLogger ($"./output/libs.{CONFIGURATION}.binlog")
.WithProperty("Verbosity", VERBOSITY.ToString ());

DotNetBuild (
"./generated/AndroidX.sln",
new DotNetBuildSettings { MSBuildSettings = settings }
);
});

// Builds the Java libraries
Task ("libs-native")
.Does (() =>
{
// com.xamarin.google.android.material.extensions
BuildGradleProject (
"./source/com.google.android.material/material.extensions/",
"./externals/com.xamarin.google.android.material.extensions/",
false
);

// com.google.android.play/core.extensions
BuildGradleProject (
"./source/com.google.android.play/core.extensions/",
"./externals/com.xamarin.google.android.play.core.extensions/",
true
);

// com.google.android.play/asset.delivery.extensions
BuildGradleProject (
"./source/com.google.android.play/asset.delivery.extensions/",
"./externals/com.xamarin.google.android.play.asset.delivery.extensions/",
true
);

// com.google.android.play/feature.delivery.extensions
BuildGradleProject (
"./source/com.google.android.play/feature.delivery.extensions/",
"./externals/com.xamarin.google.android.play.feature.delivery.extensions/",
true
);
});

void BuildGradleProject (string root, string outputDir, bool moveFile)
{
RunGradle (root, "build");

EnsureDirectoryExists (outputDir);
CleanDirectories (outputDir);

var full_file_path = $"{root}/extensions-aar/build/outputs/aar/extensions-aar-release.aar";
var file_name = System.IO.Path.GetFileName (full_file_path);

CopyFileToDirectory (full_file_path, outputDir);
Unzip($"{outputDir}/{file_name}", outputDir);

if (moveFile)
MoveFile ($"{outputDir}/classes.jar", $"{outputDir}/extensions.jar");
}

void RunGradle (DirectoryPath root, string target)
{
root = MakeAbsolute (root);

var proc = IsRunningOnWindows ()
? root.CombineWithFilePath ("gradlew.bat").FullPath
: "bash";
var args = IsRunningOnWindows ()
? ""
: root.CombineWithFilePath ("gradlew").FullPath;

args += $" {target} -p {root}";

var exitCode = StartProcess (proc, args);

if (exitCode != 0)
throw new Exception ($"Gradle exited with code {exitCode}.");
}
12 changes: 12 additions & 0 deletions build/cake/clean.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Clean up the output directories
Task ("clean")
.Does (() =>
{
if (DirectoryExists ("./externals"))
DeleteDirectory ("./externals", new DeleteDirectorySettings { Recursive = true, Force = true });

if (DirectoryExists ("./generated"))
DeleteDirectory ("./generated", new DeleteDirectorySettings { Recursive = true, Force = true });

CleanDirectories ("./**/packages");
});
12 changes: 12 additions & 0 deletions build/cake/executive-order.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Forward to running 'tools-executive-order' in 'utilities.cake'
Task("tools-executive-order")
.Does (() =>
{
CakeExecuteScript (
"./utilities.cake",
new CakeSettings { Arguments = new Dictionary<string, string> () {
{ "target", "tools-executive-order" }
}
}
);
});
18 changes: 9 additions & 9 deletions build/cake/gps-parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ Task ("javadocs-gps")

return;

var astJar = new FilePath ("./util/JavaASTParameterNames-1.0.jar");
var sourcesJars = GetFiles ("./externals/**/*-sources.jar");
//var astJar = new FilePath ("./util/JavaASTParameterNames-1.0.jar");
//var sourcesJars = GetFiles ("./externals/**/*-sources.jar");

foreach (var srcJar in sourcesJars) {
var srcJarPath = MakeAbsolute (srcJar).FullPath;
var outTxtPath = srcJarPath.Replace ("-sources.jar", "-paramnames.txt");
var outXmlPath = srcJarPath.Replace ("-sources.jar", "-paramnames.xml");
//foreach (var srcJar in sourcesJars) {
// var srcJarPath = MakeAbsolute (srcJar).FullPath;
// var outTxtPath = srcJarPath.Replace ("-sources.jar", "-paramnames.txt");
// var outXmlPath = srcJarPath.Replace ("-sources.jar", "-paramnames.xml");

StartProcess ("java", "-jar \"" + MakeAbsolute(astJar).FullPath + "\" --text \"" + srcJarPath + "\" \"" + outTxtPath + "\"");
StartProcess ("java", "-jar \"" + MakeAbsolute(astJar).FullPath + "\" --xml \"" + srcJarPath + "\" \"" + outXmlPath + "\"");
}
// StartProcess ("java", "-jar \"" + MakeAbsolute(astJar).FullPath + "\" --text \"" + srcJarPath + "\" \"" + outTxtPath + "\"");
// StartProcess ("java", "-jar \"" + MakeAbsolute(astJar).FullPath + "\" --xml \"" + srcJarPath + "\" \"" + outXmlPath + "\"");
//}
});
13 changes: 13 additions & 0 deletions build/cake/setup-environment.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Contains tasks for preparing the build environment

// Adds git commit info to build files
Task ("inject-variables")
.WithCriteria (!BuildSystem.IsLocalBuild)
.Does (() =>
{
var glob = "./source/AssemblyInfo.cs";

ReplaceTextInFiles (glob, "{BUILD_COMMIT}", BUILD_COMMIT);
ReplaceTextInFiles (glob, "{BUILD_NUMBER}", BUILD_NUMBER);
ReplaceTextInFiles (glob, "{BUILD_TIMESTAMP}", BUILD_TIMESTAMP);
});
82 changes: 82 additions & 0 deletions build/cake/validations.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Contains tasks for asserting certain conditions are met

// Ensures we don't expose default package accessibility interfaces as public
System.Xml.XmlDocument xmldoc = null;
System.Xml.XmlNamespaceManager ns = null;

Task ("metadata-verify")
.Does (() =>
{
FilePathCollection metadata_files = null;

var xpath_expression_nodes_to_find =
//$@"//attr[contains(@path,'interface') and contains(@name ,'visibility')]"
$@"//attr[contains(@path,'interface')]"
;

metadata_files = GetFiles ($"./generated/**/Metadata*.xml");

foreach (var fp in metadata_files)
{
Information ($"Metadata = {fp}");
throw new Exception ("Move this file to source");
}

metadata_files = GetFiles ($"./source/**/Metadata*.xml");

foreach (var fp in metadata_files)
{
// Maintain some that slipped through for backwards compatibility
if (fp.ToString ().Contains ("/com.github.bumptech.glide/") || fp.ToString ().Contains ("/com.google.zxing/"))
continue;

xmldoc = new System.Xml.XmlDocument ();
xmldoc.Load (fp.ToString ());
ns = new System.Xml.XmlNamespaceManager (xmldoc.NameTable);

var result = GetXmlMetadata(xpath_expression_nodes_to_find, ns).ToList ();

foreach ((string Path, bool IsPublic) r in result)
{
if (r.IsPublic)
{
Information ($"Metadata = {fp}");
Information ($" Found:");
Information ($" Path: {r.Path}");
Information ($" IsPublic: {r.IsPublic}");
throw new Exception ("Preventing exposing/surfacing interfaces with default package accessibility as public");
}
}
}
});

private IEnumerable<(string Path, bool IsPublic)> GetXmlMetadata (string xpath, System.Xml.XmlNamespaceManager xml_namespace)
{
System.Xml.XmlNodeList node_list = xmldoc.SelectNodes (xpath, xml_namespace);

foreach (System.Xml.XmlNode node in node_list)
{
string name = node.Attributes["name"].Value;
string inner_text = node.InnerText; //.Value;
string path = node.Attributes["path"].Value;


if (path.Contains ("MediaRouteProvider.DynamicGroupRouteController"))
{
Information ($" path = {path}");
Information($" Found:");
Information($" Name: {name}");
Information($" Visibility: {inner_text}");
throw new Exception ("MediaRouteProvider.DynamicGroupRouteController");
}

if (string.Equals (name, "visibility") && inner_text.Contains ("public"))
{
Information ($" Visibility = {inner_text}");

bool is_public = inner_text.Contains ("public") ? true : false;

yield return (Path: path, IsPublic: is_public);
}
}
}
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@
"groupId": "androidx.wear",
"artifactId": "wear-input",
"version": "1.1.0",
"nugetVersion": "1.0.0.19",
"nugetVersion": "1.1.0",
"nugetId": "Xamarin.AndroidX.Wear.Input",
"dependencyOnly": false
},
Expand Down
Loading