Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanic as dotnet cli tool #94

Merged
merged 4 commits into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Mechanic.CommandLine/Mechanic.CommandLine.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
21 changes: 21 additions & 0 deletions src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>dotnet-mechanic</AssemblyName>
<PackageId>DotNetMechanic</PackageId>
<PackageVersion>0.0.1</PackageVersion>
<PackageType>DotnetCliTool</PackageType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mechanic\Mechanic.fsproj" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
62 changes: 62 additions & 0 deletions src/Mechanic.NetcoreCliTool/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
open System
open System.IO
open Mechanic
open Mechanic.Files
open Mechanic.GraphAlg

[<EntryPoint>]
let main argv =
let loadFromDir dir =
Directory.EnumerateFiles dir
|> Seq.map ProjectFile.tryLoad
|> Seq.filter Option.isSome
|> Seq.map (fun projectFile -> projectFile.Value)

let projectFiles =
if argv.Length = 0 then
loadFromDir Environment.CurrentDirectory
else
try
let path = Path.Combine (Environment.CurrentDirectory, argv.[0])
let attributes = File.GetAttributes path
if attributes.HasFlag FileAttributes.Directory then
loadFromDir path
else
let fi = FileInfo path
match fi.Extension with
| ".fsproj" ->
let projectFile = ProjectFile.loadFromFile path
seq {
yield projectFile
}
| _ -> Seq.empty
with
| _ -> Seq.empty

let solve (n, m) projectFile =
printfn "Project %s" projectFile.FileName

projectFile
|> ProjectFile.getSourceFiles
|> SymbolGraph.solveOrder (fun f -> f.FullName) (Some projectFile.FileName)
|> function
| TopologicalOrderResult.TopologicalOrder xs ->
ProjectFile.updateProjectFile xs projectFile
TopologicalOrderResult.TopologicalOrder (xs |> List.map (fun f -> f.FullName))
|> printfn "%A\n"
(n + 1, m)
| TopologicalOrderResult.Cycle xs ->
TopologicalOrderResult.Cycle (xs |> List.map (fun f -> f.FullName))
|> printfn "%A\n"
(n, m + 1)

if Seq.isEmpty projectFiles then
printfn "No *.fsproj files found in %s" Environment.CurrentDirectory
else
printfn "found %i projects\n" (Seq.length projectFiles)
projectFiles
|> Seq.fold solve (0, 0)
|> fun (n, m) ->
printfn "\nupdate %i projects, %i projects untouched because of cycle dependency" n m

0 // return an integer exit code
2 changes: 2 additions & 0 deletions src/Mechanic.NetcoreCliTool/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FSharp.Core
FSharp.Compiler.Service
14 changes: 14 additions & 0 deletions src/Mechanic.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Mechanic", "Mechanic\Mechan
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Mechanic.Tests", "Mechanic.Tests\Mechanic.Tests.fsproj", "{E1B1B3E7-B2C8-4E70-BCB9-F56FAA24EA93}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Mechanic.NetcoreCliTool", "Mechanic.NetcoreCliTool\Mechanic.NetcoreCliTool.fsproj", "{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -63,5 +65,17 @@ Global
{E1B1B3E7-B2C8-4E70-BCB9-F56FAA24EA93}.Release|x64.Build.0 = Release|x64
{E1B1B3E7-B2C8-4E70-BCB9-F56FAA24EA93}.Release|x86.ActiveCfg = Release|x86
{E1B1B3E7-B2C8-4E70-BCB9-F56FAA24EA93}.Release|x86.Build.0 = Release|x86
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Debug|x64.ActiveCfg = Debug|x64
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Debug|x64.Build.0 = Debug|x64
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Debug|x86.ActiveCfg = Debug|x86
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Debug|x86.Build.0 = Debug|x86
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Release|Any CPU.Build.0 = Release|Any CPU
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Release|x64.ActiveCfg = Release|x64
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Release|x64.Build.0 = Release|x64
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Release|x86.ActiveCfg = Release|x86
{D5FA2636-5CC7-4986-BEDA-72ADC8C86C49}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal