IProceduralHeaderFromToolOutputPolicy.HeaderFromToolOutput( ProceduralHeaderFileFromToolOutput sender, ExecutionContext context, TokenizedString outputPath, ICommandLineTool tool) { var toolPath = tool.Executable.Parse(); CommandLineProcessor.Processor.Execute(context, toolPath); var destPath = outputPath.Parse(); var destDir = System.IO.Path.GetDirectoryName(destPath); Bam.Core.IOWrapper.CreateDirectoryIfNotExists(destDir); var tempPath = System.IO.Path.GetTempFileName(); 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); } context.OutputStringBuilder.Clear(); }
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); }