Last active
August 29, 2015 14:16
-
-
Save aph5nt/0ae5d22a5ed787a7e11f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let compileScript(state : State) = | |
if(state.hasStartupScript = false) then Success(state, []) | |
else | |
try | |
if File.Exists(outputAssembly) then | |
File.Delete(outputAssembly) | |
let provider = new FSharpCodeProvider() | |
let params'= CompilerParameters() | |
params'.GenerateExecutable <- false | |
params'.OutputAssembly <- outputAssembly | |
params'.IncludeDebugInformation <- true | |
params'.ReferencedAssemblies.AddRange(defaultAssemblies) | |
params'.ReferencedAssemblies.AddRange(state.referencedAssemblies) | |
params'.GenerateInMemory <- true | |
params'.WarningLevel <- 3 | |
params'.TreatWarningsAsErrors <- false | |
let compiledResults = provider.CompileAssemblyFromSource(params', state.sourceCode) | |
if compiledResults.Errors.Count > 0 then | |
//TODO fix later | |
let erros = [for error in compiledResults.Errors do error.ErrorText ] | |
let errorMessages = List.append ["Failed to compile startup script"] erros | |
Failure(errorMessages) | |
else | |
let state = { state with compiledCode = Some(compiledResults.CompiledAssembly) } | |
Success(state, ["Startup script compiled successfully."]) | |
with | |
| exn -> Failure([sprintf "Failed to compile startup script. %s" exn.Message]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment