void GetFolderContent(Project project, string folder, out ProjectFileCollection files, out List <string> folders) { string folderPrefix = folder + Path.DirectorySeparatorChar; files = new ProjectFileCollection(); folders = new List <string> (); foreach (ProjectFile file in project.Files) { string dir; if (!file.Visible || file.Flags.HasFlag(ProjectItemFlags.Hidden)) { continue; } if (file.Subtype != Subtype.Directory) { if (file.DependsOnFile != null) { continue; } dir = file.IsLink ? project.BaseDirectory.Combine(file.ProjectVirtualPath).ParentDirectory : file.FilePath.ParentDirectory; if (dir == folder) { files.Add(file); continue; } } else { dir = file.Name; } // add the directory if it isn't already present if (dir.StartsWith(folderPrefix, StringComparison.Ordinal)) { int i = dir.IndexOf(Path.DirectorySeparatorChar, folderPrefix.Length); if (i != -1) { dir = dir.Substring(0, i); } if (!folders.Contains(dir)) { folders.Add(dir); } } } }
public void AddFile(ProjectFile projectFile) { FilesAdded.Add(projectFile); Files.Add(projectFile); }
protected void GetContents(MonoDevelop.Projects.Project project, MonoDevelop.Prj2Make.Schema.Csproj.File[] Include, ProjectFileCollection files, IProgressMonitor monitor) { if (Include == null || Include.Length == 0) { return; } // Iterate through the file collection of the csproj file foreach (MonoDevelop.Prj2Make.Schema.Csproj.File fl in Include) { ProjectFile flOut = new ProjectFile(); string name; if ((fl.Link == null) || (fl.Link.Length == 0)) { name = MapPath(project.BaseDirectory, fl.RelPath); } else { name = MapPath(null, fl.Link); } if (name == null) { monitor.ReportWarning(GettextCatalog.GetString("Can't import file: ") + fl.RelPath); continue; } flOut.Name = name; // Adding here as GetDefaultResourceIdInternal needs flOut.Project files.Add(flOut); switch (fl.SubType) { case "Code": flOut.Subtype = Subtype.Code; break; } switch (fl.BuildAction) { case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.Compile: flOut.BuildAction = BuildAction.Compile; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.Content: flOut.BuildAction = BuildAction.Content; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.EmbeddedResource: flOut.BuildAction = BuildAction.EmbeddedResource; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.None: flOut.BuildAction = BuildAction.None; break; } // DependentUpon is relative to flOut flOut.DependsOn = MapPath(Path.GetDirectoryName(flOut.Name), fl.DependentUpon); flOut.Data = ""; } }
void GetFolderContent(Project project, string folder, out ProjectFileCollection files, out List<string> folders) { string folderPrefix = folder + Path.DirectorySeparatorChar; files = new ProjectFileCollection (); folders = new List<string> (); foreach (ProjectFile file in project.Files) { string dir; if (file.Subtype != Subtype.Directory) { if (file.DependsOnFile != null) continue; dir = file.IsLink ? project.BaseDirectory.Combine (file.ProjectVirtualPath).ParentDirectory : file.FilePath.ParentDirectory; if (dir == folder) { files.Add (file); continue; } } else dir = file.Name; // add the directory if it isn't already present if (dir.StartsWith (folderPrefix, StringComparison.Ordinal)) { int i = dir.IndexOf (Path.DirectorySeparatorChar, folderPrefix.Length); if (i != -1) dir = dir.Substring (0,i); if (!folders.Contains (dir)) folders.Add (dir); } } }
protected void GetContents (MonoDevelop.Projects.Project project, MonoDevelop.Prj2Make.Schema.Csproj.File[] Include, ProjectFileCollection files, IProgressMonitor monitor) { if (Include == null || Include.Length == 0) return; // Iterate through the file collection of the csproj file foreach(MonoDevelop.Prj2Make.Schema.Csproj.File fl in Include) { ProjectFile flOut = new ProjectFile (); string name; if ((fl.Link == null) || (fl.Link.Length == 0)) { name = MapPath (project.BaseDirectory, fl.RelPath); } else { name = MapPath (null, fl.Link); } if (name == null) { monitor.ReportWarning (GettextCatalog.GetString ("Can't import file: ") + fl.RelPath); continue; } flOut.Name = name; // Adding here as GetDefaultResourceIdInternal needs flOut.Project files.Add (flOut); switch (fl.SubType) { case "Code": flOut.Subtype = Subtype.Code; break; } switch (fl.BuildAction) { case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.Compile: flOut.BuildAction = BuildAction.Compile; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.Content: flOut.BuildAction = BuildAction.Content; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.EmbeddedResource: flOut.BuildAction = BuildAction.EmbeddedResource; break; case MonoDevelop.Prj2Make.Schema.Csproj.FileBuildAction.None: flOut.BuildAction = BuildAction.None; break; } // DependentUpon is relative to flOut flOut.DependsOn = MapPath (Path.GetDirectoryName (flOut.Name), fl.DependentUpon); flOut.Data = ""; } }
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; }