ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { var sourcePath = sender.SourcePath; if (null == sender.Reference) { // the main file is not copied anywhere, as we copy required files around it where VS wrote the main file // this is managed by the Collation class, querying the build mode for where publishing is relative to // ignore any subdirectory on this module return; } var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); if (sender.SourceModule != null && sender.SourceModule.MetaData != null) { var destinationPath = sender.Macros["CopyDir"].Parse(); var commands = new Bam.Core.StringArray(); commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", destinationPath)); commands.Add(System.String.Format(@"{0} {1} $(OutputPath)$(TargetFileName) {2} {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), destinationPath, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); var project = sender.SourceModule.MetaData as VSSolutionBuilder.VSProject; var config = project.GetConfiguration(sender.SourceModule); config.AddPostBuildCommands(commands); } else { var commands = new Bam.Core.StringArray(); if (sender is CollatedDirectory) { // Windows XCOPY requires the directory name to be added to the destination, while Posix cp does not commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.ParseAndQuoteIfNecessary(), sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.ParseAndQuoteIfNecessary(), sender.SubDirectory, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } var project = sender.Reference.SourceModule.MetaData as VSSolutionBuilder.VSProject; var config = project.GetConfiguration(sender.Reference.SourceModule); config.AddPostBuildCommands(commands); } }
ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { if (sender is CollatedFile) { if (!(sender as CollatedFile).FailWhenSourceDoesNotExist) { var source = sender.SourcePath.Parse(); if (!System.IO.File.Exists(source)) { Bam.Core.Log.Detail("File {0} cannot be copied as it does not exist. Ignoring.", source); return; } } } var isSymLink = (sender is CollatedSymbolicLink); var sourcePath = isSymLink ? sender.Macros["LinkTarget"] : sender.SourcePath; var destinationPath = isSymLink ? sender.GeneratedPaths[CollatedObject.Key].Parse() : sender.Macros["CopyDir"].Parse(); if (!isSymLink) { // synchronize, so that multiple modules don't try to create the same directories simultaneously lock ((sender.Reference != null) ? sender.Reference : sender) { if (!System.IO.Directory.Exists(destinationPath)) { System.IO.Directory.CreateDirectory(destinationPath); } } } var copySource = sourcePath.ParseAndQuoteIfNecessary(); if (sender is CollatedDirectory && sender.Tool is CopyFilePosix & sender.Macros["CopiedFilename"].IsAliased) { copySource = System.String.Format("{0}/*", copySource); } var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); commandLine.Add(copySource); commandLine.Add(destinationPath); CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine); }
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); } Bam.Core.IOWrapper.CreateDirectoryIfNotExists(destinationDir); var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); commandLine.Add(copyFileTool.escapePath(copySourcePath)); commandLine.Add(copyFileTool.escapePath(destinationDir)); CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine); }
ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { if (sender.Ignore) { return; } var collatedInterface = sender as ICollatedObject; if (sender.IsAnchor && null != collatedInterface.SourceModule) { // since all dependents are copied _beside_ their anchor, the anchor copy is a no-op return; } 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(), copyFileTool.escapePath(copySourcePath), copyFileTool.escapePath(destinationDir)); } else { Bam.Core.Log.DebugMessage("** {0}: '{1}' -> '{2}'", sender, copyFileTool.escapePath(copySourcePath), copyFileTool.escapePath(destinationDir)); } var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); var commands = new Bam.Core.StringArray(); commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", copyFileTool.escapePath(destinationDir))); var arePostBuildCommands = true; Bam.Core.Module sourceModule; if (null != collatedInterface.SourceModule) { sourceModule = collatedInterface.SourceModule; // check for runtime dependencies that won't have projects, use their anchor if (null == sourceModule.MetaData) { sourceModule = collatedInterface.Anchor.SourceModule; } } else { if (null != collatedInterface.Anchor) { // usually preexisting files that are published as part of an executable's distribution // in which case, their anchor is the executable (or a similar binary) sourceModule = collatedInterface.Anchor.SourceModule; } else { if (sender is CollatedPreExistingFile) { sourceModule = (sender as CollatedPreExistingFile).ParentOfCollationModule; // ensure a project exists, as this collation may be visited prior to // the source which invoked it var solution = Bam.Core.Graph.Instance.MetaData as VSSolutionBuilder.VSSolution; solution.EnsureProjectExists(sourceModule); arePostBuildCommands = false; } else { throw new Bam.Core.Exception("No anchor set on '{0}' with source path '{1}'", sender.GetType().ToString(), sender.SourcePath); } } } var project = sourceModule.MetaData as VSSolutionBuilder.VSProject; var config = project.GetConfiguration(sourceModule); commands.Add(System.String.Format(@"{0} {1} {2} {3} {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), copyFileTool.escapePath(copySourcePath), copyFileTool.escapePath(destinationDir), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility && arePostBuildCommands) { config.AddPostBuildCommands(commands); } else { config.AddPreBuildCommands(commands); } }
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); } }
ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { var sourcePath = sender.SourcePath; if (null == sender.Reference) { if ((null != sender.SourceModule.MetaData) || (sender.SourceModule is CollatedObject)) { // the main file is not copied anywhere, as we copy required files around it where Xcode wrote the main file // this is managed by the Collation class, querying the build mode for where publishing is relative to // ignore any subdirectory on this module // convert the executable into an app bundle, if EPublishingType.WindowedApplication has been used as the type if ((sender.SubDirectory != null) && sender.SubDirectory.Parse().Contains(".app/")) { var target = sender.SourceModule.MetaData as XcodeBuilder.Target; target.MakeApplicationBundle(); } return; } else { // the main reference file was a prebuilt - so create a new project to handle copying files var workspace = Bam.Core.Graph.Instance.MetaData as XcodeBuilder.WorkspaceMeta; var target = workspace.EnsureTargetExists(sender.SourceModule); var configuration = target.GetConfiguration(sender.SourceModule); target.Type = XcodeBuilder.Target.EProductType.Utility; configuration.SetProductName(sender.SourceModule.Macros["modulename"]); //Bam.Core.Log.MessageAll("Configuration {0} for {1}", configuration.Name, sender.SourceModule.ToString()); } } var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); var destinationPath = sender.Macros["CopyDir"].Parse(); var commands = new Bam.Core.StringArray(); commands.Add(System.String.Format("[[ ! -d {0} ]] && mkdir -p {0}", destinationPath)); if (sender.SourceModule != null && sender.SourceModule.MetaData != null) { if ((null != sender.Reference) && (null != sender.Reference.SourceModule) && (sender.SourceModule.PackageDefinition == sender.Reference.SourceModule.PackageDefinition) && (null == sender.Reference.SubDirectory) && (sender.SubDirectory.Parse() == ".")) { // special case that the module output is already in the right directory at build return; } var target = sender.SourceModule.MetaData as XcodeBuilder.Target; if (target.Type != XcodeBuilder.Target.EProductType.Utility) { commands.Add(System.String.Format("{0} {1} $CONFIGURATION_BUILD_DIR/$EXECUTABLE_NAME {2} {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), destinationPath, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { commands.Add(System.String.Format("{0} {1} {2} {3} {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.Parse(), destinationPath, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } var configuration = target.GetConfiguration(sender.SourceModule); if (target.Type != XcodeBuilder.Target.EProductType.Utility) { target.AddPostBuildCommands(commands, configuration); } else { target.AddPreBuildCommands(commands, configuration); } } else { var target = sender.Reference.SourceModule.MetaData as XcodeBuilder.Target; var isSymlink = (sender is CollatedSymbolicLink); var destinationFolder = "$CONFIGURATION_BUILD_DIR"; if (sender.Reference != null) { destinationFolder = "$CONFIGURATION_BUILD_DIR/$EXECUTABLE_FOLDER_PATH"; } if (target.Type == XcodeBuilder.Target.EProductType.Utility) { destinationFolder = destinationPath; } if (isSymlink) { commands.Add(System.String.Format("{0} {1} {2} {3}/{4} {5}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sender.Macros["LinkTarget"].Parse(), destinationFolder, sender.CreateTokenizedString("$(0)/@filename($(1))", sender.SubDirectory, sender.SourcePath).Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { if (sender is CollatedDirectory) { var copySource = sourcePath.Parse(); if (sender.Macros["CopiedFilename"].IsAliased) { copySource = System.String.Format("{0}/*", copySource); } commands.Add(System.String.Format("{0} {1} {2} {3}/{4}/ {5}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), copySource, destinationFolder, sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),)", sender.SubDirectory).Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { commands.Add(System.String.Format("{0} {1} {2} {3}/{4}/ {5}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.Parse(), destinationFolder, sender.SubDirectory.Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } } var configuration = target.GetConfiguration(sender.Reference.SourceModule); if (target.Type != XcodeBuilder.Target.EProductType.Utility) { target.AddPostBuildCommands(commands, configuration); } else { target.AddPreBuildCommands(commands, configuration); } } }
void ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { var sourcePath = sender.SourcePath; if (null == sender.Reference) { if ((null != sender.SourceModule.MetaData) || (sender.SourceModule is CollatedObject)) { // the main file is not copied anywhere, as we copy required files around it where VS wrote the main file // this is managed by the Collation class, querying the build mode for where publishing is relative to // ignore any subdirectory on this module // could also be a DebugSymbols or Stripped copy, in which case, ignore it return; } else { // the main reference file was a prebuilt - so create a new project to handle copying files var solution = Bam.Core.Graph.Instance.MetaData as VSSolutionBuilder.VSSolution; var project = solution.EnsureProjectExists(sender.SourceModule); var config = project.GetConfiguration(sender.SourceModule); config.SetType(VSSolutionBuilder.VSProjectConfiguration.EType.Utility); config.SetOutputPath(sender.Macros["CopyDir"]); config.EnableIntermediatePath(); } } var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); if (sender.SourceModule != null && sender.SourceModule.MetaData != null) { var destinationPath = sender.Macros["CopyDir"].Parse(); var project = sender.SourceModule.MetaData as VSSolutionBuilder.VSProject; var config = project.GetConfiguration(sender.SourceModule); var commands = new Bam.Core.StringArray(); commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", destinationPath)); if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility) { commands.Add(System.String.Format(@"{0} {1} $(OutputPath)$(TargetFileName) {2} {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), destinationPath, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); config.AddPostBuildCommands(commands); } else { commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir).\ {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.ParseAndQuoteIfNecessary(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); config.AddPreBuildCommands(commands); } } else { var commands = new Bam.Core.StringArray(); if (sender is CollatedDirectory) { // Windows XCOPY requires the directory name to be added to the destination, while Posix cp does not commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.ParseAndQuoteIfNecessary(), sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.ParseAndQuoteIfNecessary(), sender.SubDirectory, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } var project = sender.Reference.SourceModule.MetaData as VSSolutionBuilder.VSProject; var config = project.GetConfiguration(sender.Reference.SourceModule); if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility) { config.AddPostBuildCommands(commands); } else { config.AddPreBuildCommands(commands); } } }
ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { var sourcePath = sender.SourcePath; if (null == sender.Reference) { if ((null != sender.SourceModule.MetaData) || (sender.SourceModule is CollatedObject)) { // the main file is not copied anywhere, as we copy required files around it where VS wrote the main file // this is managed by the Collation class, querying the build mode for where publishing is relative to // ignore any subdirectory on this module // could also be a DebugSymbols or Stripped copy, in which case, ignore it return; } else { // the main reference file was a prebuilt - so create a new project to handle copying files var solution = Bam.Core.Graph.Instance.MetaData as VSSolutionBuilder.VSSolution; var project = solution.EnsureProjectExists(sender.SourceModule); var config = project.GetConfiguration(sender.SourceModule); config.SetType(VSSolutionBuilder.VSProjectConfiguration.EType.Utility); config.SetOutputPath(sender.Macros["CopyDir"]); config.EnableIntermediatePath(); } } var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); if (sender.SourceModule != null && sender.SourceModule.MetaData != null && VSSolutionBuilder.VSProject.IsBuildable(sender.SourceModule)) { var destinationPath = sender.Macros["CopyDir"].Parse(); var project = sender.SourceModule.MetaData as VSSolutionBuilder.VSProject; var config = project.GetConfiguration(sender.SourceModule); var commands = new Bam.Core.StringArray(); commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", destinationPath)); if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility) { commands.Add(System.String.Format(@"{0} {1} $(OutputPath)$(TargetFileName) {2} {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), destinationPath, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); config.AddPostBuildCommands(commands); } else { commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir).\ {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.ParseAndQuoteIfNecessary(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); config.AddPreBuildCommands(commands); } } else { var commands = new Bam.Core.StringArray(); if (sender is CollatedDirectory) { // Windows XCOPY requires the directory name to be added to the destination, while Posix cp does not commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.ParseAndQuoteIfNecessary(), sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.ParseAndQuoteIfNecessary(), sender.SubDirectory, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } var project = sender.Reference.SourceModule.MetaData as VSSolutionBuilder.VSProject; var config = project.GetConfiguration(sender.Reference.SourceModule); if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility) { config.AddPostBuildCommands(commands); } else { config.AddPreBuildCommands(commands); } } }
ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { var sourcePath = sender.SourcePath; if (null == sender.Reference) { // the main file is not copied anywhere, as we copy required files around it where Xcode wrote the main file // this is managed by the Collation class, querying the build mode for where publishing is relative to // ignore any subdirectory on this module // convert the executable into an app bundle, if EPublishingType.WindowedApplication has been used as the type if ((sender.SubDirectory != null) && sender.SubDirectory.Parse().Contains(".app/")) { var target = sender.SourceModule.MetaData as XcodeBuilder.Target; target.MakeApplicationBundle(); } return; } var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); var destinationPath = sender.Macros["CopyDir"].Parse(); var commands = new Bam.Core.StringArray(); commands.Add(System.String.Format("[[ ! -d {0} ]] && mkdir -p {0}", destinationPath)); if (sender.SourceModule != null && sender.SourceModule.MetaData != null) { if ((null != sender.Reference) && (sender.SourceModule.PackageDefinition == sender.Reference.PackageDefinition) && (null == sender.Reference.SubDirectory) && (sender.SubDirectory.Parse() == ".")) { // special case that the module output is already in the right directory at build return; } commands.Add(System.String.Format("{0} {1} $CONFIGURATION_BUILD_DIR/$EXECUTABLE_NAME {2} {3}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), destinationPath, CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); var target = sender.SourceModule.MetaData as XcodeBuilder.Target; var configuration = target.GetConfiguration(sender.SourceModule); target.AddPostBuildCommands(commands, configuration); } else { var isSymlink = (sender is CollatedSymbolicLink); var destinationFolder = "$CONFIGURATION_BUILD_DIR"; if (sender.Reference != null) { destinationFolder = "$CONFIGURATION_BUILD_DIR/$EXECUTABLE_FOLDER_PATH"; } if (isSymlink) { commands.Add(System.String.Format("{0} {1} {2} {3}/{4} {5}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sender.Macros["LinkTarget"].Parse(), destinationFolder, sender.CreateTokenizedString("$(0)/@filename($(1))", sender.SubDirectory, sender.SourcePath).Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { if (sender is CollatedDirectory) { var copySource = sourcePath.Parse(); if (sender.Macros["CopiedFilename"].IsAliased) { copySource = System.String.Format("{0}/*", copySource); } commands.Add(System.String.Format("{0} {1} {2} {3}/{4}/ {5}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), copySource, destinationFolder, sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } else { commands.Add(System.String.Format("{0} {1} {2} {3}/{4}/ {5}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), sourcePath.Parse(), destinationFolder, sender.SubDirectory.Parse(), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); } } var target = sender.Reference.SourceModule.MetaData as XcodeBuilder.Target; var configuration = target.GetConfiguration(sender.Reference.SourceModule); target.AddPostBuildCommands(commands, configuration); } }
ICollatedObjectPolicy.Collate( CollatedObject sender, Bam.Core.ExecutionContext context) { if (sender.Ignore) { return; } var collatedInterface = sender as ICollatedObject; var arePostBuildCommands = true; Bam.Core.Module sourceModule; if (null != collatedInterface.SourceModule) { sourceModule = collatedInterface.SourceModule; if (null == sourceModule.MetaData) { // this can happen for prebuilt frameworks sourceModule = collatedInterface.Anchor.SourceModule; } } else { if (null != collatedInterface.Anchor) { // usually preexisting files that are published as part of an executable's distribution // in which case, their anchor is the executable (or a similar binary) sourceModule = collatedInterface.Anchor.SourceModule; } else { if (sender is CollatedPreExistingFile) { sourceModule = (sender as CollatedPreExistingFile).ParentOfCollationModule; var workspace = Bam.Core.Graph.Instance.MetaData as XcodeBuilder.WorkspaceMeta; workspace.EnsureTargetExists(sourceModule); arePostBuildCommands = false; } else { throw new Bam.Core.Exception("No anchor set on '{0}' with source path '{1}'", sender.GetType().ToString(), sender.SourcePath); } } } var target = sourceModule.MetaData as XcodeBuilder.Target; if (sender.IsAnchor && (null != collatedInterface.SourceModule)) { if (sender.IsAnchorAnApplicationBundle) { // application bundles are a different output type in Xcode target.MakeApplicationBundle(); } // since all dependents are copied _beside_ their anchor, the anchor copy is a no-op return; } if (sender.IsInAnchorPackage && (null != collatedInterface.SourceModule) && !(collatedInterface.Anchor as CollatedObject).IsAnchorAnApplicationBundle) { // additionally, any module-based dependents in the same package as the anchor do not need copying as they // are built into the right directory (since Xcode module build dirs do not include the module name) return; } 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(), copyFileTool.escapePath(copySourcePath), copyFileTool.escapePath(destinationDir)); } else { Bam.Core.Log.DebugMessage("** {0}: '{1}' -> '{2}'", sender, copyFileTool.escapePath(copySourcePath), copyFileTool.escapePath(destinationDir)); } var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); var commands = new Bam.Core.StringArray(); commands.Add(System.String.Format("[[ ! -d {0} ]] && mkdir -p {0}", copyFileTool.escapePath(destinationDir))); var configuration = target.GetConfiguration(sourceModule); commands.Add(System.String.Format("{0} {1} {2} {3} {4}", CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool), commandLine.ToString(' '), copyFileTool.escapePath(copySourcePath), copyFileTool.escapePath(destinationDir), CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool))); if (!target.isUtilityType && arePostBuildCommands) { target.AddPostBuildCommands(commands, configuration); } else { target.AddPreBuildCommands(commands, configuration); } }
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)); }