[WIP] Removes *3 verbs, making msbuild the driver (#4456)
Removes *3 verbs, making msbuild the driver
This commit is contained in:
parent
55c59d621e
commit
6fcbefa4f7
746 changed files with 4256 additions and 32434 deletions
|
@ -1,297 +1,183 @@
|
|||
// 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 System.IO;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using NuGet.Frameworks;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public sealed class BuildCommand : TestCommand
|
||||
{
|
||||
private Project _project;
|
||||
private readonly string _projectPath;
|
||||
private readonly string _outputDirectory;
|
||||
private readonly string _buildBasePathDirectory;
|
||||
private readonly string _configuration;
|
||||
private readonly string _framework;
|
||||
private readonly string _versionSuffix;
|
||||
private readonly bool _noHost;
|
||||
private readonly bool _native;
|
||||
private readonly string _architecture;
|
||||
private readonly string _ilcArgs;
|
||||
private readonly string _ilcPath;
|
||||
private readonly string _appDepSDKPath;
|
||||
private readonly bool _nativeCppMode;
|
||||
private readonly string _cppCompilerFlags;
|
||||
private readonly bool _buildProfile;
|
||||
private readonly bool _noIncremental;
|
||||
private readonly bool _noDependencies;
|
||||
private readonly string _runtime;
|
||||
private readonly bool _verbose;
|
||||
|
||||
private string OutputOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _outputDirectory == string.Empty ?
|
||||
"" :
|
||||
$"-o \"{_outputDirectory}\"";
|
||||
}
|
||||
}
|
||||
private bool _captureOutput;
|
||||
|
||||
private string BuildBasePathOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _buildBasePathDirectory == string.Empty ?
|
||||
"" :
|
||||
$"-b {_buildBasePathDirectory}";
|
||||
}
|
||||
}
|
||||
private string _configuration;
|
||||
|
||||
private string ConfigurationOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _configuration == string.Empty ?
|
||||
"" :
|
||||
$"-c {_configuration}";
|
||||
}
|
||||
}
|
||||
private string FrameworkOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _framework == string.Empty ?
|
||||
"" :
|
||||
$"--framework {_framework}";
|
||||
}
|
||||
}
|
||||
private NuGetFramework _framework;
|
||||
|
||||
private string VersionSuffixOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _versionSuffix == string.Empty ?
|
||||
"" :
|
||||
$"--version-suffix {_versionSuffix}";
|
||||
}
|
||||
}
|
||||
private string _runtime;
|
||||
|
||||
private string NoHostOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _noHost ?
|
||||
"--no-host" :
|
||||
"";
|
||||
}
|
||||
}
|
||||
private bool _noDependencies;
|
||||
|
||||
private string NativeOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _native ?
|
||||
"--native" :
|
||||
"";
|
||||
}
|
||||
}
|
||||
private DirectoryInfo _outputPath;
|
||||
|
||||
private FileInfo _projectFile;
|
||||
|
||||
private string RuntimeOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _runtime == string.Empty ?
|
||||
"" :
|
||||
$"--runtime {_runtime}";
|
||||
}
|
||||
}
|
||||
private DirectoryInfo _workingDirectory;
|
||||
|
||||
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}";
|
||||
}
|
||||
}
|
||||
|
||||
private string BuildProfile
|
||||
{
|
||||
get
|
||||
{
|
||||
return _buildProfile ?
|
||||
"--build-profile" :
|
||||
"";
|
||||
}
|
||||
}
|
||||
|
||||
private string NoIncremental
|
||||
{
|
||||
get
|
||||
{
|
||||
return _noIncremental ?
|
||||
"--no-incremental" :
|
||||
"";
|
||||
}
|
||||
}
|
||||
|
||||
private string NoDependencies
|
||||
{
|
||||
get
|
||||
{
|
||||
return _noDependencies ?
|
||||
"--no-dependencies" :
|
||||
"";
|
||||
}
|
||||
}
|
||||
|
||||
private string Verbose
|
||||
{
|
||||
get
|
||||
{
|
||||
return _verbose ? "--verbose" : "";
|
||||
}
|
||||
}
|
||||
|
||||
public BuildCommand(
|
||||
string projectPath,
|
||||
string output="",
|
||||
string buildBasePath = "",
|
||||
string configuration="",
|
||||
string framework="",
|
||||
string runtime="",
|
||||
string versionSuffix="",
|
||||
bool noHost=false,
|
||||
bool native=false,
|
||||
string architecture="",
|
||||
string ilcArgs="",
|
||||
string ilcPath="",
|
||||
string appDepSDKPath="",
|
||||
bool nativeCppMode=false,
|
||||
string cppCompilerFlags="",
|
||||
bool buildProfile=true,
|
||||
bool noIncremental=false,
|
||||
bool noDependencies=false,
|
||||
bool verbose=true,
|
||||
bool skipLoadProject=false)
|
||||
public BuildCommand()
|
||||
: base("dotnet")
|
||||
{
|
||||
_projectPath = projectPath;
|
||||
|
||||
if (!skipLoadProject)
|
||||
{
|
||||
_project = ProjectReader.GetProject(projectPath);
|
||||
}
|
||||
|
||||
_outputDirectory = output;
|
||||
_buildBasePathDirectory = buildBasePath;
|
||||
_configuration = configuration;
|
||||
_versionSuffix = versionSuffix;
|
||||
_framework = framework;
|
||||
_runtime = runtime;
|
||||
_noHost = noHost;
|
||||
_native = native;
|
||||
_architecture = architecture;
|
||||
_ilcArgs = ilcArgs;
|
||||
_ilcPath = ilcPath;
|
||||
_appDepSDKPath = appDepSDKPath;
|
||||
_nativeCppMode = nativeCppMode;
|
||||
_cppCompilerFlags = cppCompilerFlags;
|
||||
_buildProfile = buildProfile;
|
||||
_noIncremental = noIncremental;
|
||||
_noDependencies = noDependencies;
|
||||
_verbose = verbose;
|
||||
}
|
||||
|
||||
public override CommandResult Execute(string args = "")
|
||||
{
|
||||
args = $"{Verbose} build {BuildArgs()} {args}";
|
||||
return base.Execute(args);
|
||||
args = $"build {GetNoDependencies()} {GetProjectFile()} {GetOutputPath()} {GetConfiguration()} {GetFramework()} {GetRuntime()} {args}";
|
||||
|
||||
if (_workingDirectory != null)
|
||||
{
|
||||
this.WithWorkingDirectory(_workingDirectory.FullName);
|
||||
}
|
||||
|
||||
if (_captureOutput)
|
||||
{
|
||||
return base.ExecuteWithCapturedOutput(args);
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.Execute(args);
|
||||
}
|
||||
}
|
||||
|
||||
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
||||
{
|
||||
args = $"{Verbose} build {BuildArgs()} {args}";
|
||||
return base.ExecuteWithCapturedOutput(args);
|
||||
WithCapturedOutput();
|
||||
|
||||
return Execute(args);
|
||||
}
|
||||
|
||||
public string GetPortableOutputName()
|
||||
public BuildCommand WithCapturedOutput()
|
||||
{
|
||||
return $"{_project.Name}.dll";
|
||||
_captureOutput = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string GetOutputExecutableName()
|
||||
public BuildCommand WithConfiguration(string configuration)
|
||||
{
|
||||
return _project.Name + GetExecutableExtension();
|
||||
_configuration = configuration;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public string GetExecutableExtension()
|
||||
public BuildCommand WithFramework(NuGetFramework framework)
|
||||
{
|
||||
#if NET451
|
||||
return ".exe";
|
||||
#else
|
||||
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "";
|
||||
#endif
|
||||
_framework = framework;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private string BuildArgs()
|
||||
public BuildCommand WithRuntime(string runtime)
|
||||
{
|
||||
return $"{BuildProfile} {NoDependencies} {NoIncremental} \"{_projectPath}\" {OutputOption} {BuildBasePathOption} {ConfigurationOption} {FrameworkOption} {RuntimeOption} {VersionSuffixOption} {NoHostOption} {NativeOption} {ArchitectureOption} {IlcArgsOption} {IlcPathOption} {AppDepSDKPathOption} {NativeCppModeOption} {CppCompilerFlagsOption}";
|
||||
_runtime = runtime;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildCommand WithNoDependencies()
|
||||
{
|
||||
_noDependencies = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildCommand WithOutputPath(DirectoryInfo outputPath)
|
||||
{
|
||||
_outputPath = outputPath;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildCommand WithProjectDirectory(DirectoryInfo projectDirectory)
|
||||
{
|
||||
_workingDirectory = projectDirectory;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildCommand WithProjectFile(FileInfo projectFile)
|
||||
{
|
||||
_projectFile = projectFile;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildCommand WithWorkingDirectory(DirectoryInfo workingDirectory)
|
||||
{
|
||||
_workingDirectory = workingDirectory;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private string GetConfiguration()
|
||||
{
|
||||
if (_configuration == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $"--configuration {_configuration}";
|
||||
}
|
||||
|
||||
private string GetFramework()
|
||||
{
|
||||
if (_framework == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $"--framework {_framework.GetShortFolderName()}";
|
||||
}
|
||||
|
||||
private string GetRuntime()
|
||||
{
|
||||
if (_runtime == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $"--runtime {_runtime}";
|
||||
}
|
||||
|
||||
private string GetNoDependencies()
|
||||
{
|
||||
if (!_noDependencies)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return "--no-dependencies";
|
||||
}
|
||||
|
||||
private string GetOutputPath()
|
||||
{
|
||||
if (_outputPath == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $"\"{_outputPath.FullName}\"";
|
||||
}
|
||||
|
||||
private string GetProjectFile()
|
||||
{
|
||||
if (_projectFile == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $"\"{_projectFile.FullName}\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue