2015-12-10 21:06:33 +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 ;
using System.Collections.Generic ;
using System.Linq ;
2016-02-05 05:10:13 +00:00
using System.IO ;
2016-04-18 03:53:49 +00:00
using System.Threading.Tasks ;
2015-12-10 21:06:33 +00:00
using Microsoft.DotNet.ProjectModel ;
using Microsoft.DotNet.Tools.Compiler ;
2016-04-18 03:53:49 +00:00
using Microsoft.DotNet.Cli.Utils ;
2015-12-10 21:06:33 +00:00
namespace Microsoft.DotNet.Tools.Build
{
2016-01-31 05:47:50 +00:00
public class BuildCommand
2015-12-10 21:06:33 +00:00
{
2016-01-31 05:47:50 +00:00
public static int Run ( string [ ] args )
2015-12-10 21:06:33 +00:00
{
DebugHelper . HandleDebugSwitch ( ref args ) ;
try
{
var app = new BuilderCommandApp ( "dotnet build" , ".NET Builder" , "Builder for the .NET Platform. It performs incremental compilation if it's safe to do so. Otherwise it delegates to dotnet-compile which performs non-incremental compilation" ) ;
return app . Execute ( OnExecute , args ) ;
}
catch ( Exception ex )
{
#if DEBUG
Console . Error . WriteLine ( ex ) ;
#else
Console . Error . WriteLine ( ex . Message ) ;
#endif
return 1 ;
}
}
private static bool OnExecute ( List < ProjectContext > contexts , CompilerCommandApp args )
{
2016-04-18 03:53:49 +00:00
var graphCollector = new ProjectGraphCollector ( ( project , target ) = > ProjectContext . Create ( project , target ) ) ;
var graph = graphCollector . Collect ( contexts ) . ToArray ( ) ;
var builder = new DotNetProjectBuilder ( ( BuilderCommandApp ) args ) ;
return builder . Build ( graph ) . All ( r = > r ! = CompilationResult . Failure ) ;
2015-12-10 21:06:33 +00:00
}
}
}