public ConfigurationParameters CreateCompilationParameters (XmlElement projectOptions) { FSharpCompilerParameters pars = new FSharpCompilerParameters (); if (projectOptions != null) { string debugAtt = projectOptions.GetAttribute ("DefineDebug"); if (string.Compare ("True", debugAtt, true) == 0) pars.DefineSymbols = "DEBUG"; } return pars; }
public void Load(DotNetProjectConfiguration configuration) { this.configuration = configuration; compilerParameters = (FSharpCompilerParameters) configuration.CompilationParameters; symbolsEntry.Text = compilerParameters.DefineSymbols; generateDebugInformationCheckButton.Active = configuration.DebugMode; generateXmlOutputCheckButton.Active = compilerParameters.GenerateXmlDocumentation; enableOptimizationCheckButton.Active = compilerParameters.Optimize; warningsAsErrorsCheckButton.Active = ! configuration.RunWithWarnings; enableWarningsCheckButton.Active = compilerParameters.Warnings; additionalArgsEntry.Text = compilerParameters.AdditionalArguments; ignoreWarningsEntry.Text = compilerParameters.NoWarnings; }
public BuildResult Compile(ProjectItemCollection items, DotNetProjectConfiguration configuration, IProgressMonitor monitor) { FSharpCompilerParameters compilerparameters = (FSharpCompilerParameters) configuration.CompilationParameters; if (compilerparameters == null) compilerparameters = new FSharpCompilerParameters (); string responseFileName = Path.GetTempFileName(); StringWriter writer = new StringWriter (); ArrayList gacRoots = new ArrayList (); AddOption(writer, "--fullpaths"); AddOption(writer, "--utf8output"); ProjectFileCollection projectFiles = new ProjectFileCollection(); ProjectReferenceCollection references = new ProjectReferenceCollection(); // FIXME: Plain guesswork foreach(ProjectItem item in items) { ProjectFile file = null; ProjectReference reference = null; if((file = item as ProjectFile) != null) { projectFiles.Add(file); } else if((reference = item as ProjectReference) != null) { references.Add(reference); } else { // Nada... } } if (references != null) { foreach (ProjectReference lib in references) { if ((lib.ReferenceType == ReferenceType.Project) && (!(lib.OwnerProject.ParentSolution.FindProjectByName (lib.Reference) is DotNetProject))) continue; foreach (string fileName in lib.GetReferencedFileNames (configuration.Id)) { switch (lib.ReferenceType) { case ReferenceType.Gac: SystemPackage[] pkgs = Runtime.SystemAssemblyService.GetPackagesFromFullName(lib.Reference); SystemPackage pkg = null; if(pkgs != null && pkgs.Length > 0) { // FIXME: Now handling only one package pkg = pkgs[0]; } if (pkg == null) { string msg = String.Format (GettextCatalog.GetString ("{0} could not be found or is invalid."), lib.Reference); monitor.ReportWarning (msg); continue; } else if (pkg.IsInternalPackage) { AddOption(writer,"-r \"" + fileName + "\""); } if (pkg.GacRoot != null && !gacRoots.Contains (pkg.GacRoot)) gacRoots.Add (pkg.GacRoot); break; default: AddOption(writer,"-r \"" + fileName + "\""); break; } } } } string exe = configuration.CompiledOutputName; AddOption(writer,"--out \"" + exe + '"'); if (configuration.SignAssembly) { if (File.Exists (configuration.AssemblyKeyFile)) AddOption(writer,"--keyfile \"" + configuration.AssemblyKeyFile + '"'); } if (configuration.DebugMode) { AddOption(writer,"--debug"); } else if (compilerparameters.Optimize) AddOption(writer,"--optimize"); if (compilerparameters.CodePage != 0) { AddOption(writer,"--codepage " + compilerparameters.CodePage); } if (compilerparameters.TreatWarningsAsErrors) { AddOption(writer,"--warnaserror"); } if (compilerparameters.DefineSymbols.Length > 0) { AddOption(writer,"--define " + compilerparameters.DefineSymbols); } switch (configuration.CompileTarget) { case CompileTarget.Exe: AddOption(writer,"--target exe"); break; case CompileTarget.WinExe: AddOption(writer,"--target winexe"); break; case CompileTarget.Library: AddOption(writer,"--target library"); break; case CompileTarget.Module: AddOption(writer,"--target module"); break; } if (compilerparameters.GenerateXmlDocumentation) { AddOption(writer,"-doc \"" + Path.ChangeExtension(exe, ".xml") + '"'); } if (!string.IsNullOrEmpty (compilerparameters.AdditionalArguments)) { AddOption(writer,compilerparameters.AdditionalArguments); } if (!string.IsNullOrEmpty (compilerparameters.NoWarnings)) { AddOption(writer, String.Format("--nowarn {0}", compilerparameters.NoWarnings)); } foreach (ProjectFile finfo in projectFiles) { if (finfo.Subtype == Subtype.Directory) continue; switch (finfo.BuildAction) { case BuildAction.Compile: AddOption(writer,'"' + finfo.Name + '"'); break; // case BuildAction.EmbedAsResource: // string fname = finfo.Name; // if (String.Compare (Path.GetExtension (fname), ".resx", true) == 0) // fname = Path.ChangeExtension (fname, ".resources"); // // AddOption(writer,@"""/res:{0},{1}""", fname, finfo.ResourceId); // break; default: continue; } } writer.Close(); string output = String.Empty; string error = String.Empty; File.WriteAllText (responseFileName, writer.ToString ()); string compilerName; try { compilerName = GetCompilerName (configuration.ClrVersion); } catch (Exception e) { string message = "Could not obtain F# compiler"; monitor.ReportError (message, e); return null; } //string outstr = compilerName + " @" + responseFileName; string outstr = compilerName + " "+ writer.ToString (); TempFileCollection tf = new TempFileCollection(); string workingDir = "."; if (projectFiles != null && projectFiles.Count > 0) { workingDir = projectFiles [0].Project.BaseDirectory; if (workingDir == null) // Dummy projects created for single files have no filename // and so no BaseDirectory. // This is a workaround for a bug in // ProcessStartInfo.WorkingDirectory - not able to handle null workingDir = "."; } LoggingService.LogInfo (compilerName + " " + writer.ToString ()); int exitCode = DoCompilation (outstr, tf, workingDir, gacRoots, ref output, ref error); BuildResult result = ParseOutput(tf, output, error); if (result.CompilerOutput.Trim ().Length != 0) monitor.Log.WriteLine (result.CompilerOutput); //if compiler crashes, output entire error string if (result.ErrorCount == 0 && exitCode != 0) { if (!string.IsNullOrEmpty (error)) result.AddError (error); else result.AddError ("The compiler appears to have crashed without any error output."); } FileService.DeleteFile (responseFileName); FileService.DeleteFile (output); FileService.DeleteFile (error); return result; }