WritePatchVersionNumber( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { if (!string.IsNullOrEmpty(array[0].VersionPatch)) { WriteString(array[0].VersionPatch, "VER_PAT=", proFilePath, writer); } } else { var values = new Values <string>(); foreach (var data in array) { if (!string.IsNullOrEmpty(data.VersionPatch)) { if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.VersionPatch; } else { values.Release = data.VersionPatch; } } } WriteString(values, "VER_PAT=", proFilePath, writer); } }
WriteObjectiveSources( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { WriteStringArray(array[0].ObjectiveSources, "OBJECTIVE_SOURCES+=", proFilePath, writer); } else { var values = new Values <Bam.Core.StringArray>(); foreach (var data in array) { if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.ObjectiveSources; } else { values.Release = data.ObjectiveSources; } } WriteStringArrays(values, "OBJECTIVE_SOURCES+=", proFilePath, writer); } }
WriteLibraries( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { WriteLocationArray(array[0].Libraries, "LIBS+=", null, writer); } else { var values = new Values <Bam.Core.LocationArray>(); foreach (var data in array) { if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.Libraries; } else { values.Release = data.Libraries; } } WriteLocationArrays(values, "LIBS+=", null, writer); } }
WritePostLinkCommands( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { WriteStringArray(array[0].PostLink, "QMAKE_POST_LINK+=", proFilePath, true, false, true, writer); } else { var values = new Values <Bam.Core.StringArray>(); foreach (var data in array) { if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.PostLink; } else { values.Release = data.PostLink; } } WriteStringArrays(values, "QMAKE_POST_LINK+=", proFilePath, true, false, true, writer); } }
OrderLibrariesWithDecreasingDependencies( Bam.Core.Array <Bam.Core.Module> libs) { // work on a copy of the flattened list of libraries, as the modules may be rearranged var flatLibs = new Bam.Core.Array <Bam.Core.Module>(libs); // now ensure that the order of the libraries is such that those with the least number of dependents // are at the end // this is O(N^2) and some modules may be moved more than once for (var i = 0; i < flatLibs.Count;) { var ontoNext = true; for (var j = i + 1; j < flatLibs.Count; ++j) { if (!(flatLibs[j] is IForwardedLibraries)) { continue; } // if any other module has the first as a dependent, move the dependent to the end if ((flatLibs[j] as IForwardedLibraries).ForwardedLibraries.Contains(flatLibs[i])) { var temp = flatLibs[i]; flatLibs.Remove(temp); flatLibs.Add(temp); ontoNext = false; break; } } if (ontoNext) { ++i; } } return(flatLibs.ToReadOnlyCollection()); }
WritePriPaths( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { WriteStringArray(array[0].PriPaths, @"include({0})", proFilePath, writer); } else { var values = new Values <Bam.Core.StringArray>(); foreach (var data in array) { if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.PriPaths; } else { values.Release = data.PriPaths; } } WriteStringArrays(values, @"include({0})", proFilePath, writer); } }
WriteMocDir( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { if (null == array[0].MocDir) { return; } WriteString(array[0].MocDir.GetSinglePath(), "MOC_DIR=", null, writer); } else { var values = new Values <string>(); foreach (var data in array) { if (null == data.MocDir) { continue; } if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.MocDir.GetSinglePath(); } else { values.Release = data.MocDir.GetSinglePath(); } } WriteString(values, "MOC_DIR=", null, writer); } }
WriteTarget( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { WriteString(array[0].Target, "TARGET=", null, writer); } else { var values = new Values <string>(); foreach (var data in array) { if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.Target; } else { values.Release = data.Target; } } WriteString(values, "TARGET=", null, writer); } }
FindAllDynamicDependents( C.IDynamicLibrary dynamicModule) { var dynamicDeps = new Bam.Core.Array <C.CModule>(); if (0 == (dynamicModule as C.CModule).Dependents.Count) { return(dynamicDeps); } foreach (var dep in (dynamicModule as C.CModule).Dependents) { var dependent = dep; if (dependent is C.SharedObjectSymbolicLink) { dependent = (dependent as C.SharedObjectSymbolicLink).SharedObject; } if (!(dependent is C.IDynamicLibrary)) { continue; } var dynDep = dependent as C.CModule; dynamicDeps.AddUnique(dynDep); dynamicDeps.AddRangeUnique(FindAllDynamicDependents(dynDep as C.IDynamicLibrary)); } return(dynamicDeps); }
WriteCXXFlags( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { WriteStringArray(array[0].CXXFlags, "QMAKE_CXXFLAGS+=", proFilePath, writer); } else { var values = new Values <Bam.Core.StringArray>(); foreach (var data in array) { if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.CXXFlags; } else { values.Release = data.CXXFlags; } } WriteStringArrays(values, "QMAKE_CXXFLAGS+=", proFilePath, writer); } }
WriteTemplate( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { switch (array[0].Output) { case OutputType.Application: writer.WriteLine("TEMPLATE = app"); break; case OutputType.StaticLibrary: case OutputType.DynamicLibrary: writer.WriteLine("TEMPLATE = lib"); break; case OutputType.ObjectFile: // special case - a static library which has the least side-effects writer.WriteLine("TEMPLATE = lib"); break; case OutputType.HeaderLibrary: writer.WriteLine("TEMPLATE = subdirs"); break; default: throw new Bam.Core.Exception("Should not be writing out .pro files for outputs of type '{0}' : {1}", array[0].Output.ToString(), proFilePath); } }
AddFiles( string path, Bam.Core.Module macroModuleOverride = null, System.Text.RegularExpressions.Regex filter = null) { var macroModule = (macroModuleOverride == null) ? this : macroModuleOverride; var wildcardPath = macroModule.CreateTokenizedString(path).Parse(); var dir = System.IO.Path.GetDirectoryName(wildcardPath); if (!System.IO.Directory.Exists(dir)) { throw new Bam.Core.Exception("The directory {0} does not exist", dir); } var leafname = System.IO.Path.GetFileName(wildcardPath); var files = System.IO.Directory.GetFiles(dir, leafname, System.IO.SearchOption.TopDirectoryOnly); if (filter != null) { files = files.Where(pathname => filter.IsMatch(pathname)).ToArray(); } if (0 == files.Length) { throw new Bam.Core.Exception("No files were found that matched the pattern '{0}'", wildcardPath); } var modulesCreated = new Bam.Core.Array <Bam.Core.Module>(); foreach (var filepath in files) { modulesCreated.Add(this.AddFile(filepath, verbatim: true)); } return(modulesCreated); }
Bam.Core.Array<Bam.Core.LocationKey> Bam.Core.ITool.OutputLocationKeys( Bam.Core.BaseModule module) { var array = new Bam.Core.Array<Bam.Core.LocationKey>( XmlModule.OutputFile, XmlModule.OutputDir ); return array; }
WriteConfig( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { var config = string.Empty; if (array.Count == 1) { if (array[0].OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { config += " debug"; } else { config += " release"; } } else { config += " debug_and_release"; } var qtModules = array[0].QtModules; if (array.Count > 1) { qtModules = new Bam.Core.StringArray(qtModules.Union(array[1].QtModules)); } if (qtModules.Count > 0) { config += " qt"; } // special case of an object file creating a static lib too if (0 != (array[0].Output & (OutputType.StaticLibrary | OutputType.ObjectFile))) { config += " staticlib"; } else if (array[0].Output == OutputType.DynamicLibrary) { config += " shared"; } writer.WriteLine("CONFIG +={0}", config); if (qtModules.Count > 0) { writer.WriteLine("QT = {0}", qtModules.ToString()); } if (Bam.Core.OSUtilities.IsOSXHosting) { if (array[0].Output == OutputType.Application && !array[0].OSXApplicationBundle) { writer.WriteLine("CONFIG -= app_bundle"); } } }
Bam.Core.ITool.OutputLocationKeys( Bam.Core.BaseModule module) { var array = new Bam.Core.Array <Bam.Core.LocationKey>( C.ObjectFile.OutputFile, C.ObjectFile.OutputDir ); return(array); }
CreateBuildActionEntry( System.Xml.XmlDocument doc, System.Xml.XmlElement buildActionEntriesEl, Target target, Bam.Core.Array <Target> buildActionsCreated) { #if true #else // add all required dependencies in first (order matters) foreach (var required in target.TargetDependencies) { this.CreateBuildActionEntry(doc, buildActionEntriesEl, required., buildActionsCreated); } #endif // the same target might appear again while iterating through the required targets of dependencies // only add it once (first one is important for ordering) if (buildActionsCreated.Contains(target)) { return; } var buildActionEntry = doc.CreateElement("BuildActionEntry"); buildActionEntriesEl.AppendChild(buildActionEntry); var buildableReference = doc.CreateElement("BuildableReference"); buildActionEntry.AppendChild(buildableReference); { buildableReference.SetAttribute("BuildableIdentifier", "primary"); buildableReference.SetAttribute("BlueprintIdentifier", target.GUID); if (null != target.FileReference) { buildableReference.SetAttribute("BuildableName", target.FileReference.Name); } buildableReference.SetAttribute("BlueprintName", target.Name); if (target.Project.ProjectDir == this.Project.ProjectDir) { buildableReference.SetAttribute("ReferencedContainer", "container:" + System.IO.Path.GetFileName(this.Project.ProjectDir.Parse())); } else { var relative = this.Project.GetRelativePathToProject(target.Project.ProjectDir); buildableReference.SetAttribute("ReferencedContainer", "container:" + relative); } } buildActionsCreated.Add(target); }
AddFiles( string path, Bam.Core.Module macroModuleOverride = null, System.Text.RegularExpressions.Regex filter = null) { if (System.String.IsNullOrEmpty(path)) { throw new Bam.Core.Exception("Cannot add files from an empty path"); } var macroModule = (macroModuleOverride == null) ? this : macroModuleOverride; var tokenizedPath = macroModule.CreateTokenizedString(path); tokenizedPath.Parse(); var wildcardPath = tokenizedPath.ToString(); var dir = System.IO.Path.GetDirectoryName(wildcardPath); if (!System.IO.Directory.Exists(dir)) { throw new Bam.Core.Exception("The directory {0} does not exist", dir); } var leafname = System.IO.Path.GetFileName(wildcardPath); var option = leafname.Contains("**") ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly; var files = System.IO.Directory.GetFiles(dir, leafname, option); if (0 == files.Length) { throw new Bam.Core.Exception("No files were found that matched the pattern '{0}'", wildcardPath); } if (filter != null) { var filteredFiles = files.Where(pathname => filter.IsMatch(pathname)).ToArray(); if (0 == filteredFiles.Length) { throw new Bam.Core.Exception("No files were found that matched the pattern '{0}', after applying the regex filter. {1} were found prior to applying the filter.", wildcardPath, files.Count()); } files = filteredFiles; } var modulesCreated = new Bam.Core.Array <Bam.Core.Module>(); foreach (var filepath in files) { modulesCreated.Add(this.AddFile(filepath, verbatim: true)); } return(modulesCreated); }
WriteCustomRules( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { if (array[0].CustomRules == null) { return; } foreach (var customRule in array[0].CustomRules) { // split on the first = only var split = customRule.Split(new [] { '=' }, 2); split[0] = split[0].Trim(); split[1] = split[1].Trim(); split[0] += '='; WriteVerboseString(split[1], split[0], proFilePath, writer); } } else { // TODO: how to handle this for splitting on the equals sign? var values = new Values <Bam.Core.StringArray>(); foreach (var data in array) { if (data.CustomRules == null) { continue; } if (data.OwningNode.Target.HasConfiguration(Bam.Core.EConfiguration.Debug)) { values.Debug = data.CustomRules; } else { values.Release = data.CustomRules; } } // TODO: this might product incorrectly formatted pro files WriteStringArrays(values, string.Empty, proFilePath, true, false, true, writer); } }
WriteCustomPathVariables( Bam.Core.Array <QMakeData> array, string proFilePath, System.IO.StreamWriter writer) { if (1 == array.Count) { foreach (var customPath in array[0].CustomPathVariables) { WriteStringArray(customPath.Value, customPath.Key + "+=", proFilePath, writer); } } else { // TODO throw new System.NotImplementedException(); } }
CreateBuildActions( System.Xml.XmlDocument doc, System.Xml.XmlElement schemeElement, Target target) { var buildActionEl = doc.CreateElement("BuildAction"); schemeElement.AppendChild(buildActionEl); { buildActionEl.SetAttribute("parallelizeBuildables", "YES"); buildActionEl.SetAttribute("buildImplicitDependencies", "YES"); var buildActionEntries = doc.CreateElement("BuildActionEntries"); buildActionEl.AppendChild(buildActionEntries); var buildActionsCreated = new Bam.Core.Array <Target>(); this.CreateBuildActionEntry(doc, buildActionEntries, target, buildActionsCreated); } }
FlattenHierarchicalFileList( Bam.Core.Array <Bam.Core.Module> files) { var list = new Bam.Core.Array <Bam.Core.Module>(); foreach (var input in files) { if (input is Bam.Core.IModuleGroup) { foreach (var child in input.Children) { list.Add(child); } } else { list.Add(input); } } return(list); }
Bam.Core.Array<Bam.Core.LocationKey> Bam.Core.ITool.OutputLocationKeys( Bam.Core.BaseModule module) { var array = new Bam.Core.Array<Bam.Core.LocationKey>( CSharp.Assembly.OutputFile, CSharp.Assembly.OutputDir, CSharp.Assembly.PDBFile, CSharp.Assembly.PDBDir ); return array; }
Setup() { this.intArray = new Bam.Core.Array <int>(); }
TearDown() { this.intArray = null; }
public object Build( CSharp.Assembly moduleToBuild, out System.Boolean success) { var assemblyModule = moduleToBuild as Bam.Core.BaseModule; var node = assemblyModule.OwningNode; var target = node.Target; var assemblyOptions = assemblyModule.Options; var options = assemblyOptions as CSharp.IOptions; if (node.ExternalDependents != null) { var keyFilters = new Bam.Core.Array<Bam.Core.LocationKey>( CSharp.Assembly.OutputFile ); var dependentAssemblies = new Bam.Core.LocationArray(); node.ExternalDependents.FilterOutputLocations(keyFilters, dependentAssemblies); foreach (var loc in dependentAssemblies) { options.References.Add(loc.GetSinglePath()); } } var sourceFiles = new Bam.Core.StringArray(); var fields = moduleToBuild.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic); foreach (var field in fields) { // C# files { var sourceFileAttributes = field.GetCustomAttributes(typeof(Bam.Core.SourceFilesAttribute), false); if (null != sourceFileAttributes && sourceFileAttributes.Length > 0) { var sourceField = field.GetValue(moduleToBuild); if (sourceField is Bam.Core.Location) { var file = sourceField as Bam.Core.Location; var absolutePath = file.GetSinglePath(); if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Source file '{0}' does not exist", absolutePath); } sourceFiles.Add(absolutePath); } else if (sourceField is Bam.Core.FileCollection) { var sourceCollection = sourceField as Bam.Core.FileCollection; // TODO: convert to var foreach (Bam.Core.Location location in sourceCollection) { var absolutePath = location.AbsolutePath; if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Source file '{0}' does not exist", absolutePath); } sourceFiles.Add(absolutePath); } } else { throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString()); } } } // WPF application definition .xaml file { var xamlFileAttributes = field.GetCustomAttributes(typeof(CSharp.ApplicationDefinitionAttribute), false); if (null != xamlFileAttributes && xamlFileAttributes.Length > 0) { var sourceField = field.GetValue(moduleToBuild); if (sourceField is Bam.Core.Location) { var file = sourceField as Bam.Core.Location; var absolutePath = file.GetSinglePath(); if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Application definition file '{0}' does not exist", absolutePath); } var csPath = absolutePath + ".cs"; if (!System.IO.File.Exists(csPath)) { throw new Bam.Core.Exception("Associated source file '{0}' to application definition file '{1}' does not exist", csPath, absolutePath); } sourceFiles.Add(csPath); } else if (sourceField is Bam.Core.FileCollection) { var sourceCollection = sourceField as Bam.Core.FileCollection; if (sourceCollection.Count != 1) { throw new Bam.Core.Exception("There can be only one application definition"); } // TODO: convert to var foreach (string absolutePath in sourceCollection) { if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Application definition file '{0}' does not exist", absolutePath); } var csPath = absolutePath + ".cs"; if (!System.IO.File.Exists(csPath)) { throw new Bam.Core.Exception("Associated source file '{0}' to application definition file '{1}' does not exist", csPath, absolutePath); } sourceFiles.Add(csPath); } } else { throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString()); } } } // WPF page .xaml files { var xamlFileAttributes = field.GetCustomAttributes(typeof(CSharp.PagesAttribute), false); if (null != xamlFileAttributes && xamlFileAttributes.Length > 0) { var sourceField = field.GetValue(moduleToBuild); if (sourceField is Bam.Core.Location) { var file = sourceField as Bam.Core.Location; var absolutePath = file.GetSinglePath(); if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Page file '{0}' does not exist", absolutePath); } var csPath = absolutePath + ".cs"; if (!System.IO.File.Exists(csPath)) { throw new Bam.Core.Exception("Associated source file '{0}' to page file '{1}' does not exist", csPath, absolutePath); } sourceFiles.Add(csPath); } else if (sourceField is Bam.Core.FileCollection) { var sourceCollection = sourceField as Bam.Core.FileCollection; if (sourceCollection.Count != 1) { throw new Bam.Core.Exception("There can be only one page file"); } // TODO: convert to var foreach (string absolutePath in sourceCollection) { if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Page file '{0}' does not exist", absolutePath); } var csPath = absolutePath + ".cs"; if (!System.IO.File.Exists(csPath)) { throw new Bam.Core.Exception("Associated source file '{0}' to page file '{1}' does not exist", csPath, absolutePath); } sourceFiles.Add(csPath); } } else { throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString()); } } } } if (0 == sourceFiles.Count) { throw new Bam.Core.Exception("There were no source files specified for the module '{0}'", node.ModuleName); } // dependency checking { var inputLocations = new Bam.Core.LocationArray(); foreach (var source in sourceFiles) { inputLocations.Add(Bam.Core.FileLocation.Get(source)); } var outputLocations = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.File, Bam.Core.Location.EExists.WillExist); if (!RequiresBuilding(outputLocations, inputLocations)) { Bam.Core.Log.DebugMessage("'{0}' is up-to-date", node.UniqueModuleName); success = true; return null; } } // at this point, we know the node outputs need building // create all directories required var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist); foreach (var dir in dirsToCreate) { var dirPath = dir.GetSinglePath(); NativeBuilder.MakeDirectory(dirPath); } var commandLineBuilder = new Bam.Core.StringArray(); if (options is CommandLineProcessor.ICommandLineSupport) { var commandLineOption = options as CommandLineProcessor.ICommandLineSupport; commandLineOption.ToCommandLineArguments(commandLineBuilder, target, null); } else { throw new Bam.Core.Exception("Compiler options does not support command line translation"); } foreach (var source in sourceFiles) { if (source.Contains(" ")) { commandLineBuilder.Add(System.String.Format("\"{0}\"", source)); } else { commandLineBuilder.Add(source); } } var compilerTool = target.Toolset.Tool(typeof(CSharp.ICSharpCompilerTool)); var exitCode = CommandLineProcessor.Processor.Execute(node, compilerTool, commandLineBuilder); success = (0 == exitCode); return null; }
public object Build( CSharp.Assembly moduleToBuild, out System.Boolean success) { var assemblyModule = moduleToBuild as Bam.Core.BaseModule; var node = assemblyModule.OwningNode; var target = node.Target; var assemblyOptions = assemblyModule.Options; var options = assemblyOptions as CSharp.OptionCollection; var inputVariables = new MakeFileVariableDictionary(); if (node.ExternalDependents != null) { foreach (var dependentNode in node.ExternalDependents) { if (null != dependentNode.Data) { continue; } var keyFilters = new Bam.Core.Array<Bam.Core.LocationKey>( CSharp.Assembly.OutputFile ); var assemblyLocations = new Bam.Core.LocationArray(); dependentNode.FilterOutputLocations(keyFilters, assemblyLocations); var data = dependentNode.Data as MakeFileData; var csharpOptions = options as CSharp.IOptions; foreach (var loc in assemblyLocations) { csharpOptions.References.Add(loc.GetSinglePath()); inputVariables.Add(CSharp.Assembly.OutputFile, data.VariableDictionary[CSharp.Assembly.OutputDir]); } } } var sourceFiles = new Bam.Core.StringArray(); var fields = moduleToBuild.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic); foreach (var field in fields) { // C# files { var sourceFileAttributes = field.GetCustomAttributes(typeof(Bam.Core.SourceFilesAttribute), false); if (null != sourceFileAttributes && sourceFileAttributes.Length > 0) { var sourceField = field.GetValue(moduleToBuild); if (sourceField is Bam.Core.Location) { var file = sourceField as Bam.Core.Location; var absolutePath = file.GetSinglePath(); if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Source file '{0}' does not exist", absolutePath); } sourceFiles.Add(absolutePath); } else if (sourceField is Bam.Core.FileCollection) { var sourceCollection = sourceField as Bam.Core.FileCollection; // TODO: convert to var foreach (Bam.Core.Location location in sourceCollection) { var absolutePath = location.GetSinglePath(); if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Source file '{0}' does not exist", absolutePath); } sourceFiles.Add(absolutePath); } } else { throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString()); } } } // WPF application definition .xaml file { var xamlFileAttributes = field.GetCustomAttributes(typeof(CSharp.ApplicationDefinitionAttribute), false); if (null != xamlFileAttributes && xamlFileAttributes.Length > 0) { var sourceField = field.GetValue(moduleToBuild); if (sourceField is Bam.Core.Location) { var file = sourceField as Bam.Core.Location; var absolutePath = file.GetSinglePath(); if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Application definition file '{0}' does not exist", absolutePath); } var csPath = absolutePath + ".cs"; if (!System.IO.File.Exists(csPath)) { throw new Bam.Core.Exception("Associated source file '{0}' to application definition file '{1}' does not exist", csPath, absolutePath); } sourceFiles.Add(csPath); } else if (sourceField is Bam.Core.FileCollection) { var sourceCollection = sourceField as Bam.Core.FileCollection; if (sourceCollection.Count != 1) { throw new Bam.Core.Exception("There can be only one application definition"); } // TODO: convert to var foreach (string absolutePath in sourceCollection) { if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Application definition file '{0}' does not exist", absolutePath); } var csPath = absolutePath + ".cs"; if (!System.IO.File.Exists(csPath)) { throw new Bam.Core.Exception("Associated source file '{0}' to application definition file '{1}' does not exist", csPath, absolutePath); } sourceFiles.Add(csPath); } } else { throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString()); } } } // WPF page .xaml files { var xamlFileAttributes = field.GetCustomAttributes(typeof(CSharp.PagesAttribute), false); if (null != xamlFileAttributes && xamlFileAttributes.Length > 0) { var sourceField = field.GetValue(moduleToBuild); if (sourceField is Bam.Core.Location) { var file = sourceField as Bam.Core.Location; var absolutePath = file.GetSinglePath(); if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Page file '{0}' does not exist", absolutePath); } var csPath = absolutePath + ".cs"; if (!System.IO.File.Exists(csPath)) { throw new Bam.Core.Exception("Associated source file '{0}' to page file '{1}' does not exist", csPath, absolutePath); } sourceFiles.Add(csPath); } else if (sourceField is Bam.Core.FileCollection) { var sourceCollection = sourceField as Bam.Core.FileCollection; if (sourceCollection.Count != 1) { throw new Bam.Core.Exception("There can be only one page file"); } // TODO: convert to var foreach (string absolutePath in sourceCollection) { if (!System.IO.File.Exists(absolutePath)) { throw new Bam.Core.Exception("Page file '{0}' does not exist", absolutePath); } var csPath = absolutePath + ".cs"; if (!System.IO.File.Exists(csPath)) { throw new Bam.Core.Exception("Associated source file '{0}' to page file '{1}' does not exist", csPath, absolutePath); } sourceFiles.Add(csPath); } } else { throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString()); } } } } if (0 == sourceFiles.Count) { throw new Bam.Core.Exception("There were no source files specified for the module '{0}'", node.ModuleName); } // at this point, we know the node outputs need building // create all directories required var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist); var commandLineBuilder = new Bam.Core.StringArray(); if (options is CommandLineProcessor.ICommandLineSupport) { var commandLineOption = options as CommandLineProcessor.ICommandLineSupport; commandLineOption.ToCommandLineArguments(commandLineBuilder, target, null); } else { throw new Bam.Core.Exception("Compiler options does not support command line translation"); } foreach (var source in sourceFiles) { if (source.Contains(" ")) { commandLineBuilder.Add(System.String.Format("\"{0}\"", source)); } else { commandLineBuilder.Add(source); } } var compilerInstance = target.Toolset.Tool(typeof(CSharp.ICSharpCompilerTool)); var executablePath = compilerInstance.Executable((Bam.Core.BaseTarget)target); var recipes = new Bam.Core.StringArray(); if (executablePath.Contains(" ")) { recipes.Add(System.String.Format("\"{0}\" {1}", executablePath, commandLineBuilder.ToString(' '))); } else { recipes.Add(System.String.Format("{0} {1}", executablePath, commandLineBuilder.ToString(' '))); } var makeFile = new MakeFile(node, this.topLevelMakeFilePath); var rule = new MakeFileRule( moduleToBuild, CSharp.Assembly.OutputFile, node.UniqueModuleName, dirsToCreate, inputVariables, null, recipes); var toolOutputLocKeys = compilerInstance.OutputLocationKeys(moduleToBuild); var outputFileLocations = moduleToBuild.Locations.Keys(Bam.Core.ScaffoldLocation.ETypeHint.File, Bam.Core.Location.EExists.WillExist); var outputFileLocationsOfInterest = outputFileLocations.Intersect(toolOutputLocKeys); rule.OutputLocationKeys = outputFileLocationsOfInterest; makeFile.RuleArray.Add(rule); var makeFilePath = MakeFileBuilder.GetMakeFilePathName(node); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(makeFilePath)); Bam.Core.Log.DebugMessage("Makefile : '{0}'", makeFilePath); using (System.IO.TextWriter makeFileWriter = new System.IO.StreamWriter(makeFilePath)) { makeFile.Write(makeFileWriter); } success = true; var compilerTool = compilerInstance as Bam.Core.ITool; System.Collections.Generic.Dictionary<string, Bam.Core.StringArray> environment = null; if (compilerTool is Bam.Core.IToolEnvironmentVariables) { environment = (compilerTool as Bam.Core.IToolEnvironmentVariables).Variables((Bam.Core.BaseTarget)target); } var returnData = new MakeFileData(makeFilePath, makeFile.ExportedTargets, makeFile.ExportedVariables, environment); return returnData; }
private void CreateBuildActions( System.Xml.XmlDocument doc, System.Xml.XmlElement schemeElement, Target target) { var buildActionEl = doc.CreateElement("BuildAction"); schemeElement.AppendChild(buildActionEl); { buildActionEl.SetAttribute("parallelizeBuildables", "YES"); buildActionEl.SetAttribute("buildImplicitDependencies", "YES"); var buildActionEntries = doc.CreateElement("BuildActionEntries"); buildActionEl.AppendChild(buildActionEntries); var buildActionsCreated = new Bam.Core.Array<Target>(); this.CreateBuildActionEntry(doc, buildActionEntries, target, buildActionsCreated); } }
Write( Bam.Core.Array <QMakeData> array) { var consistentMergeState = true; if (array.Count > 1) { foreach (var data in array) { if (data.Merged != array[0].Merged) { consistentMergeState = false; } } } if (!consistentMergeState) { throw new Bam.Core.Exception("Data is inconsistently merged"); } if (array[0].Merged) { Bam.Core.Log.DebugMessage("Not writing a pro file as qmake data is merged"); return; } var node = array[0].OwningNode; var proFileDirectory = node.GetModuleBuildDirectoryLocation().GetSingleRawPath(); var proFilePath = System.IO.Path.Combine(proFileDirectory, System.String.Format("{0}.pro", node.ModuleName)); if (array[0].Target.Length > 0) { proFilePath = proFilePath.Replace(node.ModuleName, array[0].Target); proFileDirectory = System.IO.Path.GetDirectoryName(proFilePath); } Bam.Core.Log.DebugMessage("QMake Pro File for node '{0}': '{1}'", node.UniqueModuleName, proFilePath); foreach (var data in array) { data.ProFilePath = proFilePath; } // TODO: this might be temporary System.IO.Directory.CreateDirectory(proFileDirectory); using (var proWriter = new System.IO.StreamWriter(proFilePath)) { WritePriPaths(array, proFilePath, proWriter); WriteTemplate(array, proFilePath, proWriter); WriteConfig(array, proFilePath, proWriter); WriteTarget(array, proFilePath, proWriter); WriteDestDir(array, proFilePath, proWriter); WriteMocDir(array, proFilePath, proWriter); WriteObjectsDir(array, proFilePath, proWriter); WriteIncludePaths(array, proFilePath, proWriter); WriteDefines(array, proFilePath, proWriter); WriteCCFlags(array, proFilePath, proWriter); WriteCXXFlags(array, proFilePath, proWriter); WriteSources(array, proFilePath, proWriter); WriteObjectiveSources(array, proFilePath, proWriter); WriteHeaders(array, proFilePath, proWriter); WriteWinRCFiles(array, proFilePath, proWriter); WriteLibraries(array, proFilePath, proWriter); // TODO: WriteExternalLibraries since they have been separated from built libraries by Locations WriteLinkFlags(array, proFilePath, proWriter); WriteRPathDir(array, proFilePath, proWriter); WriteMajorVersionNumber(array, proFilePath, proWriter); WriteMinorVersionNumber(array, proFilePath, proWriter); WritePatchVersionNumber(array, proFilePath, proWriter); WritePostLinkCommands(array, proFilePath, proWriter); WriteCustomPathVariables(array, proFilePath, proWriter); WriteCustomRules(array, proFilePath, proWriter); } }