From 23576629e7b309cf3d6c869dd383cff3cab5492a Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Sun, 18 Mar 2018 17:42:45 +0800 Subject: [PATCH 1/3] add project for dotnet-mechanic --- .../Mechanic.NetcoreCliTool.fsproj | 20 ++++++++ src/Mechanic.NetcoreCliTool/Program.fs | 47 +++++++++++++++++++ src/Mechanic.NetcoreCliTool/paket.references | 2 + src/Mechanic.sln | 14 ++++++ 4 files changed, 83 insertions(+) create mode 100644 src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj create mode 100644 src/Mechanic.NetcoreCliTool/Program.fs create mode 100644 src/Mechanic.NetcoreCliTool/paket.references diff --git a/src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj b/src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj new file mode 100644 index 0000000..d59e603 --- /dev/null +++ b/src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj @@ -0,0 +1,20 @@ + + + + Exe + netcoreapp2.0 + dotnet-mechanic + DotNetMechanic + 0.0.1 + DotnetCliTool + True + + + + + + + + + + diff --git a/src/Mechanic.NetcoreCliTool/Program.fs b/src/Mechanic.NetcoreCliTool/Program.fs new file mode 100644 index 0000000..8ab59eb --- /dev/null +++ b/src/Mechanic.NetcoreCliTool/Program.fs @@ -0,0 +1,47 @@ +open System +open System.IO +open Mechanic +open Mechanic.Files +open Mechanic.GraphAlg +open Mechanic.Files + +[] +let main argv = + let projectDirectory = + if argv.Length = 0 then + Environment.CurrentDirectory + else + Path.Combine (Environment.CurrentDirectory, argv.[0]) + + let solve (n, m) projectFile = + printfn "Project %s" projectFile.FileName + + projectFile + |> ProjectFile.getSourceFiles + |> SymbolGraph.solveOrder (fun f -> f.FullName) + |> function + | TopologicalOrderResult.TopologicalOrder xs -> + ProjectFile.updateProjectFile xs projectFile + TopologicalOrderResult.TopologicalOrder (xs |> List.map (fun f -> f.FullName)) + |> printfn "%A" + (n + 1, m) + | TopologicalOrderResult.Cycle xs -> + TopologicalOrderResult.Cycle (xs |> List.map (fun f -> f.FullName)) + |> printfn "%A" + (n, m + 1) + + let projectFiles = + Directory.EnumerateFiles projectDirectory + |> Seq.map ProjectFile.tryLoad + |> Seq.filter Option.isSome + |> Seq.map (fun projectFile -> projectFile.Value) + + if Seq.isEmpty projectFiles then + printfn "No *.fsproj files found in %s" Environment.CurrentDirectory + else + 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 diff --git a/src/Mechanic.NetcoreCliTool/paket.references b/src/Mechanic.NetcoreCliTool/paket.references new file mode 100644 index 0000000..e4c76ae --- /dev/null +++ b/src/Mechanic.NetcoreCliTool/paket.references @@ -0,0 +1,2 @@ +FSharp.Core +FSharp.Compiler.Service \ No newline at end of file diff --git a/src/Mechanic.sln b/src/Mechanic.sln index 1cd554f..7664008 100644 --- a/src/Mechanic.sln +++ b/src/Mechanic.sln @@ -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 @@ -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 From 0c2df18f24aeb18b1c0d4219669062461839b8a3 Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Sun, 18 Mar 2018 18:13:30 +0800 Subject: [PATCH 2/3] support specify project file --- src/Mechanic.NetcoreCliTool/Program.fs | 34 ++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Mechanic.NetcoreCliTool/Program.fs b/src/Mechanic.NetcoreCliTool/Program.fs index 8ab59eb..e514b8a 100644 --- a/src/Mechanic.NetcoreCliTool/Program.fs +++ b/src/Mechanic.NetcoreCliTool/Program.fs @@ -3,15 +3,35 @@ open System.IO open Mechanic open Mechanic.Files open Mechanic.GraphAlg -open Mechanic.Files [] let main argv = - let projectDirectory = + 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 - Environment.CurrentDirectory + loadFromDir Environment.CurrentDirectory else - Path.Combine (Environment.CurrentDirectory, argv.[0]) + 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 @@ -30,12 +50,6 @@ let main argv = |> printfn "%A" (n, m + 1) - let projectFiles = - Directory.EnumerateFiles projectDirectory - |> Seq.map ProjectFile.tryLoad - |> Seq.filter Option.isSome - |> Seq.map (fun projectFile -> projectFile.Value) - if Seq.isEmpty projectFiles then printfn "No *.fsproj files found in %s" Environment.CurrentDirectory else From cc029521c044fe764f4c6018155372d8142bb21b Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Sun, 18 Mar 2018 21:23:09 +0800 Subject: [PATCH 3/3] updated to lastest api --- .../Mechanic.CommandLine.fsproj | 2 +- .../Mechanic.NetcoreCliTool.fsproj | 41 +++--- src/Mechanic.NetcoreCliTool/Program.fs | 123 +++++++++--------- 3 files changed, 84 insertions(+), 82 deletions(-) diff --git a/src/Mechanic.CommandLine/Mechanic.CommandLine.fsproj b/src/Mechanic.CommandLine/Mechanic.CommandLine.fsproj index c4657d1..79a5608 100644 --- a/src/Mechanic.CommandLine/Mechanic.CommandLine.fsproj +++ b/src/Mechanic.CommandLine/Mechanic.CommandLine.fsproj @@ -1,4 +1,4 @@ - + Exe diff --git a/src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj b/src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj index d59e603..6bbde37 100644 --- a/src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj +++ b/src/Mechanic.NetcoreCliTool/Mechanic.NetcoreCliTool.fsproj @@ -1,20 +1,21 @@ - - - - Exe - netcoreapp2.0 - dotnet-mechanic - DotNetMechanic - 0.0.1 - DotnetCliTool - True - - - - - - - - - - + + + + + Exe + netcoreapp2.0 + dotnet-mechanic + DotNetMechanic + 0.0.1 + DotnetCliTool + True + + + + + + + + + + diff --git a/src/Mechanic.NetcoreCliTool/Program.fs b/src/Mechanic.NetcoreCliTool/Program.fs index e514b8a..65f5fe9 100644 --- a/src/Mechanic.NetcoreCliTool/Program.fs +++ b/src/Mechanic.NetcoreCliTool/Program.fs @@ -1,61 +1,62 @@ -open System -open System.IO -open Mechanic -open Mechanic.Files -open Mechanic.GraphAlg - -[] -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) - |> function - | TopologicalOrderResult.TopologicalOrder xs -> - ProjectFile.updateProjectFile xs projectFile - TopologicalOrderResult.TopologicalOrder (xs |> List.map (fun f -> f.FullName)) - |> printfn "%A" - (n + 1, m) - | TopologicalOrderResult.Cycle xs -> - TopologicalOrderResult.Cycle (xs |> List.map (fun f -> f.FullName)) - |> printfn "%A" - (n, m + 1) - - if Seq.isEmpty projectFiles then - printfn "No *.fsproj files found in %s" Environment.CurrentDirectory - else - 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 +open System +open System.IO +open Mechanic +open Mechanic.Files +open Mechanic.GraphAlg + +[] +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