Skip to content

Commit 6e57687

Browse files
author
Stewart Miles
committed
Added manifestname file attribute to Version Handler.
gvhp_manifestname is used in a follow up commit to tie multiple manifests across different versions and file paths to the same package. BUg: 150886091 Change-Id: Ic5e21a59e007466ba809911ff0e6b78a3ef90976
1 parent 073ffb2 commit 6e57687

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

source/VersionHandlerImpl/src/VersionHandlerImpl.cs

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public FilenameComponents(string filename) {
8181
public static string[] TOKEN_DOTNET_TARGETS = new [] { "dotnet-" };
8282
// Prefix which indicates this file is a package manifest.
8383
public static string[] TOKEN_MANIFEST = new [] { "manifest" };
84+
// Prefix which allows a manifest to specify a human readable package name.
85+
// If the name begins with a digit [0-9] the numeric letters at the start of the string
86+
// are used to order the priority of the package alias.
87+
// For example, given the names:
88+
// - "0current name"
89+
// - "1old name"
90+
// - "another alias"
91+
// will create the list of names ["current name", "old name", "another alias"] where
92+
// "current name" is the current display name of the package.
93+
public static string[] TOKEN_MANIFEST_NAME = new[] { "manifestname-"};
8494
// Prefix which identifies the canonical name of this Linux library.
8595
public static string[] TOKEN_LINUX_LIBRARY_BASENAME = new [] { "linuxlibname-" };
8696
// Prefix which identifies the original path of a file when the package was exported.
@@ -171,6 +181,8 @@ static public Dictionary<string, string>
171181
new Regex("^(editor|" + String.Join(
172182
"|", (new List<string>(BUILD_TARGET_NAME_TO_ENUM_NAME.Keys)).ToArray()) +
173183
")$", RegexOptions.IgnoreCase);
184+
// Regular expression which matches an index in a manifest name field.
185+
private static Regex MANIFEST_NAME_REGEX = new Regex("^([0-9]+)(.*)");
174186

175187
/// <summary>
176188
/// Get a set of build target names mapped to supported BuildTarget
@@ -287,6 +299,18 @@ public static string ScriptingRuntimeDotNetVersion {
287299
/// </summary>
288300
public bool isManifest = false;
289301

302+
/// <summary>
303+
/// Offset subtracted from entries inserted in customManifestNames.
304+
/// </summary>
305+
private const int CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET = Int32.MaxValue / 2;
306+
307+
/// <summary>
308+
/// Backing store for aliases of the manifest name, the current package name is always
309+
/// first in the set. This contains only values parsed from manifestname labels,
310+
/// the ManifestName property is used to retrieve the preferred manifest name.
311+
/// </summary>
312+
public SortedList<int, string> customManifestNames = new SortedList<int, string>();
313+
290314
/// <summary>
291315
/// Set if this references an asset which is handled by PluginManager.
292316
/// </summary>
@@ -307,6 +331,27 @@ public static string ScriptingRuntimeDotNetVersion {
307331
/// </summary>
308332
public string exportPath = "";
309333

334+
/// <summary>
335+
/// If this is a manifest, get the display name.
336+
/// </summary>
337+
/// <returns>If this file is a manifest, returns the display name of the manifest,
338+
/// null otherwise.</returns>
339+
public string ManifestName {
340+
get {
341+
string name = null;
342+
bool hasManifestNames = customManifestNames != null &&
343+
customManifestNames.Count > 0;
344+
if (isManifest || hasManifestNames) {
345+
if (hasManifestNames) {
346+
name = customManifestNames.Values[0];
347+
} else {
348+
name = (new FilenameComponents(filenameCanonical)).basenameNoExtension;
349+
}
350+
}
351+
return name;
352+
}
353+
}
354+
310355
/// <summary>
311356
/// Parse metadata from filename and store in this class.
312357
/// </summary>
@@ -413,7 +458,24 @@ private bool StringListMatchesRegex(IEnumerable<string> items, Regex regEx) {
413458
/// <returns>true if the token is parsed, false otherwise.</returns>
414459
private bool ParseToken(string token, string prefix = null) {
415460
prefix = prefix ?? "";
416-
var values = MatchPrefixesGetValues(token, TOKEN_MANIFEST, prefix);
461+
var values = MatchPrefixesGetValues(token, TOKEN_MANIFEST_NAME, prefix);
462+
if (values != null) {
463+
var name = String.Join(FIELD_SEPARATOR[0].ToString(), values);
464+
var nameMatch = MANIFEST_NAME_REGEX.Match(name);
465+
int order = CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET - customManifestNames.Count;
466+
if (nameMatch.Success) {
467+
int parsedOrder;
468+
if (Int32.TryParse(nameMatch.Groups[1].Value, out parsedOrder)) {
469+
order = parsedOrder - CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET;
470+
}
471+
name = nameMatch.Groups[2].Value;
472+
}
473+
customManifestNames.Remove(order);
474+
customManifestNames.Add(order, name);
475+
isManifest = true;
476+
return true;
477+
}
478+
values = MatchPrefixesGetValues(token, TOKEN_MANIFEST, prefix);
417479
if (values != null) {
418480
isManifest = true;
419481
return true;
@@ -622,6 +684,18 @@ public void UpdateAssetLabels() {
622684
if (isManifest) {
623685
labels.Add(CreateLabel(TOKEN_MANIFEST[0], null));
624686
}
687+
if (customManifestNames != null && customManifestNames.Count > 0) {
688+
foreach (var indexAndName in customManifestNames) {
689+
int order = indexAndName.Key + CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET;
690+
var name = indexAndName.Value;
691+
if (order < CUSTOM_MANIFEST_NAMES_FIRST_INDEX_OFFSET) {
692+
labels.Add(CreateLabel(TOKEN_MANIFEST_NAME[0], order.ToString() + name,
693+
preserve: true));
694+
} else {
695+
labels.Add(CreateLabel(TOKEN_MANIFEST_NAME[0], name, preserve: true));
696+
}
697+
}
698+
}
625699
var uniqueLabels = new HashSet<string>(labels);
626700
labels = new List<string>(uniqueLabels);
627701
if (!uniqueLabels.SetEquals(new HashSet<string>(currentLabels))) {

0 commit comments

Comments
 (0)