Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 3dd3616

Browse files
Updating the Environment path with the output of path_helper
1 parent 0f55133 commit 3dd3616

File tree

5 files changed

+60
-59
lines changed

5 files changed

+60
-59
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ protected void Initialize()
5252
public void Run(bool firstRun)
5353
{
5454
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
55+
56+
ITask<string> getMacEnvironmentPathTask;
57+
if (Environment.IsMac)
58+
{
59+
getMacEnvironmentPathTask = new SimpleProcessTask(CancellationToken, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
60+
.Configure(ProcessManager)
61+
.Then((success, path) => success ? path.Split(new[] { "\"" }, StringSplitOptions.None)[1] : null);
62+
}
63+
else
64+
{
65+
getMacEnvironmentPathTask = new FuncTask<string>(CancellationToken, () => null);
66+
}
67+
68+
var setMacEnvironmentPathTask = getMacEnvironmentPathTask.Then((_, path) => {
69+
if (path != null)
70+
{
71+
Logger.Trace("Mac Environment Path Original:{0} Updated:{1}", Environment.Path, path);
72+
Environment.Path = path;
73+
}
74+
});
5575

5676
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken,
5777
(_, path) => InitializeEnvironment(path))
@@ -60,7 +80,7 @@ public void Run(bool firstRun)
6080
isBusy = true;
6181

6282
var octorunInstaller = new OctorunInstaller(Environment, TaskManager);
63-
var setupTask = octorunInstaller.SetupOctorunIfNeeded();
83+
var setupTask = setMacEnvironmentPathTask.Then(octorunInstaller.SetupOctorunIfNeeded());
6484

6585
var initializeGitTask = new FuncTask<NPath>(CancellationToken, () =>
6686
{

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public string GetEnvironmentVariable(string variable)
132132
public NPath ExtensionInstallPath { get; set; }
133133
public NPath UserCachePath { get; set; }
134134
public NPath SystemCachePath { get; set; }
135-
public NPath Path => Environment.GetEnvironmentVariable("PATH").ToNPath();
135+
public string Path { get; set; } = Environment.GetEnvironmentVariable("PATH");
136+
136137
public string NewLine => Environment.NewLine;
137138
public NPath OctorunScriptPath
138139
{

src/GitHub.Api/Platform/IEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface IEnvironment
1010
string GetEnvironmentVariable(string v);
1111
string GetSpecialFolder(Environment.SpecialFolder folder);
1212

13-
NPath Path { get; }
13+
string Path { get; set; }
1414
string NewLine { get; }
1515
bool IsCustomGitExecutable { get; set; }
1616
NPath GitExecutablePath { get; set; }

src/GitHub.Api/Platform/ProcessEnvironment.cs

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,81 +17,60 @@ public ProcessEnvironment(IEnvironment environment)
1717

1818
public void Configure(ProcessStartInfo psi, NPath workingDirectory, bool dontSetupGit = false)
1919
{
20+
Guard.ArgumentNotNull(psi, "psi");
21+
2022
psi.WorkingDirectory = workingDirectory;
2123
psi.EnvironmentVariables["HOME"] = NPath.HomeDirectory;
2224
psi.EnvironmentVariables["TMP"] = psi.EnvironmentVariables["TEMP"] = NPath.SystemTemp;
2325
psi.EnvironmentVariables["GHU_WORKINGDIR"] = workingDirectory;
24-
25-
26-
Logger.Trace("Default System PATH:{0}", Environment.GetEnvironmentVariable("PATH"));
27-
Logger.Trace("Configure DontSetupGit:{0}", dontSetupGit);
26+
psi.EnvironmentVariables["PATH"] = Environment.Path;
27+
psi.EnvironmentVariables["GHU_FULLPATH"] = Environment.Path;
2828

2929
// if we don't know where git is, then there's nothing else to configure
3030
if (!Environment.GitInstallPath.IsInitialized || dontSetupGit)
3131
return;
32-
33-
Guard.ArgumentNotNull(psi, "psi");
34-
35-
// We need to essentially fake up what git-cmd.bat does
36-
37-
var gitPathRoot = Environment.GitInstallPath;
38-
var gitLfsPath = Environment.GitInstallPath;
39-
var gitExecutableDir = Environment.GitExecutablePath.Parent; // original path to git (might be different from install path if it's a symlink)
40-
41-
Logger.Trace("Environment.GitExecutablePath: {0}", Environment.GitExecutablePath);
42-
43-
// Paths to developer tools such as msbuild.exe
44-
//var developerPaths = StringExtensions.JoinForAppending(";", developerEnvironment.GetPaths());
45-
var developerPaths = "";
46-
32+
33+
var httpProxy = Environment.GetEnvironmentVariable("HTTP_PROXY");
34+
if (!String.IsNullOrEmpty(httpProxy))
35+
psi.EnvironmentVariables["HTTP_PROXY"] = httpProxy;
36+
37+
var httpsProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY");
38+
if (!String.IsNullOrEmpty(httpsProxy))
39+
psi.EnvironmentVariables["HTTPS_PROXY"] = httpsProxy;
40+
4741
//TODO: Remove with Git LFS Locking becomes standard
4842
psi.EnvironmentVariables["GITLFSLOCKSENABLED"] = "1";
4943

50-
string path;
51-
var baseExecPath = gitPathRoot;
52-
var binPath = baseExecPath;
5344
if (Environment.IsWindows)
5445
{
46+
// We need to essentially fake up what git-cmd.bat does
47+
var gitPathRoot = Environment.GitInstallPath;
48+
49+
var baseExecPath = gitPathRoot;
5550
if (baseExecPath.DirectoryExists("mingw32"))
5651
baseExecPath = baseExecPath.Combine("mingw32");
5752
else
5853
baseExecPath = baseExecPath.Combine("mingw64");
59-
binPath = baseExecPath.Combine("bin");
60-
}
61-
62-
var execPath = baseExecPath.Combine("libexec", "git-core");
63-
if (!execPath.DirectoryExists())
64-
execPath = NPath.Default;
54+
var binPath = baseExecPath.Combine("bin");
55+
56+
var execPath = baseExecPath.Combine("libexec", "git-core");
57+
if (!execPath.DirectoryExists())
58+
execPath = NPath.Default;
6559

66-
if (Environment.IsWindows)
67-
{
6860
var userPath = @"C:\windows\system32;C:\windows";
69-
path = $"{gitPathRoot}\\cmd;{gitPathRoot}\\usr\\bin;{execPath};{binPath};{gitLfsPath};{userPath}{developerPaths}";
70-
}
71-
else
72-
{
73-
path = $"{gitExecutableDir}:{binPath}:{execPath}:{gitLfsPath}:{Environment.Path}:{developerPaths}";
61+
var path = $"{gitPathRoot}\\cmd;{gitPathRoot}\\usr\\bin;{execPath};{binPath}";
62+
63+
Logger.Trace("Calculated Path: {0}", path);
64+
65+
if (execPath.IsInitialized)
66+
psi.EnvironmentVariables["GIT_EXEC_PATH"] = execPath.ToString();
67+
68+
psi.EnvironmentVariables["PATH"] = path;
69+
psi.EnvironmentVariables["GHU_FULLPATH"] = path;
70+
71+
psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh";
72+
psi.EnvironmentVariables["TERM"] = "msys";
7473
}
75-
76-
Logger.Trace("Environment Path: {0}", Environment.Path);
77-
Logger.Trace("Calculated Path: {0}", path);
78-
79-
if (execPath.IsInitialized)
80-
psi.EnvironmentVariables["GIT_EXEC_PATH"] = execPath.ToString();
81-
82-
psi.EnvironmentVariables["PATH"] = path;
83-
psi.EnvironmentVariables["GHU_FULLPATH"] = path;
84-
85-
psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh";
86-
psi.EnvironmentVariables["TERM"] = "msys";
87-
88-
var httpProxy = Environment.GetEnvironmentVariable("HTTP_PROXY");
89-
if (!String.IsNullOrEmpty(httpProxy))
90-
psi.EnvironmentVariables["HTTP_PROXY"] = httpProxy;
91-
92-
var httpsProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY");
93-
if (!String.IsNullOrEmpty(httpsProxy))
94-
psi.EnvironmentVariables["HTTPS_PROXY"] = httpsProxy;
9574
}
9675
}
9776
}

src/tests/IntegrationTests/IntegrationTestEnvironment.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public string GetSpecialFolder(Environment.SpecialFolder folder)
8484

8585
public string UserProfilePath => UserCachePath.Parent.CreateDirectory("user profile path");
8686

87-
public NPath Path => Environment.GetEnvironmentVariable("PATH").ToNPath();
87+
public string Path { get; set; } = Environment.GetEnvironmentVariable("PATH").ToNPath();
88+
8889
public string NewLine => Environment.NewLine;
8990
public string UnityVersion => "5.6";
9091

0 commit comments

Comments
 (0)