Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Sep 5, 2024
1 parent b1a3a69 commit 2bac47e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions fsxc/Fsxc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type ProgramInvocationType =
| FsxLauncherScript
| FsxcPureInvocation

type ExtraExtension = string

exception NoScriptProvided

module Program =
Expand Down Expand Up @@ -210,7 +212,7 @@ module Program =
let GetBinFolderForAScript(script: FileInfo) =
DirectoryInfo(Path.Combine(script.Directory.FullName, "bin"))

let GetAutoGenerationTargets (orig: FileInfo) (extension: string) =
let GetAutoGenerationTargets (orig: FileInfo) (extension: ExtraExtension) =
let binDir = GetBinFolderForAScript(orig)

let autogeneratedFileName =
Expand Down Expand Up @@ -477,7 +479,7 @@ module Program =
let preprocessScriptContents
(origScript: FileInfo)
(contents: List<LineAction>)
: List<CompilerInput> * FileInfo =
: List<CompilerInput> * List<ExtraExtension> * FileInfo =

#if LEGACY_FRAMEWORK
// from "Microsoft.Build", "16.11.0" to .../packages/Microsoft.Build.16.11.0/lib/net472/Microsoft.Build.dll
Expand Down Expand Up @@ -586,8 +588,8 @@ module FsxScriptInit
type FsiStub = { CommandLineArgs: array<string> }
let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
"""

let autogeneratedFile = GetAutoGenerationTargets origScript "fs"
let extraExtensionForMain: ExtraExtension = "fs"
let autogeneratedFile = GetAutoGenerationTargets origScript extraExtensionForMain

let binFolder = autogeneratedFile.Directory

Expand All @@ -602,9 +604,12 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
"""
)

let initFile = GetAutoGenerationTargets origScript "init.fs"
let extraExtensionForInitFile: ExtraExtension = "init.fs"
let initFile = GetAutoGenerationTargets origScript extraExtensionForInitFile
File.WriteAllText(initFile.FullName, initialFileContent)

let extraExtensions = [extraExtensionForInitFile ; extraExtensionForMain]

seq {
// for !LEGACY_FRAMEWORK, this init file will be added to the fsproj file
#if LEGACY_FRAMEWORK
Expand Down Expand Up @@ -690,6 +695,7 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
)
}
|> List.ofSeq,
extraExtensions,
autogeneratedFile

#if LEGACY_FRAMEWORK
Expand All @@ -715,6 +721,7 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }
let generateProjectFile
(origScript: FileInfo)
(contents: List<LineAction>)
(extraExtensions: seq<ExtraExtension>)
: FileInfo =
let projectFile = GetAutoGenerationTargets origScript "fsproj"

Expand Down Expand Up @@ -813,7 +820,8 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }

iterate contents

addFile(sprintf "%s.fs" origScript.Name)
for ext in extraExtensions do
addFile(sprintf "%s.%s" origScript.Name ext)

File.AppendAllText(projectFile.FullName, "</Project>")

Expand All @@ -825,7 +833,7 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }

let binFolder = GetBinFolderForAScript script

let compilerInputs, autoGenFile =
let compilerInputs, extraExtensions, autoGenFile =
preprocessScriptContents script contents

Console.WriteLine(
Expand All @@ -837,7 +845,7 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }

Console.WriteLine("_________________END AUTOGEN FILE_________________")
#if !LEGACY_FRAMEWORK
let projectFile = generateProjectFile script contents
let projectFile = generateProjectFile script contents extraExtensions
#endif

let exitCode, exeTarget =
Expand Down

0 comments on commit 2bac47e

Please sign in to comment.