Beispiel #1
0
        IProceduralHeaderFromToolOutputPolicy.HeaderFromToolOutput(
            ProceduralHeaderFileFromToolOutput sender,
            ExecutionContext context,
            TokenizedString outputPath,
            ICommandLineTool tool)
        {
            var toolPath = tool.Executable.ToString();

            CommandLineProcessor.Processor.Execute(context, toolPath);

            var destPath = outputPath.ToString();
            var destDir  = System.IO.Path.GetDirectoryName(destPath);

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(destDir);

            var tempPath = Bam.Core.IOWrapper.CreateTemporaryFile();

            using (System.IO.TextWriter writeFile = new System.IO.StreamWriter(tempPath))
            {
                writeFile.Write(context.OutputStringBuilder.ToString());
            }

            var moveFile = true;

            if (System.IO.File.Exists(destPath))
            {
                // compare contents
                using (System.IO.TextReader existingFile = new System.IO.StreamReader(destPath))
                {
                    var contents  = existingFile.ReadToEnd();
                    var contentsL = contents.Length;
                    var oldL      = context.OutputStringBuilder.ToString().Length;
                    if (contents.Equals(context.OutputStringBuilder.ToString()))
                    {
                        moveFile = false;
                    }
                }
            }
            if (moveFile)
            {
                Bam.Core.Log.Info("Written procedurally generated header : {0}, from the output of {1}", destPath, toolPath);
                System.IO.File.Delete(destPath);
                System.IO.File.Move(tempPath, destPath);
            }
            else
            {
                Bam.Core.Log.Info("{0} contents have not changed", destPath);
                System.IO.File.Delete(tempPath);
            }
            context.OutputStringBuilder.Clear();
        }
        /// <inheritdoc />
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="commandLineTool">An instance of the command-line tool to be used.</param>
        /// <param name="serverUri">The Azure DevOps server's URL</param>
        /// <param name="workingDirectory">The working directory where the operations will take place</param>
        /// <param name="logger">Optional NLog Logger</param>
        /// <param name="performanceConfiguration">Optional Performance Configuration</param>
        public GitToolCommandLine(
            ICommandLineTool commandLineTool,
            Uri serverUri,
            string workingDirectory,
            Logger logger = null,
            PerformanceConfiguration performanceConfiguration = null
            ) : base(logger, performanceConfiguration)
        {
            Validators.AssertIsNotNull(serverUri, nameof(serverUri));
            Validators.AssertIsNotNullOrWhitespace(workingDirectory, nameof(workingDirectory));

            _commandLineTool  = commandLineTool;
            _serverUri        = serverUri;
            _workingDirectory = workingDirectory;
        }
        IProceduralHeaderFromToolOutputPolicy.HeaderFromToolOutput(
            ProceduralHeaderFileFromToolOutput sender,
            ExecutionContext context,
            TokenizedString outputPath,
            ICommandLineTool tool)
        {
            var toolProject = (tool as Bam.Core.Module).MetaData as VSSolutionBuilder.VSProject;
            var toolConfig  = toolProject.GetConfiguration(tool as Bam.Core.Module);

            var output = outputPath.Parse();

            var commands = new Bam.Core.StringArray();

            commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", System.IO.Path.GetDirectoryName(output)));
            commands.Add(System.String.Format("{0} > {1}", CommandLineProcessor.Processor.StringifyTool(tool), output));
            toolConfig.AddPostBuildCommands(commands);

            // alias the tool's project so that inter-project dependencies can be set up
            sender.MetaData = toolProject;
        }
        IProceduralHeaderFromToolOutputPolicy.HeaderFromToolOutput(
            ProceduralHeaderFileFromToolOutput sender,
            ExecutionContext context,
            TokenizedString outputPath,
            ICommandLineTool tool)
        {
            var toolTarget        = (tool as Bam.Core.Module).MetaData as XcodeBuilder.Target;
            var toolConfiguration = toolTarget.GetConfiguration(tool as Bam.Core.Module);

            var output = outputPath.Parse();

            var commands = new Bam.Core.StringArray();

            commands.Add(System.String.Format("[[ ! -d {0} ]] && mkdir -p {0}", System.IO.Path.GetDirectoryName(output)));
            commands.Add(System.String.Format("{0} > {1}", CommandLineProcessor.Processor.StringifyTool(tool), output));
            toolTarget.AddPostBuildCommands(commands, toolConfiguration);

            // alias the tool's target so that inter-target dependencies can be set up
            sender.MetaData = toolTarget;
        }
        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);
        }