Skip to content

Commit 3eb137e

Browse files
Unify TF and VSTSOM Directory Structure (#5348)
* Onboarding TF latest version behind a knob * AB#2283472 * Update#2 on Review Comments * Modify unused fiels * Move copy operations to build time * Update#3 on review comments * AB#2313525 Added User Story * Remove Unused Files * Skip windows specific tests for Linux and Mac * Unify tf and vstsom dir * Updatee in common utils * Update *cmd to unblock new directories * Update util logic * Update Unit Tests * Update#1 on Review
1 parent eb1e644 commit 3eb137e

File tree

16 files changed

+208
-130
lines changed

16 files changed

+208
-130
lines changed

src/Agent.Plugins/TFCliManager.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,7 @@ public override TfsVCFeatures Features
3838

3939
public static readonly int RetriesOnFailure = 3;
4040

41-
private string TfPath
42-
{
43-
get
44-
{
45-
string agentHomeDirectory = ExecutionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value;
46-
string tfDirectoryName = VarUtil.GetTfDirectoryName(ExecutionContext);
47-
return Path.Combine(agentHomeDirectory, "externals", tfDirectoryName);
48-
}
49-
}
41+
private string TfPath => VarUtil.GetTfDirectoryPath(ExecutionContext);
5042

5143
public string FilePath => Path.Combine(TfPath, "tf.exe");
5244

src/Agent.Plugins/TfsVCSourceProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public async Task GetSourceAsync(
101101
if (PlatformUtil.RunningOnWindows)
102102
{
103103
// Set TFVC_BUILDAGENT_POLICYPATH
104-
string tfDirectoryName = VarUtil.GetTfDirectoryName(executionContext);
105-
string policyDllPath = Path.Combine(executionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", tfDirectoryName, "Microsoft.TeamFoundation.VersionControl.Controls.dll");
104+
string TfPath = VarUtil.GetTfDirectoryPath(executionContext);
105+
string policyDllPath = Path.Combine(TfPath, "Microsoft.TeamFoundation.VersionControl.Controls.dll");
106106
ArgUtil.File(policyDllPath, nameof(policyDllPath));
107107
const string policyPathEnvKey = "TFVC_BUILDAGENT_POLICYPATH";
108108
executionContext.Output(StringUtil.Loc("SetEnvVar", policyPathEnvKey));

src/Agent.Worker/Build/TFCommandManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override TfsVCFeatures Features
3535

3636
protected override string Switch => "/";
3737

38-
private string TfPath => VarUtil.GetTfPath(HostContext, ExecutionContext);
38+
private string TfPath => VarUtil.GetTfDirectoryPath(ExecutionContext);
3939

4040
public override string FilePath => Path.Combine(TfPath, "tf.exe");
4141

src/Agent.Worker/Build/TfsVCSourceProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ public async Task GetSourceAsync(
8989
if (PlatformUtil.RunningOnWindows)
9090
{
9191
// Set TFVC_BUILDAGENT_POLICYPATH
92-
string vstsomPath = VarUtil.GetServerOMPath(HostContext, executionContext);
93-
94-
string policyDllPath = Path.Combine(vstsomPath, "Microsoft.TeamFoundation.VersionControl.Controls.dll");
92+
string TfPath = VarUtil.GetTfDirectoryPath(executionContext);
93+
string policyDllPath = Path.Combine(TfPath, "Microsoft.TeamFoundation.VersionControl.Controls.dll");
9594
ArgUtil.File(policyDllPath, nameof(policyDllPath));
9695
const string policyPathEnvKey = "TFVC_BUILDAGENT_POLICYPATH";
9796
executionContext.Output(StringUtil.Loc("SetEnvVar", policyPathEnvKey));

src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ private List<Tuple<String, List<Tuple<String, String>>>> GetAdditionalCommandsFo
8282
}
8383

8484
// Initialize our Azure Support (imports the module, sets up the Azure subscription)
85-
string path = (!AgentKnobs.UseLatestTfExe.GetValue(ExecutionContext).AsBoolean() && AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean())
86-
? Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), "vstshost-legacy")
87-
: Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), "vstshost");
85+
string path = VarUtil.GetLegacyPowerShellHostDirectoryPath(ExecutionContext);
8886

8987
string azurePSM1 = Path.Combine(path, "Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Azure\\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Azure.psm1");
9088

@@ -241,9 +239,7 @@ public async Task RunAsync()
241239

242240
try
243241
{
244-
String vstsPSHostExeDirectory = (!AgentKnobs.UseLatestTfExe.GetValue(ExecutionContext).AsBoolean() && AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean())
245-
? HostContext.GetDirectory(WellKnownDirectory.LegacyPSHostLegacy)
246-
: HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost);
242+
String vstsPSHostExeDirectory = VarUtil.GetLegacyPowerShellHostDirectoryPath(ExecutionContext);
247243

248244
String vstsPSHostExe = Path.Combine(vstsPSHostExeDirectory, "LegacyVSTSPowerShellHost.exe");
249245
Int32 exitCode = await processInvoker.ExecuteAsync(workingDirectory: workingDirectory,
@@ -447,9 +443,7 @@ protected virtual void AddLegacyHostEnvironmentVariables(string scriptFile, stri
447443

448444
private void AddProxySetting(IVstsAgentWebProxy agentProxy)
449445
{
450-
string psHostDirectory = (!AgentKnobs.UseLatestTfExe.GetValue(ExecutionContext).AsBoolean() && AgentKnobs.InstallLegacyTfExe.GetValue(ExecutionContext).AsBoolean())
451-
? HostContext.GetDirectory(WellKnownDirectory.LegacyPSHostLegacy)
452-
: HostContext.GetDirectory(WellKnownDirectory.LegacyPSHost);
446+
string psHostDirectory = VarUtil.GetLegacyPowerShellHostDirectoryPath(ExecutionContext);
453447

454448
string appConfig = Path.Combine(psHostDirectory, _appConfigFileName);
455449

src/Agent.Worker/JobRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public async Task<TaskResult> RunAsync(Pipelines.AgentJobRequestMessage message,
198198
Trace.Info($"Agent metadata populated [AgentId:{settings.AgentId}, AgentName:{settings.AgentName}, OS:{VarUtil.OS}, Architecture:{VarUtil.OSArchitecture}, SelfHosted:{!settings.IsMSHosted}, CloudId:{settings.AgentCloudId}, MachineName:{Environment.MachineName}]");
199199
if (PlatformUtil.RunningOnWindows)
200200
{
201-
string serverOMDirectoryVariable = VarUtil.GetServerOMPath(HostContext, jobContext);
201+
string serverOMDirectoryVariable = VarUtil.GetTfDirectoryPath(jobContext);
202202
jobContext.SetVariable(Constants.Variables.Agent.ServerOMDirectory, serverOMDirectoryVariable, isFilePath: true);
203203
}
204204
if (!PlatformUtil.RunningOnWindows)

src/Microsoft.VisualStudio.Services.Agent/Constants.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public enum WellKnownDirectory
2525
TfLegacy,
2626
TfLatest,
2727
ServerOMLegacy,
28-
ServerOMLatest,
2928
LegacyPSHostLegacy
3029
}
3130

@@ -320,9 +319,8 @@ public static class Path
320319
public static readonly string ExternalsDirectory = "externals";
321320
public static readonly string LegacyPSHostDirectory = "vstshost";
322321
public static readonly string LegacyPSHostLegacyDirectory = "vstshost-legacy";
323-
public static readonly string ServerOMDirectory = "vstsom";
322+
public static readonly string ServerOMDirectory = "tf";
324323
public static readonly string ServerOMLegacyDirectory = "vstsom-legacy";
325-
public static readonly string ServerOMLatestDirectory = "vstsom-latest";
326324
public static readonly string TempDirectory = "_temp";
327325
public static readonly string TeeDirectory = "tee";
328326
public static readonly string TfDirectory = "tf";

src/Microsoft.VisualStudio.Services.Agent/HostContext.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,6 @@ public virtual string GetDirectory(WellKnownDirectory directory)
265265
Constants.Path.ServerOMLegacyDirectory);
266266
break;
267267

268-
case WellKnownDirectory.ServerOMLatest:
269-
path = Path.Combine(
270-
GetDirectory(WellKnownDirectory.Externals),
271-
Constants.Path.ServerOMLatestDirectory);
272-
break;
273-
274268
case WellKnownDirectory.Tf:
275269
path = Path.Combine(
276270
GetDirectory(WellKnownDirectory.Externals),

src/Microsoft.VisualStudio.Services.Agent/Util/VarUtil.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Runtime.InteropServices;
1111
using Microsoft.VisualStudio.Services.WebApi;
1212
using Newtonsoft.Json.Linq;
13+
using System.IO;
1314

1415
namespace Microsoft.VisualStudio.Services.Agent.Util
1516
{
@@ -217,39 +218,39 @@ private static bool TryGetValue(Tracing trace, IDictionary<string, string> sourc
217218
return false;
218219
}
219220

220-
public static string GetServerOMPath(IHostContext hostContext, IKnobValueContext context)
221+
public static string GetTfDirectoryPath(IKnobValueContext context)
221222
{
222-
ArgUtil.NotNull(hostContext, nameof(hostContext));
223-
ArgUtil.NotNull(context, nameof(context));
223+
var (useLatest, useLegacy, externalsPath) = GetKnobsAndExternalsPath(context);
224224

225-
return AgentKnobs.UseLatestTfExe.GetValue(context).AsBoolean()
226-
? hostContext.GetDirectory(WellKnownDirectory.ServerOMLatest)
227-
: AgentKnobs.InstallLegacyTfExe.GetValue(context).AsBoolean()
228-
? hostContext.GetDirectory(WellKnownDirectory.ServerOMLegacy)
229-
: hostContext.GetDirectory(WellKnownDirectory.ServerOM);
225+
return useLatest
226+
? Path.Combine(externalsPath, Constants.Path.TfLatestDirectory)
227+
: useLegacy
228+
? Path.Combine(externalsPath, Constants.Path.TfLegacyDirectory)
229+
: Path.Combine(externalsPath, Constants.Path.ServerOMDirectory);
230230
}
231231

232-
public static string GetTfPath(IHostContext hostContext, IKnobValueContext context)
232+
public static string GetLegacyPowerShellHostDirectoryPath(IKnobValueContext context)
233233
{
234-
ArgUtil.NotNull(hostContext, nameof(hostContext));
235-
ArgUtil.NotNull(context, nameof(context));
234+
var (useLatest, useLegacy, externalsPath) = GetKnobsAndExternalsPath(context);
236235

237-
return AgentKnobs.UseLatestTfExe.GetValue(context).AsBoolean()
238-
? hostContext.GetDirectory(WellKnownDirectory.TfLatest)
239-
: AgentKnobs.InstallLegacyTfExe.GetValue(context).AsBoolean()
240-
? hostContext.GetDirectory(WellKnownDirectory.TfLegacy)
241-
: hostContext.GetDirectory(WellKnownDirectory.Tf);
236+
return !useLatest && useLegacy
237+
? Path.Combine(externalsPath, Constants.Path.LegacyPSHostLegacyDirectory)
238+
: Path.Combine(externalsPath, Constants.Path.LegacyPSHostDirectory);
242239
}
243240

244-
public static string GetTfDirectoryName(IKnobValueContext context)
241+
242+
243+
private static (bool useLatest, bool useLegacy, string externalsPath) GetKnobsAndExternalsPath(IKnobValueContext context)
245244
{
246245
ArgUtil.NotNull(context, nameof(context));
247246

248-
return AgentKnobs.UseLatestTfExe.GetValue(context).AsBoolean()
249-
? "tf-latest"
250-
: AgentKnobs.InstallLegacyTfExe.GetValue(context).AsBoolean()
251-
? "tf-legacy"
252-
: "tf";
247+
bool useLatest = AgentKnobs.UseLatestTfExe.GetValue(context).AsBoolean();
248+
bool useLegacy = AgentKnobs.InstallLegacyTfExe.GetValue(context).AsBoolean();
249+
250+
string agentHomeDirectory = context.GetVariableValueOrDefault(Constants.Variables.Agent.HomeDirectory);
251+
string externalsPath = Path.Combine(agentHomeDirectory, Constants.Path.ExternalsDirectory);
252+
253+
return (useLatest, useLegacy, externalsPath);
253254
}
254255
}
255256
}

src/Misc/externals.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ if [[ "$PACKAGERUNTIME" == "win-x"* ]]; then
173173
BIT="64"
174174
acquireExternalTool "$CONTAINER_URL/azcopy/1/azcopy.zip" azcopy
175175
acquireExternalTool "$CONTAINER_URL/vstshost/m122_887c6659_binding_redirect_patched/vstshost.zip" vstshost
176-
acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" vstsom
177-
acquireExternalTool "$CONTAINER_URL/vstsom/dev17.11vs_c0748e6e/vstsom.zip" vstsom-latest
178-
179-
# Copy vstsom to vstshost for default PowerShell handler behavior
180-
cp -r "$LAYOUT_DIR/externals/vstsom/"* "$LAYOUT_DIR/externals/vstshost/"
181176
fi
182177

183178
acquireExternalTool "$CONTAINER_URL/mingit/${MINGIT_VERSION}/MinGit-${MINGIT_VERSION}-${BIT}-bit.zip" git
@@ -186,6 +181,10 @@ if [[ "$PACKAGERUNTIME" == "win-x"* ]]; then
186181
acquireExternalTool "$CONTAINER_URL/symstore/1/symstore.zip" symstore
187182
acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" tf
188183
acquireExternalTool "$CONTAINER_URL/vstsom/dev17.11vs_c0748e6e/vstsom.zip" tf-latest
184+
if [[ "$PACKAGERUNTIME" == "win-x64" ]]; then
185+
# Copy tf to vstshost for default PowerShell handler behavior
186+
cp -r "$LAYOUT_DIR/externals/tf/"* "$LAYOUT_DIR/externals/vstshost/"
187+
fi
189188
acquireExternalTool "$CONTAINER_URL/vswhere/2_8_4/vswhere.zip" vswhere
190189
acquireExternalTool "https://dist.nuget.org/win-x86-commandline/v4.6.4/nuget.exe" nuget
191190

@@ -210,11 +209,6 @@ elif [[ "$PACKAGERUNTIME" == "win-arm64" || "$PACKAGERUNTIME" == "win-arm32" ]];
210209

211210
# acquireExternalTool "$CONTAINER_URL/azcopy/1/azcopy.zip" azcopy # Unavailable for Win ARM 64 - https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10?tabs=dnf#download-the-azcopy-portable-binary
212211
acquireExternalTool "$CONTAINER_URL/vstshost/m122_887c6659_binding_redirect_patched/vstshost.zip" vstshost # Custom package. Will the same work for Win ARM 64?
213-
acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" vstsom # Custom package. Will the same work for Win ARM 64?
214-
acquireExternalTool "$CONTAINER_URL/vstsom/dev17.11vs_c0748e6e/vstsom.zip" vstsom-latest
215-
216-
# Copy vstsom to vstshost for default PowerShell handler behavior
217-
cp -r "$LAYOUT_DIR/externals/vstsom/"* "$LAYOUT_DIR/externals/vstshost/"
218212
fi
219213

220214
acquireExternalTool "$CONTAINER_URL/mingit/${MINGIT_VERSION}/MinGit-${MINGIT_VERSION}-${BIT}-bit.zip" git # Unavailable for Win ARM 64 - https://github.com/git-for-windows/git/releases
@@ -223,6 +217,10 @@ elif [[ "$PACKAGERUNTIME" == "win-arm64" || "$PACKAGERUNTIME" == "win-arm32" ]];
223217
acquireExternalTool "$CONTAINER_URL/symstore/win-arm${BIT}/1/symstore.zip" symstore
224218
acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" tf
225219
acquireExternalTool "$CONTAINER_URL/vstsom/dev17.11vs_c0748e6e/vstsom.zip" tf-latest
220+
if [[ "$PACKAGERUNTIME" == "win-arm64" ]]; then
221+
# Copy tf to vstshost for default PowerShell handler behavior
222+
cp -r "$LAYOUT_DIR/externals/tf/"* "$LAYOUT_DIR/externals/vstshost/"
223+
fi
226224
acquireExternalTool "$CONTAINER_URL/vswhere/2_8_4/vswhere.zip" vswhere
227225
acquireExternalTool "https://dist.nuget.org/win-x86-commandline/v4.6.4/nuget.exe" nuget
228226

0 commit comments

Comments
 (0)