2015-12-30 17:02:59 -08: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 ;
using Microsoft.DotNet.Cli.Utils ;
using System.Runtime.InteropServices ;
using Microsoft.DotNet.ProjectModel ;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public sealed class BuildCommand : TestCommand
{
private Project _project ;
private string _projectPath ;
private string _outputDirectory ;
2016-02-03 10:57:25 -08:00
private string _buidBasePathDirectory ;
2015-12-30 17:02:59 -08:00
private string _configuration ;
2016-02-03 10:57:25 -08:00
private string _framework ;
2016-02-18 01:09:23 -08:00
private string _versionSuffix ;
2015-12-30 17:02:59 -08:00
private bool _noHost ;
private bool _native ;
private string _architecture ;
private string _ilcArgs ;
private string _ilcPath ;
private string _appDepSDKPath ;
private bool _nativeCppMode ;
private string _cppCompilerFlags ;
2015-12-21 10:42:41 -08:00
private bool _buildProfile ;
2016-01-21 11:04:45 -08:00
private bool _noIncremental ;
2016-02-05 15:29:34 -08:00
private bool _noDependencies ;
2015-12-30 17:02:59 -08:00
private string OutputOption
{
get
{
return _outputDirectory = = string . Empty ?
"" :
2016-01-22 14:05:02 -08:00
$"-o \" { _outputDirectory } \ "" ;
2015-12-30 17:02:59 -08:00
}
}
2016-02-03 10:57:25 -08:00
private string BuildBasePathOption
2015-12-30 17:02:59 -08:00
{
get
{
2016-02-03 10:57:25 -08:00
return _buidBasePathDirectory = = string . Empty ?
2015-12-30 17:02:59 -08:00
"" :
2016-02-03 10:57:25 -08:00
$"-b {_buidBasePathDirectory}" ;
2015-12-30 17:02:59 -08:00
}
}
private string ConfigurationOption
{
get
{
return _configuration = = string . Empty ?
"" :
$"-c {_configuration}" ;
}
}
2016-02-03 10:57:25 -08:00
private string FrameworkOption
{
get
{
return _framework = = string . Empty ?
"" :
$"--framework {_framework}" ;
}
}
2016-02-18 01:09:23 -08:00
private string VersionSuffixOption
{
get
{
return _versionSuffix = = string . Empty ?
"" :
$"--version-suffix {_versionSuffix}" ;
}
}
2015-12-30 17:02:59 -08:00
private string NoHostOption
{
get
{
return _noHost ?
"--no-host" :
"" ;
}
}
private string NativeOption
{
get
{
return _native ?
"--native" :
"" ;
}
}
private string ArchitectureOption
{
get
{
return _architecture = = string . Empty ?
"" :
$"--arch {_architecture}" ;
}
}
private string IlcArgsOption
{
get
{
return _ilcArgs = = string . Empty ?
"" :
$"--ilcargs {_ilcArgs}" ;
}
}
private string IlcPathOption
{
get
{
return _ilcPath = = string . Empty ?
"" :
$"--ilcpath {_ilcPath}" ;
}
}
private string AppDepSDKPathOption
{
get
{
return _appDepSDKPath = = string . Empty ?
"" :
$"--appdepsdkpath {_appDepSDKPath}" ;
}
}
private string NativeCppModeOption
{
get
{
return _nativeCppMode ?
"--cpp" :
"" ;
}
}
private string CppCompilerFlagsOption
{
get
{
return _cppCompilerFlags = = string . Empty ?
"" :
$"--cppcompilerflags {_cppCompilerFlags}" ;
}
}
2015-12-21 10:42:41 -08:00
private string BuildProfile
{
get
{
return _buildProfile ?
"--build-profile" :
"" ;
}
}
2016-01-21 11:04:45 -08:00
private string NoIncremental
2015-12-21 10:42:41 -08:00
{
get
{
2016-01-21 11:04:45 -08:00
return _noIncremental ?
"--no-incremental" :
2015-12-21 10:42:41 -08:00
"" ;
}
}
2016-02-05 15:29:34 -08:00
private string NoDependencies
{
get
{
return _noDependencies ?
"--no-dependencies" :
"" ;
}
}
2015-12-30 17:02:59 -08:00
public BuildCommand (
string projectPath ,
string output = "" ,
2016-02-03 10:57:25 -08:00
string buidBasePath = "" ,
2015-12-30 17:02:59 -08:00
string configuration = "" ,
2016-02-03 10:57:25 -08:00
string framework = "" ,
2016-02-18 01:09:23 -08:00
string versionSuffix = "" ,
2015-12-30 17:02:59 -08:00
bool noHost = false ,
bool native = false ,
string architecture = "" ,
string ilcArgs = "" ,
string ilcPath = "" ,
string appDepSDKPath = "" ,
bool nativeCppMode = false ,
2015-12-21 10:42:41 -08:00
string cppCompilerFlags = "" ,
bool buildProfile = true ,
2016-02-05 15:29:34 -08:00
bool noIncremental = false ,
bool noDependencies = false
2015-12-30 17:02:59 -08:00
)
: base ( "dotnet" )
{
_projectPath = projectPath ;
_project = ProjectReader . GetProject ( projectPath ) ;
_outputDirectory = output ;
2016-02-03 10:57:25 -08:00
_buidBasePathDirectory = buidBasePath ;
2015-12-30 17:02:59 -08:00
_configuration = configuration ;
2016-02-18 01:09:23 -08:00
_versionSuffix = versionSuffix ;
2016-02-03 10:57:25 -08:00
_framework = framework ;
2015-12-30 17:02:59 -08:00
_noHost = noHost ;
_native = native ;
_architecture = architecture ;
_ilcArgs = ilcArgs ;
_ilcPath = ilcPath ;
_appDepSDKPath = appDepSDKPath ;
_nativeCppMode = nativeCppMode ;
_cppCompilerFlags = cppCompilerFlags ;
2015-12-21 10:42:41 -08:00
_buildProfile = buildProfile ;
2016-01-21 11:04:45 -08:00
_noIncremental = noIncremental ;
2016-02-05 15:29:34 -08:00
_noDependencies = noDependencies ;
2015-12-30 17:02:59 -08:00
}
public override CommandResult Execute ( string args = "" )
{
2015-12-21 10:42:41 -08:00
args = $"--verbose build {BuildArgs()} {args}" ;
2015-12-30 17:02:59 -08:00
return base . Execute ( args ) ;
}
2016-01-08 11:03:14 -08:00
public override CommandResult ExecuteWithCapturedOutput ( string args = "" )
{
2016-01-14 11:52:54 -08:00
args = $"--verbose build {BuildArgs()} {args}" ;
2016-01-08 11:03:14 -08:00
return base . ExecuteWithCapturedOutput ( args ) ;
}
2015-12-30 17:02:59 -08:00
public string GetOutputExecutableName ( )
{
var result = _project . Name ;
result + = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? ".exe" : "" ;
return result ;
}
private string BuildArgs ( )
{
2016-02-18 01:09:23 -08:00
return $"{BuildProfile} {NoDependencies} {NoIncremental} \" { _projectPath } \ " {OutputOption} {BuildBasePathOption} {ConfigurationOption} {FrameworkOption} {VersionSuffixOption} {NoHostOption} {NativeOption} {ArchitectureOption} {IlcArgsOption} {IlcPathOption} {AppDepSDKPathOption} {NativeCppModeOption} {CppCompilerFlagsOption}" ;
2015-12-30 17:02:59 -08:00
}
}
}