Skip to content

Commit

Permalink
passing args via JSON (avoiding command line length problems)
Browse files Browse the repository at this point in the history
  • Loading branch information
krauthaufen committed Sep 30, 2024
1 parent 5affd67 commit 90041c9
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Adaptify.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "adaptify", "src\Adaptify.Co
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compiler", "Compiler", "{F28EFCED-51C1-4D6E-94CA-BA7C84247CFC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFolder1", "SolutionFolder1", "{5354664B-13B9-431C-83EB-A1F74FD82C2F}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5354664B-13B9-431C-83EB-A1F74FD82C2F}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
LICENSE = LICENSE
Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.3.0
* passing args via JSON (avoiding command line length problems)

### 1.3.0-prerelease6
* pure XML msbuild integration 5/N

Expand Down
132 changes: 88 additions & 44 deletions src/Adaptify.Compiler/Program.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open System
open System.IO
open System.Text.Json
open FSharp.Compiler.Symbols
open FSharp.Compiler.Text
open FSharp.Core
Expand Down Expand Up @@ -160,7 +161,7 @@ type Path with


let msbuild (argv : string[]) =

let mutable lenses = false
let mutable debugHate = false
let mutable touchFiles = false
Expand All @@ -173,50 +174,93 @@ let msbuild (argv : string[]) =
let mutable files = [||]
let mutable references = [||]
let mutable verbose = false

let mutable argv = argv
if argv.Length = 2 && File.Exists argv.[1] then
let args = File.ReadAllText(argv.[1]).Replace("\\", "\\\\")
let doc = System.Text.Json.JsonDocument.Parse args
let root = doc.RootElement

let inline stringArr (e : JsonElement) =
let cnt = e.GetArrayLength()
Array.init cnt (fun i -> e.[i].GetString())

lenses <- root.GetProperty("lenses").GetString().ToLower() = "true"
debugHate <- root.GetProperty("debugHate").GetString().ToLower() = "true"
touchFiles <- root.GetProperty("touchFiles").GetString().ToLower() = "true"
designTime <- root.GetProperty("designTime").GetString().ToLower() = "true"
targetFramework <- root.GetProperty("targetFramework").GetString()
projectFile <- root.GetProperty("projectFile").GetString()
defines <- root.GetProperty("defines").GetString()
outputPath <- root.GetProperty("outputPath").GetString()
outputType <- root.GetProperty("outputType").GetString()
files <- stringArr(root.GetProperty("files"))
references <- stringArr(root.GetProperty("references"))
verbose <- root.GetProperty("verbose").GetString().ToLower() = "true"
else

for i in 0 .. argv.Length - 1 do
match argv.[i].ToLower().Trim() with
| "--verbose" | "-v" ->
verbose <- true
| "--lenses" ->
if i + 1 < argv.Length && argv.[i+1].Trim().ToLower() = "true" then
lenses <- true
| "--designtime" ->
if i + 1 < argv.Length then
designTime <- argv.[i+1].Trim().ToLower() = "true"
| "--debughate" ->
if i + 1 < argv.Length then
debugHate <- argv.[i+1].Trim().ToLower() = "true"
| "--touchfiles" ->
if i + 1 < argv.Length then
touchFiles <- argv.[i+1].Trim().ToLower() = "true"
| "--projectfile" ->
if i + 1 < argv.Length then
projectFile <- argv.[i+1].Trim()
| "--defines" ->
if i + 1 < argv.Length then
defines <- argv.[i+1].Trim()
| "--outputpath" ->
if i + 1 < argv.Length then
outputPath <- argv.[i+1].Trim()
| "--outputtype" ->
if i + 1 < argv.Length then
outputType <- argv.[i+1].Trim()
| "--files" ->
if i + 1 < argv.Length then
let refs = argv.[i+1].Split([|';'|], StringSplitOptions.RemoveEmptyEntries)
files <- refs

| "--targetframework" ->
if i + 1 < argv.Length then
targetFramework <- argv.[i+1].Trim()
| "--references" ->
if i + 1 < argv.Length then
let refs = argv.[i+1].Split([|';'|], StringSplitOptions.RemoveEmptyEntries)
references <- refs
| _ ->
()

for i in 0 .. argv.Length - 1 do
match argv.[i].ToLower().Trim() with
| "--verbose" | "-v" ->
verbose <- true
| "--lenses" ->
if i + 1 < argv.Length && argv.[i+1].Trim().ToLower() = "true" then
lenses <- true
| "--designtime" ->
if i + 1 < argv.Length then
designTime <- argv.[i+1].Trim().ToLower() = "true"
| "--debughate" ->
if i + 1 < argv.Length then
debugHate <- argv.[i+1].Trim().ToLower() = "true"
| "--touchfiles" ->
if i + 1 < argv.Length then
touchFiles <- argv.[i+1].Trim().ToLower() = "true"
| "--projectfile" ->
if i + 1 < argv.Length then
projectFile <- argv.[i+1].Trim()
| "--defines" ->
if i + 1 < argv.Length then
defines <- argv.[i+1].Trim()
| "--outputpath" ->
if i + 1 < argv.Length then
outputPath <- argv.[i+1].Trim()
| "--outputtype" ->
if i + 1 < argv.Length then
outputType <- argv.[i+1].Trim()
| "--files" ->
if i + 1 < argv.Length then
let refs = argv.[i+1].Split([|';'|], StringSplitOptions.RemoveEmptyEntries)
files <- refs

| "--targetframework" ->
if i + 1 < argv.Length then
targetFramework <- argv.[i+1].Trim()
| "--references" ->
if i + 1 < argv.Length then
let refs = argv.[i+1].Split([|';'|], StringSplitOptions.RemoveEmptyEntries)
references <- refs
| _ ->
()


let outputPath =
Path.Combine(Path.GetDirectoryName(projectFile), outputPath) |> Path.GetFullPath
//
// if verbose then
// printfn "lenses: %A" lenses
// printfn "debugHate: %A" debugHate
// printfn "touchFiles: %A" touchFiles
// printfn "designTime: %A" designTime
// printfn "targetFramework: %s" targetFramework
// printfn "projectFile: %s" projectFile
// printfn "defines: %s" defines
// printfn "outputPath: %s" outputPath
// printfn "outputType: %s" outputType
// printfn "files: %A" files
// printfn "references: %A" references
//


let targetType =
match outputType.ToLower() with
| "winexe" -> Target.WinExe
Expand Down
6 changes: 6 additions & 0 deletions src/Adaptify.Core/Adaptify.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
<Compile Include="Helpers.fs" />
<Compile Include="CoreInstances.fs" />
</ItemGroup>
<ItemGroup>
<Content Include="paket.references" />
<Content Include="..\..\bin\Adaptify.Core.paket.template">
<Link>Adaptify.Core.paket.template</Link>
</Content>
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
20 changes: 19 additions & 1 deletion src/Adaptify.MSBuild/Adaptify.MSBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,28 @@
<PropertyGroup>
<AdaptifyCommand Condition="'$(AdaptifyCommand)' == ''">dotnet adaptify</AdaptifyCommand>
<AdaptifyVerbosity Condition="'$(AdaptifyVerbose)' == 'true'">--verbose</AdaptifyVerbosity>
<AdaptifyArgs>
{
"lenses": "$(GenerateLenses)",
"targetFramework": "$(TargetFramework)",
"debugHate": "$(DebugHate)",
"touchFiles": "$(TouchFiles)",
"projectFile": "$(MSBuildProjectFullPath)",
"designTime": "$(DesignTimeBuild)",
"defines": "$(DefineConstants.Replace("\n", ""))",
"outputPath": "$(IntermediateOutputPath)",
"outputType": "$(OutputType)",
"files": [ @(OldItems->'&quot;%(FullPath)&quot;', ', ') ],
"references": [ @(_ResolveAssemblyReferenceResolvedFiles->'&quot;%(FullPath)&quot;', ', ') ],
"verbose": "$(AdaptifyVerbose)"
}
</AdaptifyArgs>
</PropertyGroup>


<WriteLinesToFile File="$(IntermediateOutputPath)\adaptify.args" Lines="$(AdaptifyArgs)" Overwrite="true" />
<Exec Command="
$(AdaptifyCommand) msbuild --lenses '$(GenerateLenses)' --targetFramework '$(TargetFramework)' --debugHate '$(DebugHate)' --touchFiles '$(TouchFiles)' --projectFile '$(MSBuildProjectFullPath)' --designTime '$(DesignTimeBuild)' --defines '$(DefineConstants)' --outputPath '$(IntermediateOutputPath)' --outputType '$(OutputType)' $(AdaptifyVerbosity) --files '@(OldItems, ';')' --references '@(_ResolveAssemblyReferenceResolvedFiles, ';')'" Condition="$(MSBuildProjectFullPath.EndsWith('.fsproj'))" />
$(AdaptifyCommand) msbuild $(IntermediateOutputPath)\adaptify.args" Condition="$(MSBuildProjectFullPath.EndsWith('.fsproj'))" />

<ReadLinesFromFile File="$(IntermediateOutputPath)\adaptify.files">
<Output TaskParameter="Lines" ItemName="Results"/>
Expand Down
6 changes: 4 additions & 2 deletions src/Examples/Net6/Net6.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<DisableImplicitFSharpCoreReference>True</DisableImplicitFSharpCoreReference>
<GenerateLenses>True</GenerateLenses>
<GenerateLenses>true</GenerateLenses>
<!-- <AdaptifyCommand>dotnet run &#45;&#45;framework net8.0 &#45;&#45;project "C:\Users\haaser\Development\Adaptify\src\Adaptify.Compiler\adaptify.fsproj" &#45;&#45;</AdaptifyCommand>-->
<!-- <AdaptifyVerbose>true</AdaptifyVerbose>-->
<!--<DebugHate>true</DebugHate>-->
</PropertyGroup>

Expand Down Expand Up @@ -37,6 +39,6 @@
</Reference>
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\..\..\bin\Release\Adaptify.MSBuild.targets" />
<Import Project="$(MSBuildThisFileDirectory)..\..\Adaptify.MSBuild\Adaptify.MSBuild.targets" />

</Project>

0 comments on commit 90041c9

Please sign in to comment.