Skip to content

Commit cf615ec

Browse files
Revert "Unify TF and VSTSOM Directory Structure (#5348)" (#5365)
This reverts commit 3eb137e. Co-authored-by: sanjuyadav24 <[email protected]>
1 parent 185285a commit cf615ec

File tree

16 files changed

+130
-208
lines changed

16 files changed

+130
-208
lines changed

src/Agent.Plugins/TFCliManager.cs

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

3939
public static readonly int RetriesOnFailure = 3;
4040

41-
private string TfPath => VarUtil.GetTfDirectoryPath(ExecutionContext);
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+
}
4250

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

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 TfPath = VarUtil.GetTfDirectoryPath(executionContext);
105-
string policyDllPath = Path.Combine(TfPath, "Microsoft.TeamFoundation.VersionControl.Controls.dll");
104+
string tfDirectoryName = VarUtil.GetTfDirectoryName(executionContext);
105+
string policyDllPath = Path.Combine(executionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value, "externals", tfDirectoryName, "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.GetTfDirectoryPath(ExecutionContext);
38+
private string TfPath => VarUtil.GetTfPath(HostContext, ExecutionContext);
3939

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

src/Agent.Worker/Build/TfsVCSourceProvider.cs

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

src/Agent.Worker/Handlers/LegacyPowerShellHandler.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ 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 = VarUtil.GetLegacyPowerShellHostDirectoryPath(ExecutionContext);
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");
8688

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

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

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

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

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

448454
string appConfig = Path.Combine(psHostDirectory, _appConfigFileName);
449455

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.GetTfDirectoryPath(jobContext);
201+
string serverOMDirectoryVariable = VarUtil.GetServerOMPath(HostContext, 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public enum WellKnownDirectory
2525
TfLegacy,
2626
TfLatest,
2727
ServerOMLegacy,
28+
ServerOMLatest,
2829
LegacyPSHostLegacy
2930
}
3031

@@ -319,8 +320,9 @@ public static class Path
319320
public static readonly string ExternalsDirectory = "externals";
320321
public static readonly string LegacyPSHostDirectory = "vstshost";
321322
public static readonly string LegacyPSHostLegacyDirectory = "vstshost-legacy";
322-
public static readonly string ServerOMDirectory = "tf";
323+
public static readonly string ServerOMDirectory = "vstsom";
323324
public static readonly string ServerOMLegacyDirectory = "vstsom-legacy";
325+
public static readonly string ServerOMLatestDirectory = "vstsom-latest";
324326
public static readonly string TempDirectory = "_temp";
325327
public static readonly string TeeDirectory = "tee";
326328
public static readonly string TfDirectory = "tf";

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ 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+
268274
case WellKnownDirectory.Tf:
269275
path = Path.Combine(
270276
GetDirectory(WellKnownDirectory.Externals),

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

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

1514
namespace Microsoft.VisualStudio.Services.Agent.Util
1615
{
@@ -218,39 +217,39 @@ private static bool TryGetValue(Tracing trace, IDictionary<string, string> sourc
218217
return false;
219218
}
220219

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

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);
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);
230230
}
231231

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

236-
return !useLatest && useLegacy
237-
? Path.Combine(externalsPath, Constants.Path.LegacyPSHostLegacyDirectory)
238-
: Path.Combine(externalsPath, Constants.Path.LegacyPSHostDirectory);
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);
239242
}
240243

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

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);
248+
return AgentKnobs.UseLatestTfExe.GetValue(context).AsBoolean()
249+
? "tf-latest"
250+
: AgentKnobs.InstallLegacyTfExe.GetValue(context).AsBoolean()
251+
? "tf-legacy"
252+
: "tf";
254253
}
255254
}
256255
}

src/Misc/externals.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ 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/"
176181
fi
177182

178183
acquireExternalTool "$CONTAINER_URL/mingit/${MINGIT_VERSION}/MinGit-${MINGIT_VERSION}-${BIT}-bit.zip" git
@@ -181,10 +186,6 @@ if [[ "$PACKAGERUNTIME" == "win-x"* ]]; then
181186
acquireExternalTool "$CONTAINER_URL/symstore/1/symstore.zip" symstore
182187
acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" tf
183188
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
188189
acquireExternalTool "$CONTAINER_URL/vswhere/2_8_4/vswhere.zip" vswhere
189190
acquireExternalTool "https://dist.nuget.org/win-x86-commandline/v4.6.4/nuget.exe" nuget
190191

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

210211
# 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
211212
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/"
212218
fi
213219

214220
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
@@ -217,10 +223,6 @@ elif [[ "$PACKAGERUNTIME" == "win-arm64" || "$PACKAGERUNTIME" == "win-arm32" ]];
217223
acquireExternalTool "$CONTAINER_URL/symstore/win-arm${BIT}/1/symstore.zip" symstore
218224
acquireExternalTool "$CONTAINER_URL/vstsom/m153_47c0856d_adhoc/vstsom.zip" tf
219225
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
224226
acquireExternalTool "$CONTAINER_URL/vswhere/2_8_4/vswhere.zip" vswhere
225227
acquireExternalTool "https://dist.nuget.org/win-x86-commandline/v4.6.4/nuget.exe" nuget
226228

0 commit comments

Comments
 (0)