2017-03-03 05:04:03 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-05-18 19:14:50 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Build.Framework;
|
2016-03-25 05:24:31 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Build
|
|
|
|
|
{
|
|
|
|
|
public class EnvVars
|
|
|
|
|
{
|
|
|
|
|
public static readonly bool Verbose = GetBool("DOTNET_BUILD_VERBOSE");
|
|
|
|
|
|
2016-06-24 18:06:13 +00:00
|
|
|
|
public static bool GetBool(string name, bool defaultValue = false)
|
2016-03-25 05:24:31 +00:00
|
|
|
|
{
|
|
|
|
|
var str = Environment.GetEnvironmentVariable(name);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (str.ToLowerInvariant())
|
|
|
|
|
{
|
|
|
|
|
case "true":
|
|
|
|
|
case "1":
|
|
|
|
|
case "yes":
|
|
|
|
|
return true;
|
|
|
|
|
case "false":
|
|
|
|
|
case "0":
|
|
|
|
|
case "no":
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-18 19:14:50 +00:00
|
|
|
|
|
|
|
|
|
public static string EnsureVariable(string variableName)
|
|
|
|
|
{
|
|
|
|
|
string value = Environment.GetEnvironmentVariable(variableName);
|
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
|
{
|
|
|
|
|
throw new BuildFailureException($"'{variableName}' environment variable was not found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
2016-03-25 05:24:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|