IArchivingPolicy.Archive( StaticLibrary sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString libraryPath, System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> objectFiles, System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> headers) { var commandLineArgs = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs); var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(libraryPath); foreach (var input in objectFiles) { rule.AddPrerequisite(input, C.ObjectFile.Key); } var tool = sender.Tool as Bam.Core.ICommandLineTool; var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $^ {2}", CommandLineProcessor.Processor.StringifyTool(tool), commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(command.ToString()); var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString()); meta.CommonMetaData.Directories.AddUnique(libraryFileDir); meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables); }
IGeneratedSourcePolicy.GenerateSource( GeneratedSourceModule sender, Bam.Core.ExecutionContext context, Bam.Core.ICommandLineTool compiler, Bam.Core.TokenizedString generatedFilePath) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(generatedFilePath); var buildTool = (compiler as Bam.Core.Module).MetaData as MakeFileBuilder.MakeFileMeta; rule.AddOrderOnlyDependency(System.String.Format("$({0})", buildTool.Rules[0].Targets[0].VariableName)); var commandLineArgs = new Bam.Core.StringArray(); // TODO: change this to a configuration directory really commandLineArgs.Add(Bam.Core.TokenizedString.Create("$(buildroot)", null).Parse()); commandLineArgs.Add("Generated"); var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $^", compiler.Executable.ParseAndQuoteIfNecessary(), commandLineArgs.ToString(' ')); rule.AddShellCommand(command.ToString()); }
IExternalSourceGeneratorPolicy.GenerateSource( ExternalSourceGenerator sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString executable, Bam.Core.TokenizedStringArray arguments, Bam.Core.TokenizedString output_directory, System.Collections.Generic.IReadOnlyDictionary <string, Bam.Core.TokenizedString> expected_output_files, System.Collections.Generic.IReadOnlyDictionary <string, Bam.Core.TokenizedString> input_files ) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(expected_output_files.Values.First()); foreach (var input in input_files.Values) { rule.AddPrerequisite(input); } rule.AddShellCommand( System.String.Format("{0} {1}", executable.ToStringQuoteIfNecessary(), arguments.ToString(' ')) ); meta.CommonMetaData.AddDirectory(output_directory.ToString()); }
IGeneratedSourcePolicy.GenerateSource( GeneratedSourceModule sender, Bam.Core.ExecutionContext context, Bam.Core.ICommandLineTool compiler, Bam.Core.TokenizedString generatedFilePath) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(generatedFilePath); var buildTool = (compiler as Bam.Core.Module).MetaData as MakeFileBuilder.MakeFileMeta; rule.AddOrderOnlyDependency(System.String.Format("$({0})", buildTool.Rules[0].FirstTarget.VariableName)); // TODO: change this to a configuration directory really var output_dir = Bam.Core.IOWrapper.EncloseSpaceContainingPathWithDoubleQuotes(Bam.Core.Graph.Instance.BuildRoot); var commandLineArgs = new Bam.Core.StringArray(); commandLineArgs.Add(output_dir); commandLineArgs.Add("Generated"); var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $^", compiler.Executable.ToStringQuoteIfNecessary(), commandLineArgs.ToString(' ')); rule.AddShellCommand(command.ToString()); }
ISharedObjectSymbolicLinkPolicy.Symlink( SharedObjectSymbolicLink sender, Bam.Core.ExecutionContext context, Bam.Core.PreBuiltTool tool, ConsoleApplication target) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); // since this is not a referenced type, need to specify a variable name for the MakeFile var variableName = new System.Text.StringBuilder(); variableName.Append(target.GetType().Name); // this is what it's building the symlink for variableName.Append("_"); variableName.Append(sender.Macros["SymlinkUsage"].ToString()); // intended usage rule.AddTarget(sender.GeneratedPaths[SharedObjectSymbolicLink.Key], variableName: variableName.ToString()); rule.AddPrerequisite(target, C.ConsoleApplication.Key); var commandLineArgs = new Bam.Core.StringArray(); commandLineArgs.Add("-s"); commandLineArgs.Add("-f"); var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $(notdir $<) $@ {2}", CommandLineProcessor.Processor.StringifyTool(tool), commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(command.ToString()); }
IZipToolPolicy.Zip( ZipModule sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString zipOutputPath, Bam.Core.TokenizedString zipInputPath) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); var dir = sender.CreateTokenizedString("@dir($(0))", zipOutputPath); dir.Parse(); meta.CommonMetaData.AddDirectory(dir.ToString()); rule.AddTarget(zipOutputPath); var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); var args = new Bam.Core.StringArray(); args.Add(System.String.Format("cd {0};", zipInputPath.ToString())); args.Add( System.String.Format("{0} {1} -o {2} {3} {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), zipOutputPath.ToString(), "*", CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool) ) ); rule.AddShellCommand(args.ToString(' ')); }
ICompilationPolicy.Compile( ObjectFile sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString objectFilePath, Bam.Core.Module source) { var commandLineArgs = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs); var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(objectFilePath); rule.AddPrerequisite(source, C.SourceFile.Key); var tool = sender.Tool as Bam.Core.ICommandLineTool; var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $< {2}", CommandLineProcessor.Processor.StringifyTool(tool), commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(command.ToString()); var objectFileDir = System.IO.Path.GetDirectoryName(objectFilePath.ToString()); meta.CommonMetaData.Directories.AddUnique(objectFileDir); meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables); }
IAssemblerPolicy.Assemble( AssembledObjectFile sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString objectFilePath, Bam.Core.Module source) { if (!sender.PerformCompilation) { return; } var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(objectFilePath); rule.AddPrerequisite(source, C.SourceFile.Key); var outputPath = objectFilePath.Parse(); var args = new Bam.Core.StringArray(); args.Add(CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool)); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args); args.Add("$<"); rule.AddShellCommand(args.ToString(' ')); meta.CommonMetaData.AddDirectory(System.IO.Path.GetDirectoryName(outputPath)); }
IArchivingPolicy.Archive( StaticLibrary sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString libraryPath, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers) { var commandLineArgs = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs); var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(libraryPath); foreach (var input in objectFiles) { rule.AddPrerequisite(input, C.ObjectFile.Key); } var tool = sender.Tool as Bam.Core.ICommandLineTool; var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $^ {2}", CommandLineProcessor.Processor.StringifyTool(tool), commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(command.ToString()); var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString()); meta.CommonMetaData.Directories.AddUnique(libraryFileDir); meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables); }
IStripToolPolicy.Strip( StripModule sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString originalPath, Bam.Core.TokenizedString copiedPath) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); var sourceFilename = System.IO.Path.GetFileName(originalPath.Parse()); meta.CommonMetaData.Directories.AddUnique(sender.CreateTokenizedString("@dir($(0))", copiedPath).Parse()); rule.AddTarget(copiedPath, variableName: "strip_" + sourceFilename); var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); rule.AddShellCommand(System.String.Format("{0} {1} {2} -o {3} {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), originalPath.Parse(), copiedPath.Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); }
ICompilationPolicy.Compile( ObjectFile sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString objectFilePath, Bam.Core.Module source) { if (!sender.PerformCompilation) { return; } var commandLineArgs = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs); var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(objectFilePath); rule.AddPrerequisite(source, C.SourceFile.Key); var tool = sender.Tool as Bam.Core.ICommandLineTool; var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $< {2}", CommandLineProcessor.Processor.StringifyTool(tool), commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(command.ToString()); var objectFileDir = System.IO.Path.GetDirectoryName(objectFilePath.ToString()); meta.CommonMetaData.AddDirectory(objectFileDir); meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables); // add dependencies, such as procedurally generated headers foreach (var dep in sender.Dependents) { if (null == dep.MetaData) { continue; } if (dep is C.SourceFile) { continue; } var depMeta = dep.MetaData as MakeFileBuilder.MakeFileMeta; foreach (var depRule in depMeta.Rules) { depRule.ForEachTarget(target => { if (!target.IsPhony) { rule.AddPrerequisite(target.Path); } }); } } }
ICollationPolicy.Collate( Collation sender, Bam.Core.ExecutionContext context) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(Bam.Core.TokenizedString.CreateVerbatim("publish"), isPhony: true); foreach (var required in sender.Requirements) { var requiredMeta = required.MetaData as MakeFileBuilder.MakeFileMeta; if (null == requiredMeta) { continue; } foreach (var rules in requiredMeta.Rules) { // TODO: only the first? rule.AddPrerequisite(rules.Targets[0]); } } }
void IGeneratedSourcePolicy.GenerateSource( GeneratedSourceModule sender, Bam.Core.ExecutionContext context, Bam.Core.ICommandLineTool compiler, Bam.Core.TokenizedString generatedFilePath) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(generatedFilePath); var buildTool = (compiler as Bam.Core.Module).MetaData as MakeFileBuilder.MakeFileMeta; rule.AddOrderOnlyDependency(System.String.Format("$({0})", buildTool.Rules[0].Targets[0].VariableName)); var commandLineArgs = new Bam.Core.StringArray(); // TODO: change this to a configuration directory really commandLineArgs.Add(Bam.Core.TokenizedString.Create("$(buildroot)", null).Parse()); commandLineArgs.Add("Generated"); var command = new System.Text.StringBuilder(); command.AppendFormat("{0} {1} $^", compiler.Executable.ParseAndQuoteIfNecessary(), commandLineArgs.ToString(' ')); rule.AddShellCommand(command.ToString()); }
IProceduralHeaderFromToolOutputPolicy.HeaderFromToolOutput( ProceduralHeaderFileFromToolOutput sender, ExecutionContext context, TokenizedString outputPath, ICommandLineTool tool) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(outputPath); rule.AddPrerequisite(tool.Executable); var args = new Bam.Core.StringArray(); args.Add("$< > $@"); rule.AddShellCommand(args.ToString(' ')); var outputDir = System.IO.Path.GetDirectoryName(outputPath.Parse()); meta.CommonMetaData.AddDirectory(outputDir); }
IStrippedBinaryCollationPolicy.CollateStrippedBinaries( StrippedBinaryCollation sender, Bam.Core.ExecutionContext context) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(Bam.Core.TokenizedString.CreateVerbatim("publish_stripped_binaries"), isPhony: true); foreach (var dep in sender.Dependents) { var depMeta = dep.MetaData as MakeFileBuilder.MakeFileMeta; if (null == depMeta) { continue; } foreach (var rules in depMeta.Rules) { // TODO: only the first? rule.AddPrerequisite(rules.Targets[0]); } } }
void IRccGenerationPolicy.Rcc( RccGeneratedSource sender, Bam.Core.ExecutionContext context, Bam.Core.ICommandLineTool rccCompiler, Bam.Core.TokenizedString generatedRccSource, QRCFile source) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(generatedRccSource); rule.AddPrerequisite(source, C.HeaderFile.Key); var rccOutputPath = generatedRccSource.Parse(); var rccOutputDir = System.IO.Path.GetDirectoryName(rccOutputPath); var args = new Bam.Core.StringArray(); args.Add(CommandLineProcessor.Processor.StringifyTool(rccCompiler)); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args); args.Add(System.String.Format("-o {0}", rccOutputPath)); args.Add(source.InputPath.Parse()); rule.AddShellCommand(args.ToString(' ')); meta.CommonMetaData.Directories.AddUnique(rccOutputDir); }
ILinkingPolicy.Link( ConsoleApplication sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString executablePath, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> libraries) { // any libraries added prior to here, need to be moved to the end // they are external dependencies, and thus all built modules (to be added now) may have // a dependency on them (and not vice versa) var linker = sender.Settings as C.ICommonLinkerSettings; var externalLibs = linker.Libraries; linker.Libraries = new Bam.Core.StringArray(); foreach (var library in libraries) { (sender.Tool as C.LinkerTool).ProcessLibraryDependency(sender as CModule, library as CModule); } linker.Libraries.AddRange(externalLibs); var commandLineArgs = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs); var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(executablePath); string objExt = null; // try to get the object file extension from a compiled source file foreach (var module in objectFiles) { if (null == objExt) { objExt = module.Tool.Macros["objext"].ToString(); } if (!(module as C.ObjectFileBase).PerformCompilation) { continue; } rule.AddPrerequisite(module, C.ObjectFile.Key); } foreach (var module in libraries) { if (module is StaticLibrary) { rule.AddPrerequisite(module, C.StaticLibrary.Key); } else if (module is IDynamicLibrary) { var dynLib = module as IDynamicLibrary; if (dynLib.LinkerNameSymbolicLink != null) { var linkerNameSymLink = dynLib.LinkerNameSymbolicLink; rule.AddPrerequisite(linkerNameSymLink, C.SharedObjectSymbolicLink.Key); } else { rule.AddPrerequisite(module, C.DynamicLibrary.Key); } } else if (module is CSDKModule) { continue; } else if (module is OSXFramework) { continue; } else if (module is HeaderLibrary) { continue; } else { throw new Bam.Core.Exception("Unknown module library type: {0}", module.GetType()); } } var tool = sender.Tool as Bam.Core.ICommandLineTool; var commands = new System.Text.StringBuilder(); // if there were no object files, you probably intended to use all prerequisites anyway var filter = (null != objExt) ? System.String.Format("$(filter %{0},$^)", objExt) : "$^"; commands.AppendFormat("{0} {1} {2} {3}", CommandLineProcessor.Processor.StringifyTool(tool), filter, commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(commands.ToString()); var executableDir = System.IO.Path.GetDirectoryName(executablePath.ToString()); meta.CommonMetaData.AddDirectory(executableDir); meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables); }
ILinkingPolicy.Link( ConsoleApplication sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString executablePath, System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> objectFiles, System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> headers, System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> libraries, System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> frameworks) { // any libraries added prior to here, need to be moved to the end // they are external dependencies, and thus all built modules (to be added now) may have // a dependency on them (and not vice versa) var linker = sender.Settings as C.ICommonLinkerSettings; var externalLibs = linker.Libraries; linker.Libraries = new Bam.Core.StringArray(); foreach (var library in libraries) { (sender.Tool as C.LinkerTool).ProcessLibraryDependency(sender as CModule, library as CModule); } linker.Libraries.AddRange(externalLibs); var commandLineArgs = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs); var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(executablePath); foreach (var module in objectFiles) { rule.AddPrerequisite(module, C.ObjectFile.Key); } foreach (var module in libraries) { if (module is StaticLibrary) { rule.AddPrerequisite(module, C.StaticLibrary.Key); } else if (module is IDynamicLibrary) { if (module.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Windows)) { rule.AddPrerequisite(module, C.DynamicLibrary.ImportLibraryKey); } else { rule.AddPrerequisite(module, C.DynamicLibrary.Key); } } else if (module is CSDKModule) { continue; } else if (module is OSXFramework) { continue; } else { throw new Bam.Core.Exception("Unknown module library type: {0}", module.GetType()); } } var tool = sender.Tool as Bam.Core.ICommandLineTool; var commands = new System.Text.StringBuilder(); commands.AppendFormat("{0} $^ {1} {2}", CommandLineProcessor.Processor.StringifyTool(tool), commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(commands.ToString()); var executableDir = System.IO.Path.GetDirectoryName(executablePath.ToString()); meta.CommonMetaData.Directories.AddUnique(executableDir); meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables); }
ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); var sourcePath = sender.SourcePath; var sourceFilename = System.IO.Path.GetFileName(sourcePath.Parse()); var topLevel = sender.GetEncapsulatingReferencedModule().GetType().Name; var senderType = sender.GetType().Name; var sourceType = (null != sender.SourceModule) ? sender.SourceModule.GetType().FullName : "publishroot"; var basename = sourceType + "_" + topLevel + "_" + senderType + "_" + sender.BuildEnvironment.Configuration.ToString() + "_"; var isSymLink = sender is CollatedSymbolicLink; var isDir = sender is CollatedDirectory; var isRenamedDir = sender.Tool is CopyFilePosix & sender.Macros["CopiedFilename"].IsAliased; if (isSymLink) { rule.AddTarget(sender.GeneratedPaths[CollatedObject.Key], variableName: basename + sourceFilename, isPhony: true); } else { if (isDir) { if (isRenamedDir) { var rename = sender.Macros["CopiedFilename"].Parse(); rule.AddTarget(Bam.Core.TokenizedString.CreateVerbatim(basename + rename), isPhony: true); } else { var targetName = sender.CreateTokenizedString("$(0)/@filename($(1))", sender.Macros["CopyDir"], sourcePath); rule.AddTarget(targetName, variableName: basename + sourceFilename); } } else { rule.AddTarget(sender.GeneratedPaths[CollatedObject.Key], variableName: basename + sourceFilename); } } meta.CommonMetaData.Directories.AddUnique(sender.Macros["CopyDir"].Parse()); var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); if (isSymLink) { rule.AddShellCommand(System.String.Format(@"{0} {1} {2} $@ {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sender.Macros["LinkTarget"].Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { if (isDir) { if (isRenamedDir) { rule.AddShellCommand(System.String.Format(@"{0} {1} $</* {2} {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sender.Macros["CopyDir"].Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { rule.AddShellCommand(System.String.Format(@"{0} {1} $< $(dir $@) {2}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } } else { rule.AddShellCommand(System.String.Format(@"{0} {1} $< $(dir $@) {2}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)), ignoreErrors: !(sender as CollatedFile).FailWhenSourceDoesNotExist); } rule.AddPrerequisite(sourcePath); } }
ILinkingPolicy.Link( ConsoleApplication sender, Bam.Core.ExecutionContext context, Bam.Core.TokenizedString executablePath, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> libraries, System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> frameworks) { // any libraries added prior to here, need to be moved to the end // they are external dependencies, and thus all built modules (to be added now) may have // a dependency on them (and not vice versa) var linker = sender.Settings as C.ICommonLinkerSettings; var externalLibs = linker.Libraries; linker.Libraries = new Bam.Core.StringArray(); foreach (var library in libraries) { (sender.Tool as C.LinkerTool).ProcessLibraryDependency(sender as CModule, library as CModule); } linker.Libraries.AddRange(externalLibs); var commandLineArgs = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs); var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); rule.AddTarget(executablePath); foreach (var module in objectFiles) { rule.AddPrerequisite(module, C.ObjectFile.Key); } foreach (var module in libraries) { if (module is StaticLibrary) { rule.AddPrerequisite(module, C.StaticLibrary.Key); } else if (module is IDynamicLibrary) { if (module.BuildEnvironment.Platform.Includes(Bam.Core.EPlatform.Windows)) { rule.AddPrerequisite(module, C.DynamicLibrary.ImportLibraryKey); } else { rule.AddPrerequisite(module, C.DynamicLibrary.Key); } } else if (module is CSDKModule) { continue; } else if (module is OSXFramework) { continue; } else { throw new Bam.Core.Exception("Unknown module library type: {0}", module.GetType()); } } var tool = sender.Tool as Bam.Core.ICommandLineTool; var commands = new System.Text.StringBuilder(); commands.AppendFormat("{0} $^ {1} {2}", CommandLineProcessor.Processor.StringifyTool(tool), commandLineArgs.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(tool)); rule.AddShellCommand(commands.ToString()); var executableDir = System.IO.Path.GetDirectoryName(executablePath.ToString()); meta.CommonMetaData.Directories.AddUnique(executableDir); meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables); }
ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { if (sender.Ignore) { return; } var collatedInterface = sender as ICollatedObject; var copyFileTool = sender.Tool as CopyFileTool; string copySourcePath; string destinationDir; copyFileTool.convertPaths( sender, sender.SourcePath, collatedInterface.PublishingDirectory, out copySourcePath, out destinationDir); if (null == sender.PreExistingSourcePath) { Bam.Core.Log.DebugMessage("** {0}[{1}]:\t'{2}' -> '{3}'", collatedInterface.SourceModule.ToString(), collatedInterface.SourcePathKey.ToString(), copySourcePath, destinationDir); } else { Bam.Core.Log.DebugMessage("** {0}: '{1}' -> '{2}'", sender, copySourcePath, destinationDir); } var meta = new MakeFileBuilder.MakeFileMeta(sender); var rule = meta.AddRule(); var topLevel = sender.GetEncapsulatingReferencedModule().GetType().Name; var senderType = sender.GetType().Name; var sourceType = (null != collatedInterface.SourceModule) ? collatedInterface.SourceModule.GetType().FullName : "publishroot"; var basename = sourceType + "_" + topLevel + "_" + senderType + "_" + sender.BuildEnvironment.Configuration.ToString() + "_"; var sourceFilename = System.IO.Path.GetFileName(sender.SourcePath.ToString()); var isPosixLeafRename = copySourcePath.EndsWith("*"); string prerequisitePath; var destinationPath = sender.GeneratedPaths[CollatedObject.Key]; if (isPosixLeafRename) { sourceFilename = System.String.Format("{0}-to-{1}", sourceFilename, sender.Macros["RenameLeaf"].ToString()); prerequisitePath = System.IO.Path.GetDirectoryName(copySourcePath); // there would be multiple commands for the target directory if this was // added to meta.CommonMetaData rule.AddShellCommand("mkdir -p $@"); } else { prerequisitePath = copySourcePath; meta.CommonMetaData.AddDirectory(destinationDir); } rule.AddTarget(destinationPath, variableName: basename + sourceFilename); var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); if (isPosixLeafRename) { rule.AddShellCommand(System.String.Format(@"{0} {1} $</* $@ {2}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { rule.AddShellCommand(System.String.Format(@"{0} {1} $< $(dir $@) {2}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } rule.AddPrerequisite(Bam.Core.TokenizedString.CreateVerbatim(prerequisitePath)); }