Skip to content

Commit 74f44b0

Browse files
author
Sanju Yadav
committed
Code review fixes - semantic fixes
1 parent e54704a commit 74f44b0

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

BuildConfigGen/Program.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ private static void GetVersions(string task, string configsString, out List<(str
494494
string gitRootPath = GetTasksRootPath(currentDir);
495495

496496
string taskTargetPath = Path.Combine(gitRootPath, "Tasks", task);
497+
497498
if (!Directory.Exists(taskTargetPath))
498499
{
499500
throw new Exception($"expected {taskTargetPath} to exist!");
@@ -646,9 +647,6 @@ private static void MainUpdateTask(
646647
// we need to ensure merges occur first, as the changes may cascade to other configs (e.g. Default), if there are multiple
647648
var targetConfigsWithMergeToBaseOrderedFirst = targetConfigs.OrderBy(x => x.mergeToBase ? 0 : 1);
648649

649-
var defaultConfig = targetConfigs.FirstOrDefault(x => x.isDefault)
650-
?? throw new Exception($"There is no default config for task {task}");
651-
652650
foreach (var config in targetConfigsWithMergeToBaseOrderedFirst)
653651
{
654652
if (config.useGlobalVersion && !includeLocalPackagesBuildConfig)
@@ -753,6 +751,12 @@ private static void MainUpdateTask(
753751

754752
if (useSemverBuildConfig && !config.mergeToBase)
755753
{
754+
var defaultConfig = targetConfigs.FirstOrDefault(x => x.isDefault);
755+
if (defaultConfig == null)
756+
{
757+
throw new Exception($"There is no default config for task {task}");
758+
}
759+
756760
WriteTaskJson(taskOutput, taskVersionState, config, "task.json", existingLocalPackageVersion, useSemverBuildConfig: true, defaultConfig: defaultConfig);
757761
WriteTaskJson(taskOutput, taskVersionState, config, "task.loc.json", existingLocalPackageVersion, useSemverBuildConfig: true, defaultConfig: defaultConfig);
758762
}
@@ -1403,6 +1407,7 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
14031407
{
14041408
throw new Exception($"Multiple configs for task being merged. This is not supported. task={task} mergingConfig.name={mergingConfig.name}");
14051409
}
1410+
14061411
// versionMap contains a version that needs to be merged to base
14071412
allConfigsMappedAndValid = false;
14081413
mergingConfig = config;
@@ -1521,6 +1526,7 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
15211526
else
15221527
{
15231528
TaskVersion targetVersion;
1529+
15241530
do
15251531
{
15261532
targetVersion = baseVersion.CloneWithPatch(baseVersion.Patch + offset);
@@ -1532,7 +1538,7 @@ private static void UpdateVersionsForTask(string task, TaskStateStruct taskState
15321538
{
15331539
// In the first stage of refactoring, we keep different version numbers to retain the ability to rollback.
15341540
// In the second stage of refactoring, we are going to use the same version, which is going to significantly reduce complexity of all this.
1535-
targetVersion.Build = config.constMappingKey;
1541+
targetVersion = targetVersion.CloneWithBuild(config.constMappingKey);
15361542
}
15371543

15381544
taskState.configTaskVersionMapping.Add(config, targetVersion);
@@ -1609,11 +1615,20 @@ private static void UpdateVersionsGlobal(string task, TaskStateStruct taskState,
16091615
{
16101616
if (config.useGlobalVersion)
16111617
{
1618+
TaskVersion versionToUse = globalVersion;
1619+
1620+
if (config.abTaskReleases)
1621+
{
1622+
// In the first stage of refactoring, we keep different version numbers to retain the ability to rollback.
1623+
// In the second stage of refactoring, we are going to use the same version, which is going to significantly reduce complexity of all this.
1624+
versionToUse = globalVersion.CloneWithBuild(config.constMappingKey);
1625+
}
1626+
16121627
if (taskState.configTaskVersionMapping.ContainsKey(config))
16131628
{
1614-
if (taskState.configTaskVersionMapping[config] != globalVersion)
1629+
if (taskState.configTaskVersionMapping[config] != versionToUse)
16151630
{
1616-
taskState.configTaskVersionMapping[config] = globalVersion;
1631+
taskState.configTaskVersionMapping[config] = versionToUse;
16171632

16181633
if (!taskState.versionsUpdated.Contains(config))
16191634
{
@@ -1623,7 +1638,7 @@ private static void UpdateVersionsGlobal(string task, TaskStateStruct taskState,
16231638
}
16241639
else
16251640
{
1626-
taskState.configTaskVersionMapping.Add(config, globalVersion);
1641+
taskState.configTaskVersionMapping.Add(config, versionToUse);
16271642

16281643
if (!taskState.versionsUpdated.Contains(config))
16291644
{

BuildConfigGen/TaskVersion.cs

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33

44
public class TaskVersion : IComparable<TaskVersion>, IEquatable<TaskVersion>
55
{
6-
public TaskVersion()
7-
{
8-
}
9-
106
public TaskVersion(string version)
117
{
128
VersionParser.ParseVersion(
@@ -56,35 +52,15 @@ private TaskVersion(TaskVersion taskVersionToClone)
5652
IsTest = taskVersionToClone.IsTest;
5753
}
5854

59-
public int Major
60-
{
61-
get;
62-
set;
63-
}
55+
public int Major { get; }
6456

65-
public int Minor
66-
{
67-
get;
68-
set;
69-
}
57+
public int Minor { get; }
7058

71-
public int Patch
72-
{
73-
get;
74-
set;
75-
}
59+
public int Patch { get; }
7660

77-
public string? Build
78-
{
79-
get;
80-
set;
81-
}
61+
public string? Build { get; }
8262

83-
public bool IsTest
84-
{
85-
get;
86-
set;
87-
}
63+
public bool IsTest { get; }
8864

8965
public TaskVersion Clone()
9066
{
@@ -106,6 +82,11 @@ public TaskVersion CloneWithMajor(int major)
10682
return new TaskVersion(major, Minor, Patch, Build);
10783
}
10884

85+
public TaskVersion CloneWithBuild(string? build)
86+
{
87+
return new TaskVersion(Major, Minor, Patch, build);
88+
}
89+
10990
public static implicit operator String(TaskVersion version)
11091
{
11192
return version.ToString();

0 commit comments

Comments
 (0)