ITarPolicy.CreateTarBall( TarBall sender, Bam.Core.ExecutionContext context, Bam.Core.ICommandLineTool compiler, Bam.Core.TokenizedString scriptPath, Bam.Core.TokenizedString outputPath) { var tarPath = outputPath.ToString(); var tarDir = System.IO.Path.GetDirectoryName(tarPath); Bam.Core.IOWrapper.CreateDirectoryIfNotExists(tarDir); var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); commandLine.Add("-c"); commandLine.Add("-v"); commandLine.Add("-T"); commandLine.Add(scriptPath.ToStringQuoteIfNecessary()); commandLine.Add("-f"); commandLine.Add(outputPath.ToStringQuoteIfNecessary()); // tarPath CommandLineProcessor.Processor.Execute(context, compiler, commandLine); }
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 encapsulating = sender.GetEncapsulatingReferencedModule(); var workspace = Bam.Core.Graph.Instance.MetaData as XcodeBuilder.WorkspaceMeta; var target = workspace.EnsureTargetExists(encapsulating); if (encapsulating == sender) { target.SetType(XcodeBuilder.Target.EProductType.Utility); } var configuration = target.GetConfiguration(encapsulating); if (encapsulating == sender) { configuration.SetProductName(Bam.Core.TokenizedString.CreateVerbatim("${TARGET_NAME}")); } var commands = new Bam.Core.StringArray(); commands.Add( System.String.Format( "[[ ! -d {0} ]] && mkdir -p {0}", Bam.Core.IOWrapper.EscapeSpacesInPath(output_directory.ToString()) ) ); var condition_text = new System.Text.StringBuilder(); condition_text.Append("if [[ "); var last_output = expected_output_files.Values.Last(); foreach (var output in expected_output_files.Values) { var output_path = Bam.Core.IOWrapper.EscapeSpacesInPath(output.ToString()); condition_text.AppendFormat("! -e {0} ", output_path); foreach (var input in input_files.Values) { var input_path = Bam.Core.IOWrapper.EscapeSpacesInPath(input.ToString()); condition_text.AppendFormat("|| {1} -nt {0} ", output_path, input_path); } if (output != last_output) { condition_text.AppendFormat("|| "); } } condition_text.AppendLine("]]"); condition_text.AppendLine("then"); var cmd_line = System.String.Format("{0} {1}", executable.ToStringQuoteIfNecessary(), arguments.ToString(' ')); condition_text.AppendLine(System.String.Format("\techo {0}", cmd_line)); condition_text.AppendLine(System.String.Format("\t{0}", cmd_line)); condition_text.AppendLine("fi"); commands.Add(condition_text.ToString()); target.AddPreBuildCommands(commands, configuration); }
IDiskImagePolicy.CreateDMG( DiskImage sender, Bam.Core.ExecutionContext context, Bam.Core.ICommandLineTool compiler, Bam.Core.TokenizedString sourceFolderPath, Bam.Core.TokenizedString outputPath) { var volumeNameTS = sender.CreateTokenizedString("$(OutputName)"); lock (volumeNameTS) { if (!volumeNameTS.IsParsed) { volumeNameTS.Parse(); } } var volumeName = volumeNameTS.ToString(); var tempDiskImagePathName = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString() + ".dmg"; // must have .dmg extension var commandLine = new Bam.Core.StringArray(); (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine); // create the disk image { var settings = sender.Settings as IDiskImageSettings; var args = new Bam.Core.StringArray(); args.Add("create"); args.AddRange(commandLine); args.Add("-srcfolder"); args.Add(System.String.Format("\"{0}\"", sourceFolderPath.ToString())); args.Add("-size"); args.Add(settings.ImageSize); args.Add("-fs"); args.Add("HFS+"); args.Add("-volname"); args.Add(System.String.Format("\"{0}\"", volumeName)); args.Add(tempDiskImagePathName); CommandLineProcessor.Processor.Execute(context, compiler, args); } // mount disk image { var args = new Bam.Core.StringArray(); args.Add("attach"); args.AddRange(commandLine); args.Add(tempDiskImagePathName); CommandLineProcessor.Processor.Execute(context, compiler, args); } // TODO /// do a copy // unmount disk image { var args = new Bam.Core.StringArray(); args.Add("detach"); args.AddRange(commandLine); args.Add(System.String.Format("\"/Volumes/{0}\"", volumeName)); CommandLineProcessor.Processor.Execute(context, compiler, args); } var diskImagePathName = outputPath.ToString(); var dmgDir = System.IO.Path.GetDirectoryName(diskImagePathName); Bam.Core.IOWrapper.CreateDirectoryIfNotExists(dmgDir); // hdiutil convert myimg.dmg -format UDZO -o myoutputimg.dmg // this will fail if the output DMG exists, so always write to a temporary // file and then move into place var tempDMGPath = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString() + ".dmg"; { var args = new Bam.Core.StringArray(); args.Add("convert"); args.AddRange(commandLine); args.Add(tempDiskImagePathName); args.Add("-format"); args.Add("UDZO"); args.Add("-o"); args.Add(tempDMGPath); CommandLineProcessor.Processor.Execute(context, compiler, args); } // move the temporary DMG to the expected location { var args = new Bam.Core.StringArray(); args.Add("-f"); args.Add("-v"); args.Add(tempDMGPath); args.Add(outputPath.ToStringQuoteIfNecessary()); // diskImagePathName CommandLineProcessor.Processor.Execute(context, Bam.Core.OSUtilities.GetInstallLocation("mv").First(), args); } }