Exemplo n.º 1
0
        IAssemblerPolicy.Assemble(
            AssembledObjectFile sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString objectFilePath,
            Bam.Core.Module source)
        {
            var encapsulating = sender.GetEncapsulatingReferencedModule();

            var solution = Bam.Core.Graph.Instance.MetaData as VSSolutionBuilder.VSSolution;
            var project  = solution.EnsureProjectExists(encapsulating);
            var config   = project.GetConfiguration(encapsulating);

            var output = objectFilePath.Parse();

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

            args.Add(CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool));
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args);
            args.Add("%(FullPath)");

            var customBuild = config.GetSettingsGroup(VSSolutionBuilder.VSSettingsGroup.ESettingsGroup.CustomBuild, include: sender.InputPath, uniqueToProject: true);

            customBuild.AddSetting("Command", args.ToString(' '), condition: config.ConditionText);
            customBuild.AddSetting("Message", System.String.Format("Assembling {0}", System.IO.Path.GetFileName(sender.InputPath.Parse())), condition: config.ConditionText);
            customBuild.AddSetting("Outputs", output, condition: config.ConditionText);
            sender.MetaData = customBuild;
        }
Exemplo n.º 2
0
 protected override void ExecuteInternal(
     Bam.Core.ExecutionContext context)
 {
     var sourceFile = this.SourceModule;
     var objectFile = this.GeneratedPaths[Key];
     this.Policy.Assemble(this, context, objectFile, sourceFile);
 }
Exemplo n.º 3
0
        IGeneratedSourcePolicy.GenerateSource(
            GeneratedSourceModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool compiler,
            Bam.Core.TokenizedString generatedFilePath)
        {
            var encapsulating = sender.GetEncapsulatingReferencedModule();

            var workspace     = Bam.Core.Graph.Instance.MetaData as XcodeBuilder.WorkspaceMeta;
            var target        = workspace.EnsureTargetExists(encapsulating);
            var configuration = target.GetConfiguration(encapsulating);

            var command = new System.Text.StringBuilder();
            // recode the executable path for Xcode
            var xcodePath = encapsulating.CreateTokenizedString("$(packagebuilddir)/$(config)").Parse();

            xcodePath += "/" + System.IO.Path.GetFileName(compiler.Executable.Parse());
            command.AppendFormat(xcodePath);
            // TODO: change this to a configuration directory really
            command.AppendFormat(" {0}", Bam.Core.TokenizedString.Create("$(buildroot)", null).Parse());
            command.AppendFormat(" {0}", "Generated");

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

            commands.Add(command.ToString());
            target.AddPreBuildCommands(commands, configuration);

            var compilerTarget = workspace.EnsureTargetExists(compiler as Bam.Core.Module);

            target.Requires(compilerTarget);
        }
Exemplo n.º 4
0
        ICompilationPolicy.Compile(
            ObjectFile sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString objectFilePath,
            Bam.Core.Module source)
        {
            if (!sender.PerformCompilation)
            {
                return;
            }
            if (sender.ReasonToExecute.Reason == Bam.Core.ExecuteReasoning.EReason.DeferredEvaluation)
            {
                if (!DeferredEvaluationRequiresBuild(sender))
                {
                    return;
                }
            }

            var objectFileDir = System.IO.Path.GetDirectoryName(objectFilePath.ToString());

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(objectFileDir);

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

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);
            commandLine.Add(source.GeneratedPaths[SourceFile.Key].ParseAndQuoteIfNecessary());
            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
Exemplo n.º 5
0
        ExecuteInternal(
            Bam.Core.ExecutionContext context)
        {
            var path = this.ScriptPath.ToString();
            var dir  = System.IO.Path.GetDirectoryName(path);

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(dir);
            var outputName = this.GetEncapsulatingReferencedModule().Macros["OutputName"];

            using (var scriptWriter = new System.IO.StreamWriter(path))
            {
                scriptWriter.WriteLine("Name \"{0}\"", outputName.ToString());
                var installedExePath = this.CreateTokenizedString("$(buildroot)/$(config)/$(0).exe", outputName);
                installedExePath.Parse();
                scriptWriter.WriteLine("OutFile \"{0}\"", installedExePath.ToString());
                scriptWriter.WriteLine("InstallDir $APPDATA\\{0}", outputName.ToString());
                scriptWriter.WriteLine("Page directory");
                scriptWriter.WriteLine("Page instfiles");
                scriptWriter.WriteLine("Section \"\"");
                foreach (var dep in this.Files)
                {
                    scriptWriter.WriteLine("\tSetOutPath $INSTDIR");
                    scriptWriter.WriteLine("\tFile {0}", dep.Key.GeneratedPaths[dep.Value].ToStringQuoteIfNecessary());
                }
                foreach (var dep in this.Paths)
                {
                    scriptWriter.WriteLine("\tSetOutPath $INSTDIR");
                    scriptWriter.WriteLine("\tFile /r \"{0}\\*.*\"", dep.Key.GeneratedPaths[dep.Value].ToString());
                }
                scriptWriter.WriteLine("SectionEnd");
            }
        }
Exemplo n.º 6
0
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers)
        {
            var commandLineArgs = new Bam.Core.StringArray();

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs);

            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            rule.AddTarget(libraryPath);
            foreach (var input in objectFiles)
            {
                rule.AddPrerequisite(input, C.ObjectFile.Key);
            }

            var tool    = sender.Tool as Bam.Core.ICommandLineTool;
            var command = new System.Text.StringBuilder();

            command.AppendFormat("{0} {1} $^ {2}",
                                 CommandLineProcessor.Processor.StringifyTool(tool),
                                 commandLineArgs.ToString(' '),
                                 CommandLineProcessor.Processor.TerminatingArgs(tool));
            rule.AddShellCommand(command.ToString());

            var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString());

            meta.CommonMetaData.Directories.AddUnique(libraryFileDir);
            meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables);
        }
Exemplo n.º 7
0
        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
            )
        {
            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(output_directory.ToString());
            var program         = executable.ToStringQuoteIfNecessary();
            var linearised_args = arguments.ToString(' ');

            Bam.Core.Log.Info("Running: {0} {1}", program, linearised_args);
            Bam.Core.OSUtilities.RunExecutable(program, linearised_args);
            foreach (var expected_file in expected_output_files)
            {
                if (!System.IO.File.Exists(expected_file.Value.ToString()))
                {
                    throw new Bam.Core.Exception(
                              "Expected '{0}' to exist (key={1}), but it does not",
                              expected_file.Value.ToString(),
                              expected_file.Key
                              );
                }
            }
        }
Exemplo n.º 8
0
        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);

            if (!System.IO.Directory.Exists(tarDir))
            {
                System.IO.Directory.CreateDirectory(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.Parse());
            commandLine.Add("-f");
            commandLine.Add(tarPath);
            CommandLineProcessor.Processor.Execute(context, compiler, commandLine);
        }
Exemplo n.º 9
0
        IInstallNameToolPolicy.InstallName(
            InstallNameModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString oldName,
            Bam.Core.TokenizedString newName)
        {
            var originalModule = (sender.Source as ICollatedObject).SourceModule;

            if (originalModule == null)
            {
                return;
            }

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

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

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

            // TODO: check what happens for prebuilt modules (there shouldn't be any metadata)

            commands.Add(System.String.Format("{0} {1} {2} {3} {4} {5}",
                                              CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                              commandLine.ToString(' '),
                                              oldName.ToString(),
                                              newName.ToString(),
                                              sender.Source.GeneratedPaths[CollatedObject.Key].ToString(),
                                              CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));

            var target        = originalModule.MetaData as XcodeBuilder.Target;
            var configuration = target.GetConfiguration(originalModule);

            target.AddPostBuildCommands(commands, configuration);
        }
Exemplo n.º 10
0
 ExecuteInternal(
     Bam.Core.ExecutionContext context)
 {
     if (null == this.policy)
     {
         throw new Bam.Core.Exception(
                   "No execution policy for {0} for build mode {1}",
                   this.ToString(),
                   Bam.Core.Graph.Instance.Mode
                   );
     }
     if (null == this.Executable)
     {
         throw new Bam.Core.Exception("No executable was specified for {0}", this.ToString());
     }
     this.policy.GenerateSource(
         this,
         context,
         this.Executable,
         this.Arguments,
         this.OutputDirectory,
         this.InternalExpectedOutputFileDictionary,
         this.InputFiles
         );
 }
        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 solution = Bam.Core.Graph.Instance.MetaData as VSSolutionBuilder.VSSolution;
            var project  = solution.EnsureProjectExists(encapsulating);
            var config   = project.GetConfiguration(encapsulating);

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

            args.Add(System.String.Format("{0} {1}", executable.ToStringQuoteIfNecessary(), arguments.ToString(' ')));

            foreach (var input in input_files.Values)
            {
                config.AddOtherFile(input);
                var customBuild = config.GetSettingsGroup(
                    VSSolutionBuilder.VSSettingsGroup.ESettingsGroup.CustomBuild,
                    include: input,
                    uniqueToProject: true
                    );
                customBuild.AddSetting("Command", args.ToString(' '), condition: config.ConditionText);
                customBuild.AddSetting("Message", System.String.Format("Generating outputs from {0}", input.ToString()), condition: config.ConditionText);
                customBuild.AddSetting("Outputs", expected_output_files.Values, condition: config.ConditionText);
                customBuild.AddSetting("AdditionalInputs", input_files.Values, condition: config.ConditionText);
            }
        }
Exemplo n.º 12
0
        IGeneratedSourcePolicy.GenerateSource(
            GeneratedSourceModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool compiler,
            Bam.Core.TokenizedString generatedFilePath)
        {
            var encapsulating = sender.GetEncapsulatingReferencedModule();

            var solution = Bam.Core.Graph.Instance.MetaData as VSSolutionBuilder.VSSolution;
            var project  = solution.EnsureProjectExists(encapsulating);
            var config   = project.GetConfiguration(encapsulating);

            // TODO: change this to a configuration directory really
            var output_dir = Bam.Core.IOWrapper.EncloseSpaceContainingPathWithDoubleQuotes(Bam.Core.Graph.Instance.BuildRoot);

            var command = new System.Text.StringBuilder();

            command.AppendFormat(compiler.Executable.ToStringQuoteIfNecessary());
            command.AppendFormat(" {0}", output_dir);
            command.AppendFormat(" {0}", "Generated");
            config.AddPreBuildCommand(command.ToString());

            var compilerProject = solution.EnsureProjectExists(compiler as Bam.Core.Module);

            config.RequiresProject(compilerProject);
        }
Exemplo n.º 13
0
        ExecuteInternal(
            Bam.Core.ExecutionContext context)
        {
            var destPath = this.GeneratedPaths[SourceFileKey].ToString();
            var destDir  = System.IO.Path.GetDirectoryName(destPath);

            if (!System.IO.Directory.Exists(destDir))
            {
                System.IO.Directory.CreateDirectory(destDir);
            }
            var stubPath = this.Macros["templateConfig"].ToString();
            var stubText = System.IO.File.ReadAllText(stubPath);

            // TODO: this should be following the rules in Modules/makesetup and Modules/Setup.dist
            // for which modules are static (and thus part of the Python library) and which are shared
            // and separate in the distribution
            // note that you need to read Setup.dist backward, as some modules are mentioned twice
            // and it is the 'topmost' that overrules
            InsertBuiltinModules(ref stubText);
            using (System.IO.TextWriter writeFile = new System.IO.StreamWriter(destPath))
            {
                writeFile.NewLine = "\n";
                writeFile.Write(stubText);
            }
            Bam.Core.Log.MessageAll($"Written '{destPath}'");
        }
Exemplo n.º 14
0
        ExecuteInternal(
            Bam.Core.ExecutionContext context)
        {
            var path = this.ScriptPath.Parse();
            var dir  = System.IO.Path.GetDirectoryName(path);

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(dir);
            var outputName = this.GetEncapsulatingReferencedModule().Macros["OutputName"];

            using (var scriptWriter = new System.IO.StreamWriter(path))
            {
                scriptWriter.WriteLine("[Setup]");
                scriptWriter.WriteLine("OutputBaseFilename={0}", outputName.ParseAndQuoteIfNecessary());
                scriptWriter.WriteLine("OutputDir={0}", this.CreateTokenizedString("@dir($(buildroot)/$(config)/$(0).exe)", outputName).ParseAndQuoteIfNecessary());
                scriptWriter.WriteLine("AppName={0}", outputName.Parse());
                scriptWriter.WriteLine("AppVersion={0}", "1.0"); // TODO: get this from the main app: this.CreateTokenizedString("$(MajorVersion).$(MinorVersion)#valid(.$(PatchVersion))").Parse());
                scriptWriter.WriteLine("DefaultDirName={{userappdata}}\\{0}", outputName.Parse());
                scriptWriter.WriteLine("ArchitecturesAllowed=x64");
                scriptWriter.WriteLine("ArchitecturesInstallIn64BitMode=x64");
                scriptWriter.WriteLine("Uninstallable=No");
                scriptWriter.WriteLine("[Files]");
                foreach (var dep in this.Files)
                {
                    scriptWriter.Write(System.String.Format("Source: \"{0}\"; ", dep.Key.GeneratedPaths[dep.Value]));
                    scriptWriter.Write("DestDir: \"{app}\"; ");
                    scriptWriter.Write("DestName: \"Test\"");
                }
                foreach (var dep in this.Paths)
                {
                    scriptWriter.Write(System.String.Format("Source: \"{0}\\*.*\"; ", dep.Key.GeneratedPaths[dep.Value]));
                    scriptWriter.Write("DestDir: \"{app}\"; ");
                    scriptWriter.Write("Flags: recursesubdirs");
                }
            }
        }
Exemplo n.º 15
0
        ICompilationPolicy.Compile(
            ObjectFile sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString objectFilePath,
            Bam.Core.Module source)
        {
            var commandLineArgs = new Bam.Core.StringArray();

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs);

            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            rule.AddTarget(objectFilePath);
            rule.AddPrerequisite(source, C.SourceFile.Key);

            var tool    = sender.Tool as Bam.Core.ICommandLineTool;
            var command = new System.Text.StringBuilder();

            command.AppendFormat("{0} {1} $< {2}",
                                 CommandLineProcessor.Processor.StringifyTool(tool),
                                 commandLineArgs.ToString(' '),
                                 CommandLineProcessor.Processor.TerminatingArgs(tool));
            rule.AddShellCommand(command.ToString());

            var objectFileDir = System.IO.Path.GetDirectoryName(objectFilePath.ToString());

            meta.CommonMetaData.Directories.AddUnique(objectFileDir);
            meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables);
        }
Exemplo n.º 16
0
        IGeneratedSourcePolicy.GenerateSource(
            GeneratedSourceModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool compiler,
            Bam.Core.TokenizedString generatedFilePath)
        {
            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            rule.AddTarget(generatedFilePath);

            var buildTool = (compiler as Bam.Core.Module).MetaData as MakeFileBuilder.MakeFileMeta;

            rule.AddOrderOnlyDependency(System.String.Format("$({0})", buildTool.Rules[0].Targets[0].VariableName));

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

            // TODO: change this to a configuration directory really
            commandLineArgs.Add(Bam.Core.TokenizedString.Create("$(buildroot)", null).Parse());
            commandLineArgs.Add("Generated");

            var command = new System.Text.StringBuilder();

            command.AppendFormat("{0} {1} $^", compiler.Executable.ParseAndQuoteIfNecessary(), commandLineArgs.ToString(' '));
            rule.AddShellCommand(command.ToString());
        }
Exemplo n.º 17
0
        IZipToolPolicy.Zip(
            ZipModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString zipOutputPath,
            Bam.Core.TokenizedString zipInputPath)
        {
            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            var dir = sender.CreateTokenizedString("@dir($(0))", zipOutputPath);

            dir.Parse();
            meta.CommonMetaData.AddDirectory(dir.ToString());
            rule.AddTarget(zipOutputPath);

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

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

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

            args.Add(System.String.Format("cd {0};", zipInputPath.ToString()));
            args.Add(
                System.String.Format("{0} {1} -o {2} {3} {4}",
                                     CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                     commandLine.ToString(' '),
                                     zipOutputPath.ToString(),
                                     "*",
                                     CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)
                                     )
                );
            rule.AddShellCommand(args.ToString(' '));
        }
Exemplo n.º 18
0
        IZipToolPolicy.Zip(
            ZipModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString zipOutputPath,
            Bam.Core.TokenizedString zipInputPath)
        {
            var zipDir = System.IO.Path.GetDirectoryName(zipOutputPath.ToString());

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(zipDir);

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

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);
            if (sender.Tool is ZipPosix)
            {
                commandLine.Add("-o");
                commandLine.Add(Bam.Core.IOWrapper.EscapeSpacesInPath(zipOutputPath.ToString()));
            }
            else
            {
                commandLine.Add(zipOutputPath.ToStringQuoteIfNecessary());
            }
            commandLine.Add("*");
            CommandLineProcessor.Processor.Execute(
                context,
                sender.Tool as Bam.Core.ICommandLineTool,
                commandLine,
                zipInputPath.ToString()
                );
        }
Exemplo n.º 19
0
        IGeneratedSourcePolicy.GenerateSource(
            GeneratedSourceModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool compiler,
            Bam.Core.TokenizedString generatedFilePath)
        {
            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            rule.AddTarget(generatedFilePath);

            var buildTool = (compiler as Bam.Core.Module).MetaData as MakeFileBuilder.MakeFileMeta;

            rule.AddOrderOnlyDependency(System.String.Format("$({0})", buildTool.Rules[0].FirstTarget.VariableName));

            // TODO: change this to a configuration directory really
            var output_dir = Bam.Core.IOWrapper.EncloseSpaceContainingPathWithDoubleQuotes(Bam.Core.Graph.Instance.BuildRoot);

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

            commandLineArgs.Add(output_dir);
            commandLineArgs.Add("Generated");

            var command = new System.Text.StringBuilder();

            command.AppendFormat("{0} {1} $^", compiler.Executable.ToStringQuoteIfNecessary(), commandLineArgs.ToString(' '));
            rule.AddShellCommand(command.ToString());
        }
Exemplo n.º 20
0
        ExecuteInternal(
            Bam.Core.ExecutionContext context)
        {
            var destPath = this.GeneratedPaths[Key].ToString();
            var destDir  = System.IO.Path.GetDirectoryName(destPath);

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(destDir);
            using (System.IO.TextWriter writeFile = new System.IO.StreamWriter(destPath))
            {
                writeFile.NewLine = "\n";
                var guard = this.GuardString;
                writeFile.WriteLine("/* Procedurally generated by BuildAMation from module {0} */", this.ToString());
                if (null != guard)
                {
                    writeFile.WriteLine("#ifndef {0}", guard);
                    writeFile.WriteLine("#define {0}", guard);
                    writeFile.WriteLine(this.Contents);
                    writeFile.WriteLine("#endif /* {0} */", guard);
                }
                else
                {
                    writeFile.WriteLine(this.Contents);
                }
            }
            Bam.Core.Log.Info("Written procedurally generated header : {0}", destPath);
        }
Exemplo n.º 21
0
        Execute(
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool tool,
            Bam.Core.StringArray commandLine,
            string workingDirectory = null)
        {
            var commandLineArgs = new Bam.Core.StringArray();

            if (tool.InitialArguments != null)
            {
                foreach (var arg in tool.InitialArguments)
                {
                    commandLineArgs.Add(arg.ToString());
                }
            }
            commandLineArgs.AddRange(commandLine);
            if (null != tool.TerminatingArguments)
            {
                foreach (var arg in tool.TerminatingArguments)
                {
                    commandLineArgs.Add(arg.ToString());
                }
            }

            Execute(
                context,
                tool.Executable.ToString(),
                commandLineArgs,
                workingDirectory: workingDirectory,
                inheritedEnvironmentVariables: tool.InheritedEnvironmentVariables,
                addedEnvironmentVariables: tool.EnvironmentVariables,
                useResponseFileOption: tool.UseResponseFileOption);
        }
Exemplo n.º 22
0
        IAssemblerPolicy.Assemble(
            AssembledObjectFile sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString objectFilePath,
            Bam.Core.Module source)
        {
            if (!sender.PerformCompilation)
            {
                return;
            }

            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();
            rule.AddTarget(objectFilePath);
            rule.AddPrerequisite(source, C.SourceFile.Key);

            var outputPath = objectFilePath.Parse();

            var args = new Bam.Core.StringArray();
            args.Add(CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool));
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args);
            args.Add("$<");
            rule.AddShellCommand(args.ToString(' '));

            meta.CommonMetaData.AddDirectory(System.IO.Path.GetDirectoryName(outputPath));
        }
Exemplo n.º 23
0
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers)
        {
            if (sender.ReasonToExecute.Reason == Bam.Core.ExecuteReasoning.EReason.DeferredEvaluation)
            {
                if (!DeferredEvaluationRequiresBuild(sender, objectFiles))
                {
                    return;
                }
            }

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

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString());

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(libraryFileDir);

            foreach (var input in objectFiles)
            {
                if (!(input as C.ObjectFileBase).PerformCompilation)
                {
                    continue;
                }
                commandLine.Add(input.GeneratedPaths[C.ObjectFile.Key].ToString());
            }

            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, 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 meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            rule.AddTarget(expected_output_files.Values.First());
            foreach (var input in input_files.Values)
            {
                rule.AddPrerequisite(input);
            }

            rule.AddShellCommand(
                System.String.Format("{0} {1}", executable.ToStringQuoteIfNecessary(), arguments.ToString(' '))
                );

            meta.CommonMetaData.AddDirectory(output_directory.ToString());
        }
Exemplo n.º 25
0
        IZipToolPolicy.Zip(
            ZipModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString zipOutputPath,
            Bam.Core.TokenizedString zipInputPath)
        {
            var encapsulating = sender.GetEncapsulatingReferencedModule();

            var workspace = Bam.Core.Graph.Instance.MetaData as XcodeBuilder.WorkspaceMeta;
            var target    = workspace.EnsureTargetExists(encapsulating);

            target.EnsureOutputFileReferenceExists(
                zipOutputPath,
                XcodeBuilder.FileReference.EFileType.ZipArchive,
                XcodeBuilder.Target.EProductType.Utility);
            var configuration = target.GetConfiguration(encapsulating);

            configuration.SetProductName(Bam.Core.TokenizedString.CreateVerbatim("PythonZip"));

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

            args.Add(System.String.Format("cd {0} &&", Bam.Core.IOWrapper.EscapeSpacesInPath(zipInputPath.ToString())));
            args.Add(CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool));
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args);
            args.Add(System.String.Format("{0}", Bam.Core.IOWrapper.EscapeSpacesInPath(zipOutputPath.ToString())));
            args.Add("*");
            args.Add("|| true"); // because zip returns 12 (nothing to do) upon success
            args.Add(CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool));
            commands.Add(args.ToString(' '));

            target.AddPreBuildCommands(commands, configuration);
        }
Exemplo n.º 26
0
        IObjCopyToolPolicy.ObjCopy(
            ObjCopyModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString originalPath,
            Bam.Core.TokenizedString copiedPath)
        {
            var mode = (sender.Settings as IObjCopyToolSettings).Mode;

            // if linking debug data, add to the strip
            var meta = (EObjCopyToolMode.AddGNUDebugLink == mode) ? sender.SourceModule.MetaData as MakeFileBuilder.MakeFileMeta : new MakeFileBuilder.MakeFileMeta(sender);
            var rule = (EObjCopyToolMode.AddGNUDebugLink == mode) ? meta.Rules[0] :meta.AddRule();

            if (EObjCopyToolMode.AddGNUDebugLink == mode)
            {
                rule.AddOrderOnlyDependency(copiedPath.Parse());
            }
            else
            {
                meta.CommonMetaData.AddDirectory(sender.CreateTokenizedString("@dir($(0))", copiedPath).Parse());

                var sourceFilename = System.IO.Path.GetFileName(originalPath.Parse());
                rule.AddTarget(copiedPath, variableName: "objcopy_" + sourceFilename);
                rule.AddPrerequisite(originalPath);
            }

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

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            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)));
        }
Exemplo n.º 27
0
        IStripToolPolicy.Strip(
            StripModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString originalPath,
            Bam.Core.TokenizedString copiedPath)
        {
            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            var sourceFilename = System.IO.Path.GetFileName(originalPath.Parse());

            meta.CommonMetaData.Directories.AddUnique(sender.CreateTokenizedString("@dir($(0))", copiedPath).Parse());
            rule.AddTarget(copiedPath, variableName: "strip_" + sourceFilename);

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

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            rule.AddShellCommand(System.String.Format("{0} {1} {2} -o {3} {4}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      originalPath.Parse(),
                                                      copiedPath.Parse(),
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
        }
Exemplo n.º 28
0
        IArchivingPolicy.Archive(
            StaticLibrary sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString libraryPath,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection <Bam.Core.Module> headers)
        {
            var commandLine = new Bam.Core.StringArray();

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            var libraryFileDir = System.IO.Path.GetDirectoryName(libraryPath.ToString());

            if (!System.IO.Directory.Exists(libraryFileDir))
            {
                System.IO.Directory.CreateDirectory(libraryFileDir);
            }

            foreach (var input in objectFiles)
            {
                commandLine.Add(input.GeneratedPaths[C.ObjectFile.Key].ToString());
            }

            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
Exemplo n.º 29
0
        ICompilationPolicy.Compile(
            ObjectFile sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString objectFilePath,
            Bam.Core.Module source)
        {
            if (!sender.PerformCompilation)
            {
                return;
            }

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

            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLineArgs);

            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();

            rule.AddTarget(objectFilePath);
            rule.AddPrerequisite(source, C.SourceFile.Key);

            var tool    = sender.Tool as Bam.Core.ICommandLineTool;
            var command = new System.Text.StringBuilder();

            command.AppendFormat("{0} {1} $< {2}",
                                 CommandLineProcessor.Processor.StringifyTool(tool),
                                 commandLineArgs.ToString(' '),
                                 CommandLineProcessor.Processor.TerminatingArgs(tool));
            rule.AddShellCommand(command.ToString());

            var objectFileDir = System.IO.Path.GetDirectoryName(objectFilePath.ToString());

            meta.CommonMetaData.AddDirectory(objectFileDir);
            meta.CommonMetaData.ExtendEnvironmentVariables(tool.EnvironmentVariables);

            // add dependencies, such as procedurally generated headers
            foreach (var dep in sender.Dependents)
            {
                if (null == dep.MetaData)
                {
                    continue;
                }
                if (dep is C.SourceFile)
                {
                    continue;
                }
                var depMeta = dep.MetaData as MakeFileBuilder.MakeFileMeta;
                foreach (var depRule in depMeta.Rules)
                {
                    depRule.ForEachTarget(target =>
                    {
                        if (!target.IsPhony)
                        {
                            rule.AddPrerequisite(target.Path);
                        }
                    });
                }
            }
        }
Exemplo n.º 30
0
 ExecuteInternal(
     Bam.Core.ExecutionContext context)
 {
     if (null != this.Policy)
     {
         this.Policy.CreateDMG(this, context, this.Tool as DiskImageCompiler, this.SourceFolderPath, this.GeneratedPaths[Key]);
     }
 }