Skip to content

Commit 6801752

Browse files
committed
# This is a combination of 3 commits.
# This is the 1st commit message: Initial Stable Id stuff # The commit message #2 will be skipped: # rework code a bit # The commit message #3 will be skipped: # FileWrites
1 parent 5626b17 commit 6801752

File tree

6 files changed

+170
-141
lines changed

6 files changed

+170
-141
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/Aapt2Link.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public class Aapt2Link : Aapt2 {
7272

7373
public bool ProtobufFormat { get; set; }
7474

75+
public string EmitIdsFile { get; set; }
76+
77+
public string StableIdsFile { get; set; }
78+
7579
AssemblyIdentityMap assemblyMap = new AssemblyIdentityMap ();
7680
List<string> tempFiles = new List<string> ();
7781

@@ -184,6 +188,10 @@ string GenerateCommandLineCommands (string ManifestFile, string currentAbi, stri
184188
if (!string.IsNullOrWhiteSpace (assetDir) && Directory.Exists (assetDir))
185189
cmd.AppendSwitchIfNotNull ("-A ", assetDir);
186190
}
191+
if (!string.IsNullOrEmpty (StableIdsFile) && File.Exists (StableIdsFile)) {
192+
cmd.AppendSwitchIfNotNull ("--stable-ids ", StableIdsFile);
193+
}
194+
cmd.AppendSwitchIfNotNull ("--emit-ids ", EmitIdsFile);
187195
cmd.AppendSwitchIfNotNull ("-o ", currentResourceOutputFile);
188196
return cmd.ToString ();
189197
}

src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public class GenerateResourceDesigner : Task
4444
[Required]
4545
public bool DesignTimeBuild { get; set; }
4646

47+
public string StableIdsFile { get; set; }
48+
49+
public string ApplicationName { get; set; }
50+
4751
private Dictionary<string, string> resource_fixup = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase);
4852

4953
public override bool Execute ()
@@ -87,7 +91,11 @@ public override bool Execute ()
8791
// Parse out the resources from the R.java file
8892
CodeTypeDeclaration resources;
8993
if (UseManagedResourceGenerator) {
90-
var parser = new ManagedResourceParser () { Log = Log };
94+
var parser = new ManagedResourceParser () {
95+
Log = Log,
96+
StableIdsFile = StableIdsFile,
97+
ApplicationName = ApplicationName,
98+
};
9199
resources = parser.Parse (ResourceDirectory, AdditionalResourceDirectories?.Select (x => x.ItemSpec), IsApplication, resource_fixup);
92100
} else {
93101
var parser = new JavaResourceParser () { Log = Log };

src/Xamarin.Android.Build.Tasks/Tasks/GetExtraPackages.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Xamarin.Android.Tasks
1111
public class GetExtraPackages : Task
1212
{
1313
[Required]
14-
public string IntermediateOutputPath { get; set; }
14+
public string LibraryProjectIntermediatePath { get; set; }
1515

1616
[Output]
1717
public string ExtraPackages { get; set; }
@@ -22,9 +22,8 @@ public class GetExtraPackages : Task
2222
public override bool Execute ()
2323
{
2424
var extraPackages = new List<string> ();
25-
var libProjects = Path.Combine (IntermediateOutputPath, "__library_projects__");
26-
if (Directory.Exists (libProjects)) {
27-
foreach (var assemblyDir in Directory.GetDirectories (libProjects)) {
25+
if (Directory.Exists (LibraryProjectIntermediatePath)) {
26+
foreach (var assemblyDir in Directory.GetDirectories (LibraryProjectIntermediatePath)) {
2827
foreach (var importBaseDir in new string [] { LibraryProjectImportsDirectoryName, "library_project_imports", }) {
2928
string importsDir = Path.Combine (assemblyDir, importBaseDir);
3029
string libpkg = GetPackageNameForLibrary (importsDir, Path.GetDirectoryName (assemblyDir));

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ManagedResourceParserTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,46 @@ public void GenerateDesignerFileWithÜmläüts ()
124124
new TaskItem (Path.Combine (Root, path, "lp", "res")),
125125
};
126126
task.IsApplication = true;
127+
task.StableIdsFile = Path.Combine (Root, path, "stableids.txt");
128+
task.ApplicationName = "com.foo.testapp";
127129
Assert.IsTrue (task.Execute (), "Task should have executed successfully.");
128130
Assert.IsTrue (File.Exists (task.NetResgenOutputFile), $"{task.NetResgenOutputFile} should have been created.");
131+
Assert.IsTrue (File.Exists (task.StableIdsFile), $"{task.StableIdsFile} should have been created.");
129132
var expected = Path.Combine (Root, "Expected", "GenerateDesignerFileExpected.cs");
130133
Assert.IsTrue (FileCompare (task.NetResgenOutputFile, expected),
131134
$"{task.NetResgenOutputFile} and {expected} do not match.");
132135
Directory.Delete (Path.Combine (Root, path), recursive: true);
133136
}
137+
138+
[Test]
139+
public void DebugGenerator ()
140+
{
141+
string path = "/Users/dean/Documents/Sandbox/Xamarin/xaspeed/tests/Xamarin.Forms-Performance-Integration/Droid";
142+
IBuildEngine engine = new MockBuildEngine (TestContext.Out);
143+
var task = new GenerateResourceDesigner {
144+
BuildEngine = engine
145+
};
146+
task.UseManagedResourceGenerator = true;
147+
task.DesignTimeBuild = true;
148+
task.Namespace = "Xamarin.Forms.Performance.Integration.Droid";
149+
task.NetResgenOutputFile = Path.Combine (path, "Resource.designer.cs");
150+
task.ProjectDir = Path.Combine (path);
151+
task.ResourceDirectory = Path.Combine (path, "obj", "Debug", "res") + Path.DirectorySeparatorChar;
152+
var files = Directory.EnumerateFiles (task.ResourceDirectory, "*.*", SearchOption.AllDirectories);
153+
List<TaskItem> items = new List<TaskItem> ();
154+
foreach (var f in files) {
155+
items.Add (new TaskItem (f, new Dictionary<string, string> {
156+
{ "LogicalName", f.Replace (task.ResourceDirectory, string.Empty) }
157+
}));
158+
}
159+
task.Resources = items.ToArray ();
160+
task.AdditionalResourceDirectories = new TaskItem [] {
161+
new TaskItem (Path.Combine (path, "obj", "Debug", "lp", "res")),
162+
};
163+
task.IsApplication = true;
164+
task.StableIdsFile = Path.Combine (path, "stableid-test.txt");
165+
task.ApplicationName = "Xamarin.Forms_Performance_Integration";
166+
task.Execute ();
167+
}
134168
}
135169
}

0 commit comments

Comments
 (0)