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);
            }
        }
Exemplo n.º 2
0
        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)
        {
            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);
            }
        }
Exemplo n.º 4
0
        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)
        {
            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));
        }