Skip to content
Browse files

Set PATH env globally instead of each time we launch a command

  • Loading branch information...
1 parent dd1f090 commit 54479267f23ad4e6edc869210db85ee51388c0a3 @davidebbo davidebbo committed
View
24 Kudu.Core/Deployment/Generator/ExternalCommandFactory.cs
@@ -85,30 +85,6 @@ public Executable BuildCommandExecutable(string commandPath, string workingDirec
string path = System.Environment.GetEnvironmentVariable("PATH");
exe.EnvironmentVariables["PATH"] = path;
- // Add the msbuild path and git path to the %PATH% so more tools are available
- var toolsPaths = new List<string> {
- _environment.ScriptPath,
- Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()),
- Path.GetDirectoryName(PathUtility.ResolveGitPath()),
- Path.GetDirectoryName(PathUtility.ResolveVsTestPath()),
- Path.GetDirectoryName(PathUtility.ResolveSQLCmdPath()),
- Path.GetDirectoryName(PathUtility.ResolveFSharpCPath())
- };
-
- toolsPaths.AddRange(PathUtility.ResolveNodeNpmPaths());
- toolsPaths.Add(PathUtility.ResolveNpmGlobalPrefix());
-
- toolsPaths.AddRange(new[]
- {
- PathUtility.ResolveBowerPath(),
- PathUtility.ResolveGruntPath(),
- PathUtility.ResolveGulpPath()
- }.Where(p => !String.IsNullOrEmpty(p)).Select(Path.GetDirectoryName));
-
- // Add /site/deployments/tools to the path to allow users to drop tools in there
- toolsPaths.Add(_environment.DeploymentToolsPath);
-
- exe.PrependToPath(toolsPaths);
return exe;
}
View
31 Kudu.Core/Infrastructure/PathUtility.cs
@@ -6,7 +6,7 @@
namespace Kudu.Core.Infrastructure
{
- internal static class PathUtility
+ public static class PathUtility
{
private const string ProgramFiles64bitKey = "ProgramW6432";
@@ -20,6 +20,35 @@ internal static class PathUtility
/// </summary>
private const string DefaultNpmVersion = "1.4.9";
+ // Return a list of folders that need to be on the %PATH%
+ public static List<string> GetPathFolders(IEnvironment environment)
+ {
+ // Add the msbuild path and git path to the %PATH% so more tools are available
+ var toolsPaths = new List<string> {
+ environment.ScriptPath,
+ Path.GetDirectoryName(ResolveMSBuildPath()),
+ Path.GetDirectoryName(ResolveGitPath()),
+ Path.GetDirectoryName(ResolveVsTestPath()),
+ Path.GetDirectoryName(ResolveSQLCmdPath()),
+ Path.GetDirectoryName(ResolveFSharpCPath())
+ };
+
+ toolsPaths.AddRange(ResolveNodeNpmPaths());
+ toolsPaths.Add(ResolveNpmGlobalPrefix());
+
+ toolsPaths.AddRange(new[]
+ {
+ ResolveBowerPath(),
+ ResolveGruntPath(),
+ ResolveGulpPath()
+ }.Where(p => !String.IsNullOrEmpty(p)).Select(Path.GetDirectoryName));
+
+ // Add /site/deployments/tools to the path to allow users to drop tools in there
+ toolsPaths.Add(environment.DeploymentToolsPath);
+
+ return toolsPaths;
+ }
+
internal static string ResolveGitPath()
{
string relativePath = Path.Combine("Git", "bin", "git.exe");
View
20 Kudu.Services.Web/App_Start/NinjectServices.cs
@@ -46,6 +46,7 @@
using XmlSettings;
using System.Configuration;
using Kudu.Core.Functions;
+using System.Text;
[assembly: WebActivator.PreApplicationStartMethod(typeof(Kudu.Services.Web.App_Start.NinjectServices), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(Kudu.Services.Web.App_Start.NinjectServices), "Stop")]
@@ -127,6 +128,9 @@ private static void RegisterServices(IKernel kernel)
IEnvironment environment = GetEnvironment();
+ // Add various folders that never change to the process path. All child processes will inherit
+ PrependFoldersToPath(environment);
+
// Per request environment
kernel.Bind<IEnvironment>().ToMethod(context => GetEnvironment(context.Kernel.Get<IDeploymentSettingsManager>()))
.InRequestScope();
@@ -684,6 +688,22 @@ private static void EnsureHomeEnvironmentVariable()
}
}
+ private static void PrependFoldersToPath(IEnvironment environment)
+ {
+ List<string> folders = PathUtility.GetPathFolders(environment);
+
+ string path = System.Environment.GetEnvironmentVariable("PATH");
+ string additionalPaths = String.Join(";", folders);
+
+ // Make sure we haven't already added them. This can happen if the Kudu appdomain restart (since it's still same process)
+ if (!path.Contains(additionalPaths))
+ {
+ path = additionalPaths + ";" + path;
+
+ System.Environment.SetEnvironmentVariable("PATH", path);
+ }
+ }
+
private static void EnsureSiteBitnessEnvironmentVariable()
{
if (System.Environment.GetEnvironmentVariable("SITE_BITNESS") == null)

0 comments on commit 5447926

Please sign in to comment.
Something went wrong with that request. Please try again.