WriteLocationArrays( Values <Bam.Core.LocationArray> values, string format, string proFilePath, bool verbose, bool useContinuation, bool escaped, System.IO.StreamWriter writer) { var intersect = new Bam.Core.LocationArray(values.Debug.Intersect(values.Release)); WriteLocationArray(intersect, format, proFilePath, verbose, useContinuation, escaped, writer); // see the following for an explanation of this syntax // http://qt-project.org/faq/answer/what_does_the_syntax_configdebugdebugrelease_mean_what_does_the_1st_argumen if (intersect.Count != values.Debug.Count) { var debugOnly = new Bam.Core.LocationArray(values.Debug.Complement(intersect)); WriteLocationArray(debugOnly, "CONFIG(debug,debug|release):" + format, proFilePath, verbose, useContinuation, escaped, writer); } if (intersect.Count != values.Release.Count) { var releaseOnly = new Bam.Core.LocationArray(values.Release.Complement(intersect)); WriteLocationArray(releaseOnly, "CONFIG(release,debug|release):" + format, proFilePath, verbose, useContinuation, escaped, writer); } }
WriteLocationArray( Bam.Core.LocationArray locArray, string format, string proFilePath, System.IO.StreamWriter writer) { WriteLocationArray(locArray, format, proFilePath, false, true, false, writer); }
public object Build( CodeGenTest2.CodeGenModule moduleToBuild, out bool success) { var codeGenModuleModule = moduleToBuild as Bam.Core.BaseModule; var node = codeGenModuleModule.OwningNode; var target = node.Target; var codeGenModuleOptions = codeGenModuleModule.Options; var toolOptions = codeGenModuleOptions as CodeGenTest2.CodeGenOptionCollection; var tool = target.Toolset.Tool(typeof(CodeGenTest2.ICodeGenTool)); // dependency checking { var inputLocations = new Bam.Core.LocationArray( Bam.Core.FileLocation.Get(tool.Executable((Bam.Core.BaseTarget)target), Bam.Core.Location.EExists.WillExist) ); 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 (toolOptions is CommandLineProcessor.ICommandLineSupport) { var commandLineOption = toolOptions as CommandLineProcessor.ICommandLineSupport; commandLineOption.ToCommandLineArguments(commandLineBuilder, target, null); } else { throw new Bam.Core.Exception("CodeGen options does not support command line translation"); } string hostApplication = null; if (target.HasPlatform(Bam.Core.EPlatform.OSX)) { hostApplication = "mono"; } var exitCode = CommandLineProcessor.Processor.Execute(node, tool, commandLineBuilder, hostApplication); success = (0 == exitCode); return null; }
WriteLocationArray( Bam.Core.LocationArray locArray, string format, string proFilePath, bool verbose, bool useContinuation, bool escaped, System.IO.StreamWriter writer) { if (0 == locArray.Count) { return; } else if (1 == locArray.Count) { WriteString(locArray[0].GetSinglePath(), format, proFilePath, verbose, writer); } else { var builder = new System.Text.StringBuilder(); if (useContinuation) { builder.Append(format); foreach (var value in locArray) { if (escaped) { builder.Append(@"$$escape_expand(\n\t)"); } builder.AppendFormat("\\\n\t{0}", FormatPath(value.GetSinglePath(), proFilePath, verbose)); } } else { foreach (var value in locArray) { builder.AppendFormat("{0}{1}", format, FormatPath(value.GetSinglePath(), proFilePath, verbose)); if (escaped) { builder.Append(@"$$escape_expand(\n\t)"); } builder.Append("\n"); } } writer.WriteLine(builder.ToString()); } }
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; }
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; }