Beispiel #1
0
        void IMocGenerationPolicy.Moc(
            MocGeneratedSource sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool mocCompiler,
            Bam.Core.TokenizedString generatedMocSource,
            C.HeaderFile source)
        {
            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 output = generatedMocSource.Parse();
            var sourcePath = source.InputPath.Parse();

            var commands = new Bam.Core.StringArray();
            commands.Add(System.String.Format("[[ ! -d {0} ]] && mkdir -p {0}", System.IO.Path.GetDirectoryName(output)));

            var args = new Bam.Core.StringArray();
            args.Add(CommandLineProcessor.Processor.StringifyTool(mocCompiler));
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args);
            args.Add(System.String.Format("-o {0}", output));
            args.Add(sourcePath);

            var moc_commandLine = args.ToString(' ');

            commands.Add(System.String.Format("if [[ ! -e {0} || {1} -nt {0} ]]", output, sourcePath));
            commands.Add("then");
            commands.Add(System.String.Format("\techo {0}", moc_commandLine));
            commands.Add(System.String.Format("\t{0}", moc_commandLine));
            commands.Add("fi");

            target.AddPreBuildCommands(commands, configuration);
        }
        ICollatedObjectPolicy.Collate(
            CollatedObject sender,
            Bam.Core.ExecutionContext context)
        {
            var sourcePath = sender.SourcePath;
            if (null == sender.Reference)
            {
                // the main file is not copied anywhere, as we copy required files around it where VS wrote the main file
                // this is managed by the Collation class, querying the build mode for where publishing is relative to
                // ignore any subdirectory on this module
                return;
            }

            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            if (sender.SourceModule != null && sender.SourceModule.MetaData != null)
            {
                var destinationPath = sender.Macros["CopyDir"].Parse();

                var commands = new Bam.Core.StringArray();
                commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", destinationPath));
                commands.Add(System.String.Format(@"{0} {1} $(OutputPath)$(TargetFileName) {2} {3}",
                    CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                    commandLine.ToString(' '),
                    destinationPath,
                    CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));

                var project = sender.SourceModule.MetaData as VSSolutionBuilder.VSProject;
                var config = project.GetConfiguration(sender.SourceModule);
                config.AddPostBuildCommands(commands);
            }
            else
            {
                var commands = new Bam.Core.StringArray();
                if (sender is CollatedDirectory)
                {
                    // Windows XCOPY requires the directory name to be added to the destination, while Posix cp does not
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}",
                        CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                        commandLine.ToString(' '),
                        sourcePath.ParseAndQuoteIfNecessary(),
                        sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(),
                        CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }
                else
                {
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}",
                        CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                        commandLine.ToString(' '),
                        sourcePath.ParseAndQuoteIfNecessary(),
                        sender.SubDirectory,
                        CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }

                var project = sender.Reference.SourceModule.MetaData as VSSolutionBuilder.VSProject;
                var config = project.GetConfiguration(sender.Reference.SourceModule);
                config.AddPostBuildCommands(commands);
            }
        }
Beispiel #3
0
        void IRccGenerationPolicy.Rcc(
            RccGeneratedSource sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool rccCompiler,
            Bam.Core.TokenizedString generatedRccSource,
            QRCFile 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 = generatedRccSource.Parse();

            var args = new Bam.Core.StringArray();
            args.Add(CommandLineProcessor.Processor.StringifyTool(rccCompiler));
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args);
            args.Add(System.String.Format("-o {0}", output));
            args.Add("%(FullPath)");

            config.AddOtherFile(source);

            var customBuild = config.GetSettingsGroup(VSSolutionBuilder.VSSettingsGroup.ESettingsGroup.CustomBuild, include: source.InputPath, uniqueToProject: true);
            customBuild.AddSetting("Command", args.ToString(' '), condition: config.ConditionText);
            customBuild.AddSetting("Message", System.String.Format("Rccing {0}", System.IO.Path.GetFileName(source.InputPath.Parse())), condition: config.ConditionText);
            customBuild.AddSetting("Outputs", output, condition: config.ConditionText);
        }
Beispiel #4
0
 void IGeneratedSourcePolicy.GenerateSource(
     GeneratedSourceModule sender,
     Bam.Core.ExecutionContext context,
     Bam.Core.ICommandLineTool compiler,
     Bam.Core.TokenizedString generatedFilePath)
 {
     var args = new Bam.Core.StringArray();
     // TODO: change this to a configuration directory really
     args.Add(Bam.Core.TokenizedString.Create("$(buildroot)", null).Parse());
     args.Add("Generated");
     CommandLineProcessor.Processor.Execute(context, compiler, args);
 }
 IChangeRPathPolicy.Change(
     ChangeRPathModule sender,
     Bam.Core.ExecutionContext context,
     CollatedFile source,
     string newRPath)
 {
     var commandLine = new Bam.Core.StringArray();
     commandLine.Add("-r");
     commandLine.Add(newRPath);
     commandLine.Add(source.GeneratedPaths[CollatedObject.Key].Parse());
     CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
 }
        IInstallNameToolPolicy.InstallName(
            InstallNameModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString oldName,
            Bam.Core.TokenizedString newName)
        {
            var originalModule = sender.Source.SourceModule;
            if (originalModule == null)
            {
                return;
            }

            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

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

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

                var target = sender.Source.SourceModule.MetaData as XcodeBuilder.Target;
                var configuration = target.GetConfiguration(sender.Source.SourceModule);
                target.AddPostBuildCommands(commands, configuration);
            }
            else
            {
                var destinationFolder = "$CONFIGURATION_BUILD_DIR";
                if (sender.Source.Reference != null)
                {
                    destinationFolder = "$CONFIGURATION_BUILD_DIR/$EXECUTABLE_FOLDER_PATH";
                }

                commands.Add(System.String.Format("{0} {1} {2} {3} {4}/{5} {6}",
                    CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                    commandLine.ToString(' '),
                    oldName.Parse(),
                    newName.Parse(),
                    destinationFolder,
                    sender.Source.CreateTokenizedString("$(0)/@filename($(1))", sender.Source.SubDirectory, sender.Source.SourcePath).Parse(),
                    CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));

                var target = sender.Source.Reference.SourceModule.MetaData as XcodeBuilder.Target;
                var configuration = target.GetConfiguration(sender.Source.Reference.SourceModule);
                target.AddPostBuildCommands(commands, configuration);
            }
        }
Beispiel #7
0
        IInstallNameToolPolicy.InstallName(
            InstallNameModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString oldName,
            Bam.Core.TokenizedString newName)
        {
            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            commandLine.Add(newName.Parse());
            commandLine.Add(sender.Source.GeneratedPaths[CollatedObject.Key].Parse());
            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
Beispiel #8
0
        void 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);
        }
        ICollatedObjectPolicy.Collate(
            CollatedObject sender,
            Bam.Core.ExecutionContext context)
        {
            if (sender is CollatedFile)
            {
                if (!(sender as CollatedFile).FailWhenSourceDoesNotExist)
                {
                    var source = sender.SourcePath.Parse();
                    if (!System.IO.File.Exists(source))
                    {
                        Bam.Core.Log.Detail("File {0} cannot be copied as it does not exist. Ignoring.", source);
                        return;
                    }
                }
            }

            var isSymLink = (sender is CollatedSymbolicLink);
            var sourcePath = isSymLink ? sender.Macros["LinkTarget"] : sender.SourcePath;

            var destinationPath = isSymLink ? sender.GeneratedPaths[CollatedObject.Key].Parse() : sender.Macros["CopyDir"].Parse();

            if (!isSymLink)
            {
                // synchronize, so that multiple modules don't try to create the same directories simultaneously
                lock ((sender.Reference != null) ? sender.Reference : sender)
                {
                    if (!System.IO.Directory.Exists(destinationPath))
                    {
                        System.IO.Directory.CreateDirectory(destinationPath);
                    }
                }
            }

            var copySource = sourcePath.ParseAndQuoteIfNecessary();
            if (sender is CollatedDirectory && sender.Tool is CopyFilePosix & sender.Macros["CopiedFilename"].IsAliased)
            {
                copySource = System.String.Format("{0}/*", copySource);
            }

            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            commandLine.Add(copySource);
            commandLine.Add(destinationPath);
            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
Beispiel #10
0
        public object Build(
            XmlUtilities.XmlModule moduleToBuild,
            out bool success)
        {
            var node = moduleToBuild.OwningNode;

            var xmlLocation = moduleToBuild.Locations[XmlUtilities.XmlModule.OutputFile];
            var xmlPath = xmlLocation.GetSinglePath();
            if (null == xmlPath)
            {
                throw new Bam.Core.Exception("XML output path was not set");
            }

            // dependency checking
            {
                var outputFiles = new Bam.Core.StringArray();
                outputFiles.Add(xmlPath);
                if (!RequiresBuilding(outputFiles, new Bam.Core.StringArray()))
                {
                    Bam.Core.Log.DebugMessage("'{0}' is up-to-date", node.UniqueModuleName);
                    success = true;
                    return null;
                }
            }

            Bam.Core.Log.Info("Writing XML file '{0}'", xmlPath);

            // create all directories required
            var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist);
            foreach (var dir in dirsToCreate)
            {
                var dirPath = dir.GetSinglePath();
                NativeBuilder.MakeDirectory(dirPath);
            }

            // serialize the XML to disk
            var settings = new System.Xml.XmlWriterSettings();
            settings.CheckCharacters = true;
            settings.CloseOutput = true;
            settings.ConformanceLevel = System.Xml.ConformanceLevel.Auto;
            settings.Indent = true;
            settings.IndentChars = new string(' ', 4);
            settings.NewLineChars = "\n";
            settings.NewLineHandling = System.Xml.NewLineHandling.None;
            settings.NewLineOnAttributes = false;
            settings.OmitXmlDeclaration = false;
            settings.Encoding = new System.Text.UTF8Encoding(false); // do not write BOM

            using (var xmlWriter = System.Xml.XmlWriter.Create(xmlPath, settings))
            {
                moduleToBuild.Document.WriteTo(xmlWriter);
                xmlWriter.WriteWhitespace(settings.NewLineChars);
            }

            success = true;
            return null;
        }
Beispiel #11
0
        IStripToolPolicy.Strip(
            StripModule sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString originalPath,
            Bam.Core.TokenizedString strippedPath)
        {
            var strippedDir = System.IO.Path.GetDirectoryName(strippedPath.Parse());
            if (!System.IO.Directory.Exists(strippedDir))
            {
                System.IO.Directory.CreateDirectory(strippedDir);
            }

            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);
            commandLine.Add(originalPath.Parse());
            commandLine.Add(System.String.Format("-o {0}", strippedPath.Parse()));
            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
Beispiel #12
0
        public object Build(
            XmlUtilities.XmlModule moduleToBuild,
            out bool success)
        {
            var isPlist = moduleToBuild is XmlUtilities.OSXPlistModule;
            var locationMap = moduleToBuild.Locations;
            var outputDir = locationMap[XmlUtilities.OSXPlistModule.OutputDir];
            var outputDirPath = outputDir.GetSingleRawPath();

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

            var xmlFileLoc = locationMap[XmlUtilities.XmlModule.OutputFile];
            var xmlFilePath = xmlFileLoc.GetSingleRawPath();

            // write a script that can be invoked by the MakeFile to generate the XML file
            var shellScriptLeafName = isPlist ? "writePList.py" : "writeXMLFile.py";
            var shellScriptLoc = Bam.Core.FileLocation.Get(outputDir, shellScriptLeafName, Bam.Core.Location.EExists.WillExist);
            var shellScriptPath = shellScriptLoc.GetSingleRawPath();
            XmlUtilities.XmlDocumentToPythonScript.Write(moduleToBuild.Document, shellScriptPath, xmlFilePath);

            var node = moduleToBuild.OwningNode;
            var makeFile = new MakeFile(node, this.topLevelMakeFilePath);

            var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist);

            var recipe = new Bam.Core.StringArray();
            recipe.Add(System.String.Format("$(shell python {0})", shellScriptPath));

            var rule = new MakeFileRule(
                moduleToBuild,
                XmlUtilities.XmlModule.OutputFile,
                node.UniqueModuleName,
                dirsToCreate,
                null,
                null,
                recipe);
            rule.OutputLocationKeys = new Bam.Core.Array<Bam.Core.LocationKey>(XmlUtilities.XmlModule.OutputFile);
            makeFile.RuleArray.Add(rule);

            var makeFilePath = MakeFileBuilder.GetMakeFilePathName(node);
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(makeFilePath));

            using (var makeFileWriter = new System.IO.StreamWriter(makeFilePath))
            {
                makeFile.Write(makeFileWriter);
            }

            var exportedTargets = makeFile.ExportedTargets;
            var exportedVariables = makeFile.ExportedVariables;
            var returnData = new MakeFileData(makeFilePath, exportedTargets, exportedVariables, null);
            success = true;
            return returnData;
        }
Beispiel #13
0
 INSISPolicy.CreateInstaller(
     NSISInstaller sender,
     Bam.Core.ExecutionContext context,
     Bam.Core.ICommandLineTool compiler,
     Bam.Core.TokenizedString scriptPath)
 {
     var args = new Bam.Core.StringArray();
     args.Add(scriptPath.Parse());
     CommandLineProcessor.Processor.Execute(context, compiler, args);
 }
Beispiel #14
0
        void IMocGenerationPolicy.Moc(
            MocGeneratedSource sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool mocCompiler,
            Bam.Core.TokenizedString generatedMocSource,
            C.HeaderFile source)
        {
            var mocOutputPath = generatedMocSource.Parse();
            var mocOutputDir = System.IO.Path.GetDirectoryName(mocOutputPath);
            if (!System.IO.Directory.Exists(mocOutputDir))
            {
                System.IO.Directory.CreateDirectory(mocOutputDir);
            }

            var args = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args);
            args.Add(System.String.Format("-o {0}", mocOutputPath));
            args.Add(source.InputPath.Parse());
            CommandLineProcessor.Processor.Execute(context, mocCompiler, args);
        }
Beispiel #15
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);
        }
Beispiel #16
0
        void 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());
        }
Beispiel #17
0
        void IRccGenerationPolicy.Rcc(
            RccGeneratedSource sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool rccCompiler,
            Bam.Core.TokenizedString generatedRccSource,
            QRCFile source)
        {
            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 output = generatedRccSource.Parse();
            var sourcePath = source.InputPath.Parse();

            var commands = new Bam.Core.StringArray();
            commands.Add(System.String.Format("[[ ! -d {0} ]] && mkdir -p {0}", System.IO.Path.GetDirectoryName(output)));

            var args = new Bam.Core.StringArray();
            args.Add(CommandLineProcessor.Processor.StringifyTool(rccCompiler));
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args);
            args.Add(System.String.Format("-o {0}", output));
            args.Add(sourcePath);

            target.EnsureFileOfTypeExists(source.InputPath, XcodeBuilder.FileReference.EFileType.TextFile,
                                          relativePath: target.Project.GetRelativePathToProject(source.InputPath),
                                          explicitType: false);

            var rcc_commandLine = args.ToString(' ');

            commands.Add(System.String.Format("if [[ ! -e {0} || {1} -nt {0} ]]", output, sourcePath));
            commands.Add("then");
            commands.Add(System.String.Format("\techo {0}", rcc_commandLine));
            commands.Add(System.String.Format("\t{0}", rcc_commandLine));
            commands.Add("fi");

            target.AddPreBuildCommands(commands, configuration);
        }
Beispiel #18
0
        void IRccGenerationPolicy.Rcc(
            RccGeneratedSource sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool rccCompiler,
            Bam.Core.TokenizedString generatedRccSource,
            QRCFile source)
        {
            var meta = new MakeFileBuilder.MakeFileMeta(sender);
            var rule = meta.AddRule();
            rule.AddTarget(generatedRccSource);
            rule.AddPrerequisite(source, C.HeaderFile.Key);

            var rccOutputPath = generatedRccSource.Parse();
            var rccOutputDir = System.IO.Path.GetDirectoryName(rccOutputPath);

            var args = new Bam.Core.StringArray();
            args.Add(CommandLineProcessor.Processor.StringifyTool(rccCompiler));
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(args);
            args.Add(System.String.Format("-o {0}", rccOutputPath));
            args.Add(source.InputPath.Parse());
            rule.AddShellCommand(args.ToString(' '));

            meta.CommonMetaData.Directories.AddUnique(rccOutputDir);
        }
Beispiel #19
0
        public object Build(
            XmlUtilities.TextFileModule moduleToBuild,
            out bool success)
        {
            var node = moduleToBuild.OwningNode;

            var outputLoc = moduleToBuild.Locations[XmlUtilities.TextFileModule.OutputFile];
            var outputPath = outputLoc.GetSinglePath();
            if (null == outputPath)
            {
                throw new Bam.Core.Exception("Text output path was not set");
            }

            // dependency checking
            {
                var outputFiles = new Bam.Core.StringArray();
                outputFiles.Add(outputPath);
                if (!RequiresBuilding(outputFiles, new Bam.Core.StringArray()))
                {
                    Bam.Core.Log.DebugMessage("'{0}' is up-to-date", node.UniqueModuleName);
                    success = true;
                    return null;
                }
            }

            Bam.Core.Log.Info("Writing text file '{0}'", outputPath);

            // create all directories required
            var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist);
            foreach (var dir in dirsToCreate)
            {
                var dirPath = dir.GetSinglePath();
                NativeBuilder.MakeDirectory(dirPath);
            }

            using (var writer = new System.IO.StreamWriter(outputPath, false, System.Text.Encoding.ASCII))
            {
                var content = moduleToBuild.Content.ToString();
                writer.Write(content);
            }

            success = true;
            return null;
        }
        IChangeRPathPolicy.Change(
            ChangeRPathModule sender,
            Bam.Core.ExecutionContext context,
            CollatedFile source,
            string newRPath)
        {
            // add another shell command to the rule for copying the file
            var meta = source.MetaData as MakeFileBuilder.MakeFileMeta;
            var rule = meta.Rules[0];

            var commandLine = new Bam.Core.StringArray();
            commandLine.Add("-r");

            rule.AddShellCommand(System.String.Format(@"{0} {1} {2} $@ {3}",
                CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                commandLine.ToString(' '),
                newRPath,
                CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
        }
Beispiel #21
0
        Convert(
            this C.ICOnlyCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.LanguageStandard.HasValue)
            {
                switch (settings.LanguageStandard.Value)
                {
                case C.ELanguageStandard.C89:
                    break;

                case C.ELanguageStandard.C99:
                    commandLine.Add("-std=c99");
                    break;

                default:
                    throw new Bam.Core.Exception("Invalid C language standard, {0}", settings.LanguageStandard.Value.ToString());
                }
            }
        }
        IChangeRPathPolicy.Change(
            ChangeRPathModule sender,
            Bam.Core.ExecutionContext context,
            CollatedFile source,
            string newRPath)
        {
            // add another shell command to the rule for copying the file
            var meta = source.MetaData as MakeFileBuilder.MakeFileMeta;
            var rule = meta.Rules[0];

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

            commandLine.Add("-r");

            rule.AddShellCommand(System.String.Format(@"{0} {1} {2} $@ {3}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      newRPath,
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
        }
Beispiel #23
0
        IAssemblerPolicy.Assemble(
            AssembledObjectFile sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString objectFilePath,
            Bam.Core.Module source)
        {
            if (!sender.PerformCompilation)
            {
                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].ToStringQuoteIfNecessary());
            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
Beispiel #24
0
        ILinkingPolicy.Link(
            ConsoleApplication sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.TokenizedString executablePath,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> objectFiles,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> headers,
            System.Collections.ObjectModel.ReadOnlyCollection<Bam.Core.Module> libraries)
        {
            // any libraries added prior to here, need to be moved to the end
            // they are external dependencies, and thus all built modules (to be added now) may have
            // a dependency on them (and not vice versa)
            var linker = sender.Settings as C.ICommonLinkerSettings;
            var externalLibs = linker.Libraries;
            linker.Libraries = new Bam.Core.StringArray();
            foreach (var library in libraries)
            {
                (sender.Tool as C.LinkerTool).ProcessLibraryDependency(sender as CModule, library as CModule);
            }
            linker.Libraries.AddRange(externalLibs);

            var executableDir = System.IO.Path.GetDirectoryName(executablePath.ToString());
            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(executableDir);

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

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

            // then all options
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            CommandLineProcessor.Processor.Execute(context, sender.Tool as Bam.Core.ICommandLineTool, commandLine);
        }
Beispiel #25
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);
        }
        Convert(
            this VisualCCommon.ICommonCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.NoLogo.HasValue)
            {
                if (settings.NoLogo.Value)
                {
                    commandLine.Add("-nologo");
                }
            }

            if (settings.RuntimeLibrary.HasValue)
            {
                switch (settings.RuntimeLibrary.Value)
                {
                case ERuntimeLibrary.MultiThreaded:
                    commandLine.Add("-MT");
                    break;

                case ERuntimeLibrary.MultiThreadedDebug:
                    commandLine.Add("-MTd");
                    break;

                case ERuntimeLibrary.MultiThreadedDebugDLL:
                    commandLine.Add("-MDd");
                    break;

                case ERuntimeLibrary.MultiThreadedDLL:
                    commandLine.Add("-MD");
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown runtime library, {0}", settings.RuntimeLibrary.Value.ToString());
                }
            }

            if (settings.WarningLevel.HasValue)
            {
                commandLine.Add(System.String.Format("-W{0}", settings.WarningLevel.Value.ToString("D")));
            }
        }
Beispiel #27
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);

            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.Parse());
            commandLine.Add("-f");
            commandLine.Add(tarPath);
            CommandLineProcessor.Processor.Execute(context, compiler, commandLine);
        }
        Convert(
            this C.ICxxOnlyCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.ExceptionHandler.HasValue)
            {
                switch (settings.ExceptionHandler.Value)
                {
                case C.Cxx.EExceptionHandler.Disabled:
                    commandLine.Add("-fno-exceptions");
                    break;

                case C.Cxx.EExceptionHandler.Asynchronous:
                case C.Cxx.EExceptionHandler.Synchronous:
                    commandLine.Add("-fexceptions");
                    break;

                default:
                    throw new Bam.Core.Exception("Unrecognized exception handler option, {0}", settings.ExceptionHandler.Value.ToString());
                }
            }
            if (settings.LanguageStandard.HasValue)
            {
                switch (settings.LanguageStandard.Value)
                {
                case C.Cxx.ELanguageStandard.Cxx98:
                    commandLine.Add("-std=c++98");
                    break;

                case C.Cxx.ELanguageStandard.GnuCxx98:
                    commandLine.Add("-std=gnu++98");
                    break;

                case C.Cxx.ELanguageStandard.Cxx11:
                    commandLine.Add("-std=c++11");
                    break;

                default:
                    throw new Bam.Core.Exception("Invalid C++ language standard, {0}", settings.LanguageStandard.Value.ToString());
                }
            }
            if (settings.StandardLibrary.HasValue)
            {
                switch (settings.StandardLibrary.Value)
                {
                case C.Cxx.EStandardLibrary.NotSet:
                    break;

                case C.Cxx.EStandardLibrary.libstdcxx:
                    commandLine.Add("-stdlib=libstdc++");
                    break;

                case C.Cxx.EStandardLibrary.libcxx:
                    commandLine.Add("-stdlib=libc++");
                    break;

                default:
                    throw new Bam.Core.Exception("Invalid C++ standard library {0}", settings.StandardLibrary.Value.ToString());
                }
            }
        }
Beispiel #29
0
        Convert(
            this ClangCommon.ICommonCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.AllWarnings.HasValue)
            {
                if (settings.AllWarnings.Value)
                {
                    commandLine.Add("-Wall");
                }
                else
                {
                    commandLine.Add("-Wno-all");
                }
            }
            if (settings.ExtraWarnings.HasValue)
            {
                if (settings.ExtraWarnings.Value)
                {
                    commandLine.Add("-Wextra");
                }
                else
                {
                    commandLine.Add("-Wno-extra");
                }
            }
            if (settings.Pedantic.HasValue)
            {
                if (settings.Pedantic.Value)
                {
                    commandLine.Add("-Wpedantic");
                }
                else
                {
                    commandLine.Add("-Wno-pedantic");
                }
            }
            if (settings.Visibility.HasValue)
            {
                switch (settings.Visibility.Value)
                {
                case EVisibility.Default:
                    commandLine.Add("-fvisibility=default");
                    break;

                case EVisibility.Hidden:
                    commandLine.Add("-fvisibility=hidden");
                    break;

                case EVisibility.Internal:
                    commandLine.Add("-fvisibility=internal");
                    break;

                case EVisibility.Protected:
                    commandLine.Add("-fvisibility=protected");
                    break;

                default:
                    throw new Bam.Core.Exception("Unrecognized visibility, {0}", settings.Visibility.Value.ToString());
                }
            }
            if (settings.StrictAliasing.HasValue)
            {
                if (settings.StrictAliasing.Value)
                {
                    commandLine.Add("-fstrict-aliasing");
                }
                else
                {
                    commandLine.Add("-fno-strict-aliasing");
                }
            }
            if (settings.Optimization.HasValue)
            {
                var common_optimization = (settings as C.ICommonCompilerSettings).Optimization;
                if (common_optimization.HasValue && common_optimization.Value != C.EOptimization.Custom)
                {
                    throw new Bam.Core.Exception("Compiler specific optimizations can only be set when the common optimization is C.EOptimization.Custom");
                }

                switch (settings.Optimization.Value)
                {
                case EOptimization.O1:
                    commandLine.Add("-O1");
                    break;

                case EOptimization.O3:
                    commandLine.Add("-O3");
                    break;

                case EOptimization.Ofast:
                    commandLine.Add("-Ofast");
                    break;

                default:
                    throw new Bam.Core.Exception("Unrecognized Clang optimization, {0}", settings.Optimization.Value.ToString());
                }
            }
        }
        Convert(
            this C.ICxxOnlyCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.ExceptionHandler.HasValue)
            {
                switch (settings.ExceptionHandler.Value)
                {
                case C.Cxx.EExceptionHandler.Disabled:
                    commandLine.Add("-fno-exceptions");
                    break;

                case C.Cxx.EExceptionHandler.Asynchronous:
                case C.Cxx.EExceptionHandler.Synchronous:
                    commandLine.Add("-fexceptions");
                    break;

                default:
                    throw new Bam.Core.Exception("Unrecognized exception handler option, {0}", settings.ExceptionHandler.Value.ToString());
                }
            }
            if (settings.EnableRunTimeTypeInfo.HasValue)
            {
                if (settings.EnableRunTimeTypeInfo.Value)
                {
                    commandLine.Add("-frtti");
                }
                else
                {
                    commandLine.Add("-fno-rtti");
                }
            }
            if (settings.LanguageStandard.HasValue)
            {
                switch (settings.LanguageStandard.Value)
                {
                case C.Cxx.ELanguageStandard.Cxx98:
                    commandLine.Add("-std=c++98");
                    break;

                case C.Cxx.ELanguageStandard.GnuCxx98:
                    commandLine.Add("-std=gnu++98");
                    break;

                case C.Cxx.ELanguageStandard.Cxx03:
                    commandLine.Add("-std=c++03");
                    break;

                case C.Cxx.ELanguageStandard.GnuCxx03:
                    commandLine.Add("-std=gnu++03");
                    break;

                case C.Cxx.ELanguageStandard.Cxx11:
                    commandLine.Add("-std=c++11");
                    break;

                case C.Cxx.ELanguageStandard.GnuCxx11:
                    commandLine.Add("-std=gnu++11");
                    break;

                case C.Cxx.ELanguageStandard.Cxx14:
                    commandLine.Add("-std=c++14");
                    break;

                case C.Cxx.ELanguageStandard.GnuCxx14:
                    commandLine.Add("-std=gnu++14");
                    break;

                default:
                    throw new Bam.Core.Exception("Invalid C++ language standard, {0}", settings.LanguageStandard.Value.ToString());
                }
            }
        }
        ICollatedObjectPolicy.Collate(
            CollatedObject sender,
            Bam.Core.ExecutionContext context)
        {
            var sourcePath = sender.SourcePath;

            if (null == sender.Reference)
            {
                // the main file is not copied anywhere, as we copy required files around it where VS wrote the main file
                // this is managed by the Collation class, querying the build mode for where publishing is relative to
                // ignore any subdirectory on this module
                return;
            }

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

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

            if (sender.SourceModule != null && sender.SourceModule.MetaData != null)
            {
                var destinationPath = sender.Macros["CopyDir"].Parse();

                var commands = new Bam.Core.StringArray();
                commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", destinationPath));
                commands.Add(System.String.Format(@"{0} {1} $(OutputPath)$(TargetFileName) {2} {3}",
                                                  CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                  commandLine.ToString(' '),
                                                  destinationPath,
                                                  CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));

                var project = sender.SourceModule.MetaData as VSSolutionBuilder.VSProject;
                var config  = project.GetConfiguration(sender.SourceModule);
                config.AddPostBuildCommands(commands);
            }
            else
            {
                var commands = new Bam.Core.StringArray();
                if (sender is CollatedDirectory)
                {
                    // Windows XCOPY requires the directory name to be added to the destination, while Posix cp does not
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      sourcePath.ParseAndQuoteIfNecessary(),
                                                      sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(),
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }
                else
                {
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      sourcePath.ParseAndQuoteIfNecessary(),
                                                      sender.SubDirectory,
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }

                var project = sender.Reference.SourceModule.MetaData as VSSolutionBuilder.VSProject;
                var config  = project.GetConfiguration(sender.Reference.SourceModule);
                config.AddPostBuildCommands(commands);
            }
        }
        DetermineSpecs(
            Bam.Core.BaseTarget baseTarget,
            Bam.Core.IToolset toolset)
        {
            // get version
            string gccVersion = null;
            {
                var processStartInfo = new System.Diagnostics.ProcessStartInfo();
                processStartInfo.FileName               = toolset.Tool(typeof(C.ICompilerTool)).Executable(baseTarget);
                processStartInfo.ErrorDialog            = true;
                processStartInfo.UseShellExecute        = false;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.Arguments              = "-dumpversion";

                System.Diagnostics.Process process = null;
                try
                {
                    process = System.Diagnostics.Process.Start(processStartInfo);
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    throw new Bam.Core.Exception("'{0}': process filename '{1}'", ex.Message, processStartInfo.FileName);
                }

                if (null == process)
                {
                    throw new Bam.Core.Exception("Unable to execute '{0}'", processStartInfo.FileName);
                }

                gccVersion = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                gccVersion = gccVersion.Trim();
            }

            // get target
            string gccTarget = null;
            {
                var processStartInfo = new System.Diagnostics.ProcessStartInfo();
                processStartInfo.FileName               = toolset.Tool(typeof(C.ICompilerTool)).Executable(baseTarget);
                processStartInfo.ErrorDialog            = true;
                processStartInfo.UseShellExecute        = false;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.Arguments              = "-dumpmachine";

                System.Diagnostics.Process process = null;
                try
                {
                    process = System.Diagnostics.Process.Start(processStartInfo);
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    throw new Bam.Core.Exception("'{0}': process filename '{1}'", ex.Message, processStartInfo.FileName);
                }

                if (null == process)
                {
                    throw new Bam.Core.Exception("Unable to execute '{0}'", processStartInfo.FileName);
                }

                gccTarget = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                gccTarget = gccTarget.Trim();
            }

            // get paths and targets
            string pathPrefix    = null;
            string gxxIncludeDir = null;
            string libDir        = null;
            var    includePaths  = new Bam.Core.StringArray();
            {
                var processStartInfo = new System.Diagnostics.ProcessStartInfo();
                processStartInfo.FileName               = toolset.Tool(typeof(C.ICompilerTool)).Executable(baseTarget);
                processStartInfo.ErrorDialog            = true;
                processStartInfo.UseShellExecute        = false;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardError  = true;
                processStartInfo.Arguments              = "-v";

                System.Diagnostics.Process process = null;
                try
                {
                    process = System.Diagnostics.Process.Start(processStartInfo);
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    throw new Bam.Core.Exception("'{0}': process filename '{1}'", ex.Message, processStartInfo.FileName);
                }

                if (null == process)
                {
                    throw new Bam.Core.Exception("Unable to execute '{0}'", processStartInfo.FileName);
                }

                var details = process.StandardOutput.ReadToEnd();
                process.WaitForExit();

                var splitDetails = details.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.None);

                foreach (var detail in splitDetails)
                {
                    const string configuredWith = "Configured with: ";
                    if (detail.StartsWith(configuredWith))
                    {
                        var configuredOptions     = detail.Substring(configuredWith.Length);
                        var splitConfigureOptions = configuredOptions.Split(' ');

                        const string pathPrefixKey    = "--prefix=";
                        const string gxxIncludeDirKey = "--with-gxx-include-dir=";
                        const string targetKey        = "--target=";
                        const string libexecKey       = "--libexecdir=";
                        const string slibDirKey       = "--with-slibdir=";
                        foreach (var option in splitConfigureOptions)
                        {
                            if (option.StartsWith(pathPrefixKey))
                            {
                                pathPrefix = option.Substring(pathPrefixKey.Length).Trim();;
                            }
                            else if (option.StartsWith(gxxIncludeDirKey))
                            {
                                gxxIncludeDir = option.Substring(gxxIncludeDirKey.Length).Trim();
                            }
                            else if (option.StartsWith(targetKey))
                            {
                                gccTarget = option.Substring(targetKey.Length).Trim();
                            }
                            else if (option.StartsWith(libexecKey))
                            {
                                if (null != libDir)
                                {
                                    throw new Bam.Core.Exception("lib dir already defined");
                                }
                                libDir = option.Substring(libexecKey.Length).Trim();
                            }
                            else if (option.StartsWith(slibDirKey))
                            {
                                if (null != libDir)
                                {
                                    throw new Bam.Core.Exception("lib dir already defined");
                                }
                                libDir = option.Substring(slibDirKey.Length).Trim();
                            }
                        }

                        break;
                    }
                }

                if (null == gccTarget)
                {
                    foreach (var detail in splitDetails)
                    {
                        var targetKey = "Target: ";
                        if (detail.StartsWith(targetKey))
                        {
                            gccTarget = detail.Substring(targetKey.Length).Trim();
                        }
                    }
                }

                if ((null != gxxIncludeDir) && !gxxIncludeDir.StartsWith(pathPrefix))
                {
                    // remove any prefix directory separator so that Combine works
                    gxxIncludeDir = gxxIncludeDir.TrimStart(System.IO.Path.DirectorySeparatorChar);
                    gxxIncludeDir = System.IO.Path.Combine(pathPrefix, gxxIncludeDir);
                }

                // C include paths (http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html)
                includePaths.Add("/usr/local/include");
                includePaths.Add("/usr/include");

                // TODO: this looks like the targetIncludeFolder, and has been necessary
                {
                    // this is for some Linux distributions
                    var path = System.String.Format("/usr/include/{0}", gccTarget);
                    if (System.IO.Directory.Exists(path))
                    {
                        includePaths.Add(path);
                    }
                }
            }

            var gccDetails = new GccDetailData(gccVersion, includePaths, gxxIncludeDir, gccTarget, libDir);

            gccDetailsForTarget[baseTarget] = gccDetails;

            Bam.Core.Log.DebugMessage("Gcc version for target '{0}' is '{1}'", baseTarget.ToString(), gccDetails.Version);
            Bam.Core.Log.DebugMessage("Gcc machine type for target '{0}' is '{1}'", baseTarget.ToString(), gccDetails.Target);
            Bam.Core.Log.DebugMessage("Gxx include path for target '{0}' is '{1}'", baseTarget.ToString(), gccDetails.GxxIncludePath);

            return(gccDetails);
        }
Beispiel #33
0
        public object Build(
            CodeGenTest2.CodeGenModule moduleToBuild,
            out System.Boolean success)
        {
            var codeGenModuleModule = moduleToBuild as Bam.Core.BaseModule;
            var node = codeGenModuleModule.OwningNode;
            var target = node.Target;
            var codeGenModuleOptions = codeGenModuleModule.Options;
            var toolOptions = codeGenModuleOptions as CodeGenTest2.CodeGenOptionCollection;
            var tool = target.Toolset.Tool(typeof(CodeGenTest2.ICodeGenTool));
            var toolExePath = tool.Executable((Bam.Core.BaseTarget)target);

            var inputFiles = new Bam.Core.StringArray();
            inputFiles.Add(toolExePath);

            // at this point, we know the node outputs need building

            // create all directories required
            var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist);

            var commandLineBuilder = new Bam.Core.StringArray();
            if (toolOptions is CommandLineProcessor.ICommandLineSupport)
            {
                var commandLineOption = toolOptions as CommandLineProcessor.ICommandLineSupport;
                commandLineOption.ToCommandLineArguments(commandLineBuilder, target, null);
            }
            else
            {
                throw new Bam.Core.Exception("Moc options does not support command line translation");
            }

            var recipes = new Bam.Core.StringArray();
            if (toolExePath.Contains(" "))
            {
                recipes.Add("\"" + toolExePath + "\" " + commandLineBuilder.ToString());
            }
            else
            {
                recipes.Add(toolExePath + " " + commandLineBuilder.ToString());
            }

            var makeFilePath = MakeFileBuilder.GetMakeFilePathName(node);
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(makeFilePath));
            Bam.Core.Log.DebugMessage("Makefile : '{0}'", makeFilePath);

            var makeFile = new MakeFile(node, this.topLevelMakeFilePath);

            var rule = new MakeFileRule(
                moduleToBuild,
                CodeGenTest2.CodeGenModule.OutputFile,
                node.UniqueModuleName,
                dirsToCreate,
                null,
                inputFiles,
                recipes);
            rule.OutputLocationKeys = new Bam.Core.Array<Bam.Core.LocationKey>(CodeGenTest2.CodeGenModule.OutputFile);
            makeFile.RuleArray.Add(rule);

            using (var makeFileWriter = new System.IO.StreamWriter(makeFilePath))
            {
                makeFile.Write(makeFileWriter);
            }

            System.Collections.Generic.Dictionary<string, Bam.Core.StringArray> environment = null;
            if (tool is Bam.Core.IToolEnvironmentVariables)
            {
                environment = (tool as Bam.Core.IToolEnvironmentVariables).Variables((Bam.Core.BaseTarget)target);
            }
            var returnData = new MakeFileData(makeFilePath, makeFile.ExportedTargets, makeFile.ExportedVariables, environment);
            success = true;
            return returnData;
        }
        Convert(
            this C.ICommonCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            var module = (settings as Bam.Core.Settings).Module;

            if (settings.DebugSymbols.HasValue)
            {
                if (settings.DebugSymbols.Value)
                {
                    commandLine.Add("-Z7");
                }
            }
            foreach (var warning in settings.DisableWarnings)
            {
                commandLine.Add(System.String.Format("-wd{0}", warning));
            }
            foreach (var path in settings.IncludePaths)
            {
                commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary()));
            }
            if (settings.OmitFramePointer.HasValue)
            {
                commandLine.Add(settings.OmitFramePointer.Value ? "-Oy" : "-Oy-");
            }
            if (settings.Optimization.HasValue)
            {
                switch (settings.Optimization.Value)
                {
                case C.EOptimization.Off:
                    commandLine.Add("-Od");
                    break;

                case C.EOptimization.Size:
                    commandLine.Add("-Os");
                    break;

                case C.EOptimization.Speed:
                    commandLine.Add("-O1");
                    break;

                case C.EOptimization.Full:
                    commandLine.Add("-Ox");
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown optimization level, {0}", settings.Optimization.Value.ToString());
                }
            }
            foreach (var define in settings.PreprocessorDefines)
            {
                if (System.String.IsNullOrEmpty(define.Value))
                {
                    commandLine.Add(System.String.Format("-D{0}", define.Key));
                }
                else
                {
                    var value = define.Value;
                    if (value.Contains("\""))
                    {
                        value = value.Replace("\"", "\\\"");
                    }
                    commandLine.Add(System.String.Format("-D{0}={1}", define.Key, value));
                }
            }
            foreach (var undefine in settings.PreprocessorUndefines)
            {
                commandLine.Add(System.String.Format("-U{0}", undefine));
            }
            foreach (var path in settings.SystemIncludePaths)
            {
                commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary()));
            }
            if (settings.TargetLanguage.HasValue)
            {
                switch (settings.TargetLanguage.Value)
                {
                case C.ETargetLanguage.C:
                    commandLine.Add("-TC");
                    break;

                case C.ETargetLanguage.Cxx:
                    commandLine.Add("-TP");
                    break;

                default:
                    throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value.ToString());
                }
            }
            if (settings.WarningsAsErrors.HasValue)
            {
                if (settings.WarningsAsErrors.Value)
                {
                    commandLine.Add("-WX");
                }
            }
            if (settings.OutputType.HasValue)
            {
                switch (settings.OutputType.Value)
                {
                case C.ECompilerOutput.CompileOnly:
                    commandLine.Add(System.String.Format("-c -Fo{0}", module.GeneratedPaths[C.ObjectFile.Key].ToString()));
                    break;

                case C.ECompilerOutput.Preprocess:
                    commandLine.Add(System.String.Format("-E -Fo{0}", module.GeneratedPaths[C.ObjectFile.Key].ToString()));
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown output type, {0}", settings.OutputType.Value.ToString());
                }
            }
        }
Beispiel #35
0
        public static void 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.Parse());
                }
            }
            commandLineArgs.AddRange(commandLine);
            if (null != tool.TerminatingArguments)
            {
                foreach (var arg in tool.TerminatingArguments)
                {
                    commandLineArgs.Add(arg.Parse());
                }
            }

            Execute(
                context,
                tool.Executable.Parse(),
                commandLineArgs,
                workingDirectory: workingDirectory,
                inheritedEnvironmentVariables: tool.InheritedEnvironmentVariables,
                addedEnvironmentVariables: tool.EnvironmentVariables,
                useResponseFileOption: tool.UseResponseFileOption);
        }
        Convert(
            this C.ICommonCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            var module = (settings as Bam.Core.Settings).Module;

            if (settings.DebugSymbols.HasValue)
            {
                if (settings.DebugSymbols.Value)
                {
                    commandLine.Add("-Z7");
                }
            }
            foreach (var warning in settings.DisableWarnings)
            {
                commandLine.Add(System.String.Format("-wd{0}", warning));
            }
            foreach (var path in settings.IncludePaths.ToEnumerableWithoutDuplicates())
            {
                commandLine.Add(System.String.Format("-I{0}", path.ToStringQuoteIfNecessary()));
            }
            if (settings.Optimization.HasValue)
            {
                switch (settings.Optimization.Value)
                {
                case C.EOptimization.Off:
                    commandLine.Add("-Od");
                    break;

                case C.EOptimization.Size:
                    commandLine.Add("-O1");
                    break;

                case C.EOptimization.Speed:
                    commandLine.Add("-O2");
                    break;

                case C.EOptimization.Custom:
                    // do nothing - deferred to compiler specific optimization settings
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown optimization level, {0}", settings.Optimization.Value.ToString());
                }
            }
            if (settings.OmitFramePointer.HasValue)
            {
                commandLine.Add(settings.OmitFramePointer.Value ? "-Oy" : "-Oy-");
            }
            foreach (var define in settings.PreprocessorDefines)
            {
                if (null == define.Value)
                {
                    commandLine.Add(System.String.Format("-D{0}", define.Key));
                }
                else
                {
                    var defineValue = define.Value.ToString();
                    if (defineValue.Contains("\""))
                    {
                        defineValue = defineValue.Replace("\"", "\\\"");
                    }
                    defineValue = Bam.Core.IOWrapper.EncloseSpaceContainingPathWithDoubleQuotes(defineValue);
                    commandLine.Add(System.String.Format("-D{0}={1}", define.Key, defineValue));
                }
            }
            foreach (var undefine in settings.PreprocessorUndefines)
            {
                commandLine.Add(System.String.Format("-U{0}", undefine));
            }
            foreach (var path in settings.SystemIncludePaths.ToEnumerableWithoutDuplicates())
            {
                commandLine.Add(System.String.Format("-I{0}", path.ToStringQuoteIfNecessary()));
            }
            if (settings.TargetLanguage.HasValue)
            {
                switch (settings.TargetLanguage.Value)
                {
                case C.ETargetLanguage.C:
                    commandLine.Add("-TC");
                    break;

                case C.ETargetLanguage.Cxx:
                    commandLine.Add("-TP");
                    break;

                default:
                    throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value.ToString());
                }
            }
            if (settings.WarningsAsErrors.HasValue)
            {
                if (settings.WarningsAsErrors.Value)
                {
                    commandLine.Add("-WX");
                }
                else
                {
                    commandLine.Add("-WX-");
                }
            }
            if (settings.OutputType.HasValue)
            {
                switch (settings.OutputType.Value)
                {
                case C.ECompilerOutput.CompileOnly:
                    commandLine.Add(System.String.Format("-c -Fo{0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary()));
                    break;

                case C.ECompilerOutput.Preprocess:
                    commandLine.Add(System.String.Format("-E -Fo{0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary()));
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown output type, {0}", settings.OutputType.Value.ToString());
                }
            }
            foreach (var header in settings.NamedHeaders)
            {
                commandLine.Add(System.String.Format("-FI{0}", header));
            }
        }
Beispiel #37
0
        Evaluate()
        {
            this.ReasonToExecute = null;
            var graph   = Bam.Core.Graph.Instance;
            var factory = graph.MetaData as System.Threading.Tasks.TaskFactory;

            this.EvaluationTask = factory.StartNew(() =>
            {
                // does the object file exist?
                var objectFilePath = this.GeneratedPaths[Key].Parse();
                if (!System.IO.File.Exists(objectFilePath))
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.FileDoesNotExist(this.GeneratedPaths[Key]);
                    return;
                }
                var objectFileWriteTime = System.IO.File.GetLastWriteTime(objectFilePath);

                // has the source file been evaluated to be rebuilt?
                if ((this as IRequiresSourceModule).Source.ReasonToExecute != null)
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(this.GeneratedPaths[Key], this.InputPath);
                    return;
                }

                // is the source file newer than the object file?
                var sourcePath      = this.InputPath.Parse();
                var sourceWriteTime = System.IO.File.GetLastWriteTime(sourcePath);
                if (sourceWriteTime > objectFileWriteTime)
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(this.GeneratedPaths[Key], this.InputPath);
                    return;
                }

                if (this is WinResource)
                {
                    return;
                }

                var includeSearchPaths = (this.Settings as C.ICommonCompilerSettings).IncludePaths;

                var filesToSearch = new System.Collections.Generic.Queue <string>();
                filesToSearch.Enqueue(sourcePath);

                var headerPathsFound = new Bam.Core.StringArray();
                while (filesToSearch.Count > 0)
                {
                    var fileToSearch = filesToSearch.Dequeue();

                    string fileContents = null;
                    using (System.IO.TextReader reader = new System.IO.StreamReader(fileToSearch))
                    {
                        fileContents = reader.ReadToEnd();
                    }

                    var matches = System.Text.RegularExpressions.Regex.Matches(
                        fileContents,
                        "^\\s*#include \"(.*)\"",
                        System.Text.RegularExpressions.RegexOptions.Multiline);
                    if (0 == matches.Count)
                    {
                        // no #includes
                        return;
                    }

                    foreach (System.Text.RegularExpressions.Match match in matches)
                    {
                        bool exists = false;
                        // search for the file on the include paths the compiler uses
                        foreach (var includePath in includeSearchPaths)
                        {
                            try
                            {
                                var potentialPath = System.IO.Path.Combine(includePath.Parse(), match.Groups[1].Value);
                                if (!System.IO.File.Exists(potentialPath))
                                {
                                    continue;
                                }
                                potentialPath       = System.IO.Path.GetFullPath(potentialPath);
                                var headerWriteTime = System.IO.File.GetLastWriteTime(potentialPath);

                                // early out - header is newer than generated object file
                                if (headerWriteTime > objectFileWriteTime)
                                {
                                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(
                                        this.GeneratedPaths[Key],
                                        Bam.Core.TokenizedString.CreateVerbatim(potentialPath));
                                    return;
                                }

                                if (!headerPathsFound.Contains(potentialPath))
                                {
                                    headerPathsFound.Add(potentialPath);
                                    filesToSearch.Enqueue(potentialPath);
                                }

                                exists = true;
                                break;
                            }
                            catch (System.Exception ex)
                            {
                                Bam.Core.Log.MessageAll("IncludeDependency Exception: Cannot locate '{0}' on '{1}' due to {2}", match.Groups[1].Value, includePath, ex.Message);
                            }
                        }

                        if (!exists)
                        {
#if false
                            Bam.Core.Log.DebugMessage("***** Could not locate '{0}' on any include search path, included from {1}:\n{2}",
                                                      match.Groups[1],
                                                      fileToSearch,
                                                      entry.includePaths.ToString('\n'));
#endif
                        }
                    }
                }

                return;
            });
        }
        Convert(
            this C.ICommonCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.Bits.HasValue)
            {
                switch (settings.Bits.Value)
                {
                case C.EBit.SixtyFour:
                    commandLine.Add("-arch x86_64");
                    break;

                case C.EBit.ThirtyTwo:
                    commandLine.Add("-arch i386");
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown bit depth, {0}", settings.Bits.Value);
                }
            }
            if (settings.DebugSymbols.HasValue)
            {
                if (settings.DebugSymbols.Value)
                {
                    commandLine.Add("-g");
                }
            }
            foreach (var warning in settings.DisableWarnings)
            {
                commandLine.Add(System.String.Format("-Wno-{0}", warning));
            }
            foreach (var path in settings.IncludePaths.ToEnumerableWithoutDuplicates())
            {
                var quoted_path = path.ToStringQuoteIfNecessary();
                if (Bam.Core.Graph.Instance.Mode == "Xcode")
                {
                    quoted_path = quoted_path.Replace("\"", "\\\"");
                }
                commandLine.Add(System.String.Format("-I{0}", quoted_path));
            }
            if (settings.Optimization.HasValue)
            {
                switch (settings.Optimization.Value)
                {
                case C.EOptimization.Off:
                    commandLine.Add("-O0");
                    break;

                case C.EOptimization.Size:
                    commandLine.Add("-Os");
                    break;

                case C.EOptimization.Speed:
                    commandLine.Add("-O2");
                    break;

                case C.EOptimization.Custom:
                    // do nothing - defer to the compiler specific optimization settings
                    break;

                default:
                    throw new Bam.Core.Exception("Unsupported optimization, {0}", settings.Optimization.Value);
                }
            }
            if (settings.OmitFramePointer.HasValue)
            {
                commandLine.Add(settings.OmitFramePointer.Value ? "-fomit-frame-pointer" : "-fno-omit-frame-pointer");
            }
            foreach (var define in settings.PreprocessorDefines)
            {
                if (null == define.Value)
                {
                    commandLine.Add(System.String.Format("-D{0}", define.Key));
                }
                else
                {
                    var defineValue = define.Value.ToString();
                    if (defineValue.Contains("\""))
                    {
                        if (Bam.Core.Graph.Instance.Mode == "Xcode")
                        {
                            // note the number of back slashes here
                            // required to get \\\" for each " in the original value
                            defineValue = defineValue.Replace("\"", "\\\\\\\"");
                        }
                        else
                        {
                            defineValue = defineValue.Replace("\"", "\\\"");
                        }
                    }
                    defineValue = Bam.Core.IOWrapper.EncloseSpaceContainingPathWithDoubleQuotes(defineValue);
                    commandLine.Add(System.String.Format("-D{0}={1}", define.Key, defineValue));
                }
            }
            foreach (var undefine in settings.PreprocessorUndefines)
            {
                commandLine.Add(System.String.Format("-U{0}", undefine));
            }
            foreach (var path in settings.SystemIncludePaths.ToEnumerableWithoutDuplicates())
            {
                var quoted_path = path.ToStringQuoteIfNecessary();
                if (Bam.Core.Graph.Instance.Mode == "Xcode")
                {
                    quoted_path = quoted_path.Replace("\"", "\\\"");
                }
                commandLine.Add(System.String.Format("-I{0}", quoted_path));
            }
            if (settings.TargetLanguage.HasValue)
            {
                switch (settings.TargetLanguage.Value)
                {
                case C.ETargetLanguage.C:
                    commandLine.Add("-x c");
                    break;

                case C.ETargetLanguage.Cxx:
                    commandLine.Add("-x c++");
                    break;

                case C.ETargetLanguage.ObjectiveC:
                    commandLine.Add("-x objective-c");
                    break;

                case C.ETargetLanguage.ObjectiveCxx:
                    commandLine.Add("-x objective-c++");
                    break;

                default:
                    throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value);
                }
            }
            if (settings.WarningsAsErrors.HasValue)
            {
                if (settings.WarningsAsErrors.Value)
                {
                    commandLine.Add("-Werror");
                }
                else
                {
                    commandLine.Add("-Wno-error");
                }
            }
            if (settings.OutputType.HasValue)
            {
                var module = (settings as Bam.Core.Settings).Module;
                switch (settings.OutputType.Value)
                {
                case C.ECompilerOutput.CompileOnly:
                    commandLine.Add(System.String.Format("-c -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary()));
                    break;

                case C.ECompilerOutput.Preprocess:
                    commandLine.Add(System.String.Format("-E -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary()));
                    break;

                default:
                    throw new Bam.Core.Exception("Unsupported output type, {0}", settings.OutputType.Value.ToString());
                }
            }
            foreach (var header in settings.NamedHeaders)
            {
                commandLine.Add(System.String.Format("-include {0}", header));
            }
        }
Beispiel #39
0
        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);
            }
        }
        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);
        }
Beispiel #41
0
        ICollatedObjectPolicy.Collate(
            CollatedObject sender,
            Bam.Core.ExecutionContext context)
        {
            var sourcePath = sender.SourcePath;

            if (null == sender.Reference)
            {
                if ((null != sender.SourceModule.MetaData) || (sender.SourceModule is CollatedObject))
                {
                    // the main file is not copied anywhere, as we copy required files around it where VS wrote the main file
                    // this is managed by the Collation class, querying the build mode for where publishing is relative to
                    // ignore any subdirectory on this module

                    // could also be a DebugSymbols or Stripped copy, in which case, ignore it
                    return;
                }
                else
                {
                    // the main reference file was a prebuilt - so create a new project to handle copying files

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

                    config.SetType(VSSolutionBuilder.VSProjectConfiguration.EType.Utility);
                    config.SetOutputPath(sender.Macros["CopyDir"]);
                    config.EnableIntermediatePath();
                }
            }

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

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

            if (sender.SourceModule != null && sender.SourceModule.MetaData != null && VSSolutionBuilder.VSProject.IsBuildable(sender.SourceModule))
            {
                var destinationPath = sender.Macros["CopyDir"].Parse();

                var project = sender.SourceModule.MetaData as VSSolutionBuilder.VSProject;
                var config  = project.GetConfiguration(sender.SourceModule);

                var commands = new Bam.Core.StringArray();
                commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", destinationPath));
                if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility)
                {
                    commands.Add(System.String.Format(@"{0} {1} $(OutputPath)$(TargetFileName) {2} {3}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      destinationPath,
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                    config.AddPostBuildCommands(commands);
                }
                else
                {
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir).\ {3}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      sourcePath.ParseAndQuoteIfNecessary(),
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                    config.AddPreBuildCommands(commands);
                }
            }
            else
            {
                var commands = new Bam.Core.StringArray();
                if (sender is CollatedDirectory)
                {
                    // Windows XCOPY requires the directory name to be added to the destination, while Posix cp does not
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      sourcePath.ParseAndQuoteIfNecessary(),
                                                      sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(),
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }
                else
                {
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      sourcePath.ParseAndQuoteIfNecessary(),
                                                      sender.SubDirectory,
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }

                var project = sender.Reference.SourceModule.MetaData as VSSolutionBuilder.VSProject;
                var config  = project.GetConfiguration(sender.Reference.SourceModule);
                if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility)
                {
                    config.AddPostBuildCommands(commands);
                }
                else
                {
                    config.AddPreBuildCommands(commands);
                }
            }
        }
        ICollatedObjectPolicy.Collate(
            CollatedObject sender,
            Bam.Core.ExecutionContext context)
        {
            var sourcePath = sender.SourcePath;

            if (null == sender.Reference)
            {
                if ((null != sender.SourceModule.MetaData) || (sender.SourceModule is CollatedObject))
                {
                    // the main file is not copied anywhere, as we copy required files around it where Xcode wrote the main file
                    // this is managed by the Collation class, querying the build mode for where publishing is relative to
                    // ignore any subdirectory on this module

                    // convert the executable into an app bundle, if EPublishingType.WindowedApplication has been used as the type
                    if ((sender.SubDirectory != null) && sender.SubDirectory.Parse().Contains(".app/"))
                    {
                        var target = sender.SourceModule.MetaData as XcodeBuilder.Target;
                        target.MakeApplicationBundle();
                    }

                    return;
                }
                else
                {
                    // the main reference file was a prebuilt - so create a new project to handle copying files

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

                    target.Type = XcodeBuilder.Target.EProductType.Utility;
                    configuration.SetProductName(sender.SourceModule.Macros["modulename"]);
                    //Bam.Core.Log.MessageAll("Configuration {0} for {1}", configuration.Name, sender.SourceModule.ToString());
                }
            }

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

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

            var destinationPath = sender.Macros["CopyDir"].Parse();
            var commands        = new Bam.Core.StringArray();

            commands.Add(System.String.Format("[[ ! -d {0} ]] && mkdir -p {0}", destinationPath));

            if (sender.SourceModule != null && sender.SourceModule.MetaData != null)
            {
                if ((null != sender.Reference) &&
                    (null != sender.Reference.SourceModule) &&
                    (sender.SourceModule.PackageDefinition == sender.Reference.SourceModule.PackageDefinition) &&
                    (null == sender.Reference.SubDirectory) &&
                    (sender.SubDirectory.Parse() == "."))
                {
                    // special case that the module output is already in the right directory at build
                    return;
                }

                var target = sender.SourceModule.MetaData as XcodeBuilder.Target;
                if (target.Type != XcodeBuilder.Target.EProductType.Utility)
                {
                    commands.Add(System.String.Format("{0} {1} $CONFIGURATION_BUILD_DIR/$EXECUTABLE_NAME {2} {3}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      destinationPath,
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }
                else
                {
                    commands.Add(System.String.Format("{0} {1} {2} {3} {4}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      sourcePath.Parse(),
                                                      destinationPath,
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }

                var configuration = target.GetConfiguration(sender.SourceModule);
                if (target.Type != XcodeBuilder.Target.EProductType.Utility)
                {
                    target.AddPostBuildCommands(commands, configuration);
                }
                else
                {
                    target.AddPreBuildCommands(commands, configuration);
                }
            }
            else
            {
                var target = sender.Reference.SourceModule.MetaData as XcodeBuilder.Target;

                var isSymlink = (sender is CollatedSymbolicLink);

                var destinationFolder = "$CONFIGURATION_BUILD_DIR";
                if (sender.Reference != null)
                {
                    destinationFolder = "$CONFIGURATION_BUILD_DIR/$EXECUTABLE_FOLDER_PATH";
                }
                if (target.Type == XcodeBuilder.Target.EProductType.Utility)
                {
                    destinationFolder = destinationPath;
                }

                if (isSymlink)
                {
                    commands.Add(System.String.Format("{0} {1} {2} {3}/{4} {5}",
                                                      CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                      commandLine.ToString(' '),
                                                      sender.Macros["LinkTarget"].Parse(),
                                                      destinationFolder,
                                                      sender.CreateTokenizedString("$(0)/@filename($(1))", sender.SubDirectory, sender.SourcePath).Parse(),
                                                      CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }
                else
                {
                    if (sender is CollatedDirectory)
                    {
                        var copySource = sourcePath.Parse();
                        if (sender.Macros["CopiedFilename"].IsAliased)
                        {
                            copySource = System.String.Format("{0}/*", copySource);
                        }

                        commands.Add(System.String.Format("{0} {1} {2} {3}/{4}/ {5}",
                                                          CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                          commandLine.ToString(' '),
                                                          copySource,
                                                          destinationFolder,
                                                          sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),)", sender.SubDirectory).Parse(),
                                                          CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                    }
                    else
                    {
                        commands.Add(System.String.Format("{0} {1} {2} {3}/{4}/ {5}",
                                                          CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                                                          commandLine.ToString(' '),
                                                          sourcePath.Parse(),
                                                          destinationFolder,
                                                          sender.SubDirectory.Parse(),
                                                          CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                    }
                }

                var configuration = target.GetConfiguration(sender.Reference.SourceModule);
                if (target.Type != XcodeBuilder.Target.EProductType.Utility)
                {
                    target.AddPostBuildCommands(commands, configuration);
                }
                else
                {
                    target.AddPreBuildCommands(commands, configuration);
                }
            }
        }
        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);
            }
        }
Beispiel #44
0
        public override void Evaluate()
        {
            this.ReasonToExecute = null;
            var graph = Bam.Core.Graph.Instance;
            var factory = graph.MetaData as System.Threading.Tasks.TaskFactory;
            this.EvaluationTask = factory.StartNew(() =>
            {
                // does the object file exist?
                var objectFilePath = this.GeneratedPaths[Key].Parse();
                if (!System.IO.File.Exists(objectFilePath))
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.FileDoesNotExist(this.GeneratedPaths[Key]);
                    return;
                }
                var objectFileWriteTime = System.IO.File.GetLastWriteTime(objectFilePath);

                // has the source file been evaluated to be rebuilt?
                if ((this as IRequiresSourceModule).Source.ReasonToExecute != null)
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(this.GeneratedPaths[Key], this.InputPath);
                    return;
                }

                // is the source file newer than the object file?
                var sourcePath = this.InputPath.Parse();
                var sourceWriteTime = System.IO.File.GetLastWriteTime(sourcePath);
                if (sourceWriteTime > objectFileWriteTime)
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(this.GeneratedPaths[Key], this.InputPath);
                    return;
                }

                if (this is WinResource)
                {
                    return;
                }

                // are there any headers as explicit dependencies (procedurally generated most likely), which are newer?
                var explicitHeadersUpdated = new Bam.Core.StringArray();
                foreach (var dep in this.Dependents)
                {
                    if (!(dep is HeaderFile))
                    {
                        continue;
                    }
                    if (null == dep.ReasonToExecute)
                    {
                        continue;
                    }
                    explicitHeadersUpdated.AddUnique((dep as HeaderFile).InputPath.Parse());
                }

                var includeSearchPaths = (this.Settings as C.ICommonCompilerSettings).IncludePaths;

                var filesToSearch = new System.Collections.Generic.Queue<string>();
                filesToSearch.Enqueue(sourcePath);

                var headerPathsFound = new Bam.Core.StringArray();
                while (filesToSearch.Count > 0)
                {
                    var fileToSearch = filesToSearch.Dequeue();

                    string fileContents = null;
                    using (System.IO.TextReader reader = new System.IO.StreamReader(fileToSearch))
                    {
                        fileContents = reader.ReadToEnd();
                    }

                    // never know if developers are consistent with #include "header.h" or #include <header.h> so look for both
                    var matches = System.Text.RegularExpressions.Regex.Matches(
                        fileContents,
                        "^\\s*#include [\"<]([^\\s]*)[\">]",
                        System.Text.RegularExpressions.RegexOptions.Multiline);
                    if (0 == matches.Count)
                    {
                        // no #includes
                        return;
                    }

                    foreach (System.Text.RegularExpressions.Match match in matches)
                    {
                        var headerFile = match.Groups[1].Value;
                        bool exists = false;
                        // search for the file on the include paths the compiler uses
                        foreach (var includePath in includeSearchPaths)
                        {
                            try
                            {
                                var potentialPath = System.IO.Path.Combine(includePath.Parse(), headerFile);
                                if (!System.IO.File.Exists(potentialPath))
                                {
                                    continue;
                                }
                                potentialPath = System.IO.Path.GetFullPath(potentialPath);
                                var headerWriteTime = System.IO.File.GetLastWriteTime(potentialPath);

                                // early out - header is newer than generated object file
                                if (headerWriteTime > objectFileWriteTime)
                                {
                                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(
                                        this.GeneratedPaths[Key],
                                        Bam.Core.TokenizedString.CreateVerbatim(potentialPath));
                                    return;
                                }

                                if (explicitHeadersUpdated.Contains(potentialPath))
                                {
                                    // found #included header in list of explicitly dependent headers that have been updated
                                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(
                                        this.GeneratedPaths[Key],
                                        Bam.Core.TokenizedString.CreateVerbatim(potentialPath));
                                    return;
                                }

                                if (!headerPathsFound.Contains(potentialPath))
                                {
                                    headerPathsFound.Add(potentialPath);
                                    filesToSearch.Enqueue(potentialPath);
                                }

                                exists = true;
                                break;
                            }
                            catch (System.Exception ex)
                            {
                                Bam.Core.Log.MessageAll("IncludeDependency Exception: Cannot locate '{0}' on '{1}' due to {2}", headerFile, includePath, ex.Message);
                            }
                        }

                        if (!exists)
                        {
            #if false
                                Bam.Core.Log.DebugMessage("***** Could not locate '{0}' on any include search path, included from {1}:\n{2}",
                                                          match.Groups[1],
                                                          fileToSearch,
                                                          entry.includePaths.ToString('\n'));
            #endif
                        }
                    }
                }

                return;
            });
        }
        void ICollatedObjectPolicy.Collate(
            CollatedObject sender,
            Bam.Core.ExecutionContext context)
        {
            var sourcePath = sender.SourcePath;
            if (null == sender.Reference)
            {
                if ((null != sender.SourceModule.MetaData) || (sender.SourceModule is CollatedObject))
                {
                    // the main file is not copied anywhere, as we copy required files around it where VS wrote the main file
                    // this is managed by the Collation class, querying the build mode for where publishing is relative to
                    // ignore any subdirectory on this module

                    // could also be a DebugSymbols or Stripped copy, in which case, ignore it
                    return;
                }
                else
                {
                    // the main reference file was a prebuilt - so create a new project to handle copying files

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

                    config.SetType(VSSolutionBuilder.VSProjectConfiguration.EType.Utility);
                    config.SetOutputPath(sender.Macros["CopyDir"]);
                    config.EnableIntermediatePath();
                }
            }

            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            if (sender.SourceModule != null && sender.SourceModule.MetaData != null)
            {
                var destinationPath = sender.Macros["CopyDir"].Parse();

                var project = sender.SourceModule.MetaData as VSSolutionBuilder.VSProject;
                var config = project.GetConfiguration(sender.SourceModule);

                var commands = new Bam.Core.StringArray();
                commands.Add(System.String.Format("IF NOT EXIST {0} MKDIR {0}", destinationPath));
                if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility)
                {
                    commands.Add(System.String.Format(@"{0} {1} $(OutputPath)$(TargetFileName) {2} {3}",
                        CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                        commandLine.ToString(' '),
                        destinationPath,
                        CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                    config.AddPostBuildCommands(commands);
                }
                else
                {
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir).\ {3}",
                        CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                        commandLine.ToString(' '),
                        sourcePath.ParseAndQuoteIfNecessary(),
                        CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                    config.AddPreBuildCommands(commands);
                }
            }
            else
            {
                var commands = new Bam.Core.StringArray();
                if (sender is CollatedDirectory)
                {
                    // Windows XCOPY requires the directory name to be added to the destination, while Posix cp does not
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}",
                        CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                        commandLine.ToString(' '),
                        sourcePath.ParseAndQuoteIfNecessary(),
                        sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(),
                        CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }
                else
                {
                    commands.Add(System.String.Format(@"{0} {1} {2} $(OutDir){3}\ {4}",
                        CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                        commandLine.ToString(' '),
                        sourcePath.ParseAndQuoteIfNecessary(),
                        sender.SubDirectory,
                        CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }

                var project = sender.Reference.SourceModule.MetaData as VSSolutionBuilder.VSProject;
                var config = project.GetConfiguration(sender.Reference.SourceModule);
                if (config.Type != VSSolutionBuilder.VSProjectConfiguration.EType.Utility)
                {
                    config.AddPostBuildCommands(commands);
                }
                else
                {
                    config.AddPreBuildCommands(commands);
                }
            }
        }
Beispiel #46
0
        Build(
            XmlUtilities.XmlModule moduleToBuild,
            out bool success)
        {
            var isPlist       = moduleToBuild is XmlUtilities.OSXPlistModule;
            var locationMap   = moduleToBuild.Locations;
            var outputDir     = locationMap[XmlUtilities.OSXPlistModule.OutputDir];
            var outputDirPath = outputDir.GetSingleRawPath();

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

            var xmlFileLoc  = locationMap[XmlUtilities.XmlModule.OutputFile];
            var xmlFilePath = xmlFileLoc.GetSingleRawPath();

            // write a script that can be invoked by the MakeFile to generate the XML file
            var shellScriptLeafName = isPlist ? "writePList.py" : "writeXMLFile.py";
            var shellScriptLoc      = Bam.Core.FileLocation.Get(outputDir, shellScriptLeafName, Bam.Core.Location.EExists.WillExist);
            var shellScriptPath     = shellScriptLoc.GetSingleRawPath();

            XmlUtilities.XmlDocumentToPythonScript.Write(moduleToBuild.Document, shellScriptPath, xmlFilePath);

            var node     = moduleToBuild.OwningNode;
            var makeFile = new MakeFile(node, this.topLevelMakeFilePath);

            var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist);

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

            recipe.Add(System.String.Format("$(shell python {0})", shellScriptPath));

            var rule = new MakeFileRule(
                moduleToBuild,
                XmlUtilities.XmlModule.OutputFile,
                node.UniqueModuleName,
                dirsToCreate,
                null,
                null,
                recipe);

            rule.OutputLocationKeys = new Bam.Core.Array <Bam.Core.LocationKey>(XmlUtilities.XmlModule.OutputFile);
            makeFile.RuleArray.Add(rule);

            var makeFilePath = MakeFileBuilder.GetMakeFilePathName(node);

            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(makeFilePath));

            using (var makeFileWriter = new System.IO.StreamWriter(makeFilePath))
            {
                makeFile.Write(makeFileWriter);
            }

            var exportedTargets   = makeFile.ExportedTargets;
            var exportedVariables = makeFile.ExportedVariables;
            var returnData        = new MakeFileData(makeFilePath, exportedTargets, exportedVariables, null);

            success = true;
            return(returnData);
        }
Beispiel #47
0
        Convert(
            this C.ICommonAssemblerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            var module = (settings as Bam.Core.Settings).Module;

            switch (settings.Bits.Value)
            {
            case C.EBit.SixtyFour:
                commandLine.Add("-arch x86_64");
                break;

            case C.EBit.ThirtyTwo:
                commandLine.Add("-arch i386");
                break;

            default:
                throw new Bam.Core.Exception("Unknown bit depth, {0}", settings.Bits.Value);
            }
            if (settings.DebugSymbols)
            {
                commandLine.Add("-g");
            }
            switch (settings.OutputType)
            {
            case C.ECompilerOutput.CompileOnly:
                commandLine.Add(System.String.Format("-c -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary()));
                break;

            case C.ECompilerOutput.Preprocess:
                commandLine.Add(System.String.Format("-E -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToStringQuoteIfNecessary()));
                break;

            default:
                throw new Bam.Core.Exception("Unknown output type, {0}", settings.OutputType.ToString());
            }
            if (settings.WarningsAsErrors)
            {
                commandLine.Add("-Werror");
            }
            else
            {
                commandLine.Add("-Wno-error");
            }
            foreach (var path in settings.IncludePaths.ToEnumerableWithoutDuplicates())
            {
                commandLine.Add(System.String.Format("-I{0}", path.ToStringQuoteIfNecessary()));
            }
            foreach (var define in settings.PreprocessorDefines)
            {
                if (null == define.Value)
                {
                    commandLine.Add(System.String.Format("-D{0}", define.Key));
                }
                else
                {
                    var defineValue = define.Value.ToString();
                    if (defineValue.Contains("\""))
                    {
                        defineValue = defineValue.Replace("\"", "\\\"");
                    }
                    defineValue = Bam.Core.IOWrapper.EncloseSpaceContainingPathWithDoubleQuotes(defineValue);
                    commandLine.Add(System.String.Format("-D{0}={1}", define.Key, defineValue));
                }
            }
        }
        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);
            }
        }
        DetermineSpecs(
            Bam.Core.BaseTarget baseTarget,
            Bam.Core.IToolset toolset)
        {
            // get version
            string gccVersion = null;
            {
                var processStartInfo = new System.Diagnostics.ProcessStartInfo();
                processStartInfo.FileName = toolset.Tool(typeof(C.ICompilerTool)).Executable(baseTarget);
                processStartInfo.ErrorDialog = true;
                processStartInfo.UseShellExecute = false;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.Arguments = "-dumpversion";

                System.Diagnostics.Process process = null;
                try
                {
                    process = System.Diagnostics.Process.Start(processStartInfo);
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    throw new Bam.Core.Exception("'{0}': process filename '{1}'", ex.Message, processStartInfo.FileName);
                }

                if (null == process)
                {
                    throw new Bam.Core.Exception("Unable to execute '{0}'", processStartInfo.FileName);
                }

                gccVersion = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                gccVersion = gccVersion.Trim();
            }

            // get target
            string gccTarget = null;
            {
                var processStartInfo = new System.Diagnostics.ProcessStartInfo();
                processStartInfo.FileName = toolset.Tool(typeof(C.ICompilerTool)).Executable(baseTarget);
                processStartInfo.ErrorDialog = true;
                processStartInfo.UseShellExecute = false;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.Arguments = "-dumpmachine";

                System.Diagnostics.Process process = null;
                try
                {
                    process = System.Diagnostics.Process.Start(processStartInfo);
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    throw new Bam.Core.Exception("'{0}': process filename '{1}'", ex.Message, processStartInfo.FileName);
                }

                if (null == process)
                {
                    throw new Bam.Core.Exception("Unable to execute '{0}'", processStartInfo.FileName);
                }

                gccTarget = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                gccTarget = gccTarget.Trim();
            }

            // get paths and targets
            string pathPrefix = null;
            string gxxIncludeDir = null;
            string libDir = null;
            var includePaths = new Bam.Core.StringArray();
            {
                var processStartInfo = new System.Diagnostics.ProcessStartInfo();
                processStartInfo.FileName = toolset.Tool(typeof(C.ICompilerTool)).Executable(baseTarget);
                processStartInfo.ErrorDialog = true;
                processStartInfo.UseShellExecute = false;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardError = true;
                processStartInfo.Arguments = "-v";

                System.Diagnostics.Process process = null;
                try
                {
                    process = System.Diagnostics.Process.Start(processStartInfo);
                }
                catch (System.ComponentModel.Win32Exception ex)
                {
                    throw new Bam.Core.Exception("'{0}': process filename '{1}'", ex.Message, processStartInfo.FileName);
                }

                if (null == process)
                {
                    throw new Bam.Core.Exception("Unable to execute '{0}'", processStartInfo.FileName);
                }

                var details = process.StandardOutput.ReadToEnd();
                process.WaitForExit();

                var splitDetails = details.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.None);

                foreach (var detail in splitDetails)
                {
                    const string configuredWith = "Configured with: ";
                    if (detail.StartsWith(configuredWith))
                    {
                        var configuredOptions = detail.Substring(configuredWith.Length);
                        var splitConfigureOptions = configuredOptions.Split(' ');

                        const string pathPrefixKey = "--prefix=";
                        const string gxxIncludeDirKey = "--with-gxx-include-dir=";
                        const string targetKey = "--target=";
                        const string libexecKey = "--libexecdir=";
                        const string slibDirKey = "--with-slibdir=";
                        foreach (var option in splitConfigureOptions)
                        {
                            if (option.StartsWith(pathPrefixKey))
                            {
                                pathPrefix = option.Substring(pathPrefixKey.Length).Trim(); ;
                            }
                            else if (option.StartsWith(gxxIncludeDirKey))
                            {
                                gxxIncludeDir = option.Substring(gxxIncludeDirKey.Length).Trim();
                            }
                            else if (option.StartsWith(targetKey))
                            {
                                gccTarget = option.Substring(targetKey.Length).Trim();
                            }
                            else if (option.StartsWith(libexecKey))
                            {
                                if (null != libDir)
                                {
                                    throw new Bam.Core.Exception("lib dir already defined");
                                }
                                libDir = option.Substring(libexecKey.Length).Trim();
                            }
                            else if (option.StartsWith(slibDirKey))
                            {
                                if (null != libDir)
                                {
                                    throw new Bam.Core.Exception("lib dir already defined");
                                }
                                libDir = option.Substring(slibDirKey.Length).Trim();
                            }
                        }

                        break;
                    }
                }

                if (null == gccTarget)
                {
                    foreach (var detail in splitDetails)
                    {
                        var targetKey = "Target: ";
                        if (detail.StartsWith(targetKey))
                        {
                            gccTarget = detail.Substring(targetKey.Length).Trim();
                        }
                    }
                }

                if ((null != gxxIncludeDir) && !gxxIncludeDir.StartsWith(pathPrefix))
                {
                    // remove any prefix directory separator so that Combine works
                    gxxIncludeDir = gxxIncludeDir.TrimStart(System.IO.Path.DirectorySeparatorChar);
                    gxxIncludeDir = System.IO.Path.Combine(pathPrefix, gxxIncludeDir);
                }

                // C include paths (http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html)
                includePaths.Add("/usr/local/include");
                includePaths.Add("/usr/include");

                // TODO: this looks like the targetIncludeFolder, and has been necessary
                {
                    // this is for some Linux distributions
                    var path = System.String.Format("/usr/include/{0}", gccTarget);
                    if (System.IO.Directory.Exists(path))
                    {
                        includePaths.Add(path);
                    }
                }
            }

            var gccDetails = new GccDetailData(gccVersion, includePaths, gxxIncludeDir, gccTarget, libDir);
            gccDetailsForTarget[baseTarget] = gccDetails;

            Bam.Core.Log.DebugMessage("Gcc version for target '{0}' is '{1}'", baseTarget.ToString(), gccDetails.Version);
            Bam.Core.Log.DebugMessage("Gcc machine type for target '{0}' is '{1}'", baseTarget.ToString(), gccDetails.Target);
            Bam.Core.Log.DebugMessage("Gxx include path for target '{0}' is '{1}'", baseTarget.ToString(), gccDetails.GxxIncludePath);

            return gccDetails;
        }
        Convert(
            this VisualCCommon.ICommonCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.NoLogo.HasValue)
            {
                if (settings.NoLogo.Value)
                {
                    commandLine.Add("-nologo");
                }
            }

            if (settings.RuntimeLibrary.HasValue)
            {
                switch (settings.RuntimeLibrary.Value)
                {
                case ERuntimeLibrary.MultiThreaded:
                    commandLine.Add("-MT");
                    break;

                case ERuntimeLibrary.MultiThreadedDebug:
                    commandLine.Add("-MTd");
                    break;

                case ERuntimeLibrary.MultiThreadedDebugDLL:
                    commandLine.Add("-MDd");
                    break;

                case ERuntimeLibrary.MultiThreadedDLL:
                    commandLine.Add("-MD");
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown runtime library, {0}", settings.RuntimeLibrary.Value.ToString());
                }
            }

            if (settings.WarningLevel.HasValue)
            {
                commandLine.Add(System.String.Format("-W{0}", settings.WarningLevel.Value.ToString("D")));
            }

            if (settings.EnableLanguageExtensions.HasValue)
            {
                if (!settings.EnableLanguageExtensions.Value)
                {
                    commandLine.Add("-Za");
                }
            }

            if (settings.Optimization.HasValue)
            {
                var common_optimization = (settings as C.ICommonCompilerSettings).Optimization;
                if (common_optimization.HasValue && common_optimization.Value != C.EOptimization.Custom)
                {
                    throw new Bam.Core.Exception("Compiler specific optimizations can only be set when the common optimization is C.EOptimization.Custom");
                }

                switch (settings.Optimization.Value)
                {
                case EOptimization.Full:
                    commandLine.Add("-Ox");
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown compiler optimization, {0}", settings.Optimization.Value.ToString());
                }
            }

            if (settings.IncreaseObjectFileSectionCount.HasValue)
            {
                if (settings.IncreaseObjectFileSectionCount.Value)
                {
                    commandLine.Add("-bigobj");
                }
            }
        }
Beispiel #51
0
        Convert(
            this MingwCommon.ICommonCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.AllWarnings.HasValue)
            {
                if (settings.AllWarnings.Value)
                {
                    commandLine.Add("-Wall");
                }
                else
                {
                    commandLine.Add("-Wno-all");
                }
            }
            if (settings.ExtraWarnings.HasValue)
            {
                if (settings.ExtraWarnings.Value)
                {
                    commandLine.Add("-Wextra");
                }
                else
                {
                    commandLine.Add("-Wno-extra");
                }
            }
            if (settings.Pedantic.HasValue)
            {
                if (settings.Pedantic.Value)
                {
                    commandLine.Add("-Wpedantic");
                }
                else
                {
                    commandLine.Add("-Wno-pedantic");
                }
            }
            if (settings.Visibility.HasValue)
            {
                switch (settings.Visibility.Value)
                {
                case EVisibility.Default:
                    commandLine.Add("-fvisibility=default");
                    break;

                case EVisibility.Hidden:
                    commandLine.Add("-fvisibility=hidden");
                    break;

                case EVisibility.Internal:
                    commandLine.Add("-fvisibility=internal");
                    break;

                case EVisibility.Protected:
                    commandLine.Add("-fvisibility=protected");
                    break;

                default:
                    throw new Bam.Core.Exception("Unrecognized visibility, {0}", settings.Visibility.Value.ToString());
                }
            }
            if (settings.StrictAliasing.HasValue)
            {
                if (settings.StrictAliasing.Value)
                {
                    commandLine.Add("-fstrict-aliasing");
                }
                else
                {
                    commandLine.Add("-fno-strict-aliasing");
                }
            }
        }
        ICollatedObjectPolicy.Collate(
            CollatedObject sender,
            Bam.Core.ExecutionContext context)
        {
            var sourcePath = sender.SourcePath;
            if (null == sender.Reference)
            {
                // the main file is not copied anywhere, as we copy required files around it where Xcode wrote the main file
                // this is managed by the Collation class, querying the build mode for where publishing is relative to
                // ignore any subdirectory on this module

                // convert the executable into an app bundle, if EPublishingType.WindowedApplication has been used as the type
                if ((sender.SubDirectory != null) && sender.SubDirectory.Parse().Contains(".app/"))
                {
                    var target = sender.SourceModule.MetaData as XcodeBuilder.Target;
                    target.MakeApplicationBundle();
                }

                return;
            }

            var commandLine = new Bam.Core.StringArray();
            (sender.Settings as CommandLineProcessor.IConvertToCommandLine).Convert(commandLine);

            var destinationPath = sender.Macros["CopyDir"].Parse();
            var commands = new Bam.Core.StringArray();
            commands.Add(System.String.Format("[[ ! -d {0} ]] && mkdir -p {0}", destinationPath));

            if (sender.SourceModule != null && sender.SourceModule.MetaData != null)
            {
                if ((null != sender.Reference) &&
                    (sender.SourceModule.PackageDefinition == sender.Reference.PackageDefinition) &&
                    (null == sender.Reference.SubDirectory) &&
                    (sender.SubDirectory.Parse() == "."))
                {
                    // special case that the module output is already in the right directory at build
                    return;
                }

                commands.Add(System.String.Format("{0} {1} $CONFIGURATION_BUILD_DIR/$EXECUTABLE_NAME {2} {3}",
                    CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                    commandLine.ToString(' '),
                    destinationPath,
                    CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));

                var target = sender.SourceModule.MetaData as XcodeBuilder.Target;
                var configuration = target.GetConfiguration(sender.SourceModule);
                target.AddPostBuildCommands(commands, configuration);
            }
            else
            {
                var isSymlink = (sender is CollatedSymbolicLink);

                var destinationFolder = "$CONFIGURATION_BUILD_DIR";
                if (sender.Reference != null)
                {
                    destinationFolder = "$CONFIGURATION_BUILD_DIR/$EXECUTABLE_FOLDER_PATH";
                }

                if (isSymlink)
                {
                    commands.Add(System.String.Format("{0} {1} {2} {3}/{4} {5}",
                        CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                        commandLine.ToString(' '),
                        sender.Macros["LinkTarget"].Parse(),
                        destinationFolder,
                        sender.CreateTokenizedString("$(0)/@filename($(1))", sender.SubDirectory, sender.SourcePath).Parse(),
                        CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                }
                else
                {
                    if (sender is CollatedDirectory)
                    {
                        var copySource = sourcePath.Parse();
                        if (sender.Macros["CopiedFilename"].IsAliased)
                        {
                            copySource = System.String.Format("{0}/*", copySource);
                        }

                        commands.Add(System.String.Format("{0} {1} {2} {3}/{4}/ {5}",
                            CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                            commandLine.ToString(' '),
                            copySource,
                            destinationFolder,
                            sender.CreateTokenizedString("$(0)/@ifnotempty($(CopiedFilename),$(CopiedFilename),@filename($(1)))", sender.SubDirectory, sourcePath).Parse(),
                            CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                    }
                    else
                    {
                        commands.Add(System.String.Format("{0} {1} {2} {3}/{4}/ {5}",
                            CommandLineProcessor.Processor.StringifyTool(sender.Tool as Bam.Core.ICommandLineTool),
                            commandLine.ToString(' '),
                            sourcePath.Parse(),
                            destinationFolder,
                            sender.SubDirectory.Parse(),
                            CommandLineProcessor.Processor.TerminatingArgs(sender.Tool as Bam.Core.ICommandLineTool)));
                    }
                }

                var target = sender.Reference.SourceModule.MetaData as XcodeBuilder.Target;
                var configuration = target.GetConfiguration(sender.Reference.SourceModule);
                target.AddPostBuildCommands(commands, configuration);
            }
        }
Beispiel #53
0
        Evaluate()
        {
            this.ReasonToExecute = null;
            if (!this.PerformCompilation)
            {
                return;
            }
            var graph   = Bam.Core.Graph.Instance;
            var factory = graph.MetaData as System.Threading.Tasks.TaskFactory;

            this.EvaluationTask = factory.StartNew(() =>
            {
                // does the object file exist?
                var objectFilePath = this.GeneratedPaths[Key].Parse();
                if (!System.IO.File.Exists(objectFilePath))
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.FileDoesNotExist(this.GeneratedPaths[Key]);
                    return;
                }
                var objectFileWriteTime = System.IO.File.GetLastWriteTime(objectFilePath);

                // has the source file been evaluated to be rebuilt?
                if ((this as IRequiresSourceModule).Source.ReasonToExecute != null)
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(this.GeneratedPaths[Key], this.InputPath);
                    return;
                }

                // is the source file newer than the object file?
                var sourcePath      = this.InputPath.Parse();
                var sourceWriteTime = System.IO.File.GetLastWriteTime(sourcePath);
                if (sourceWriteTime > objectFileWriteTime)
                {
                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(this.GeneratedPaths[Key], this.InputPath);
                    return;
                }

                if (this is WinResource)
                {
                    return;
                }

                // are there any headers as explicit dependencies (procedurally generated most likely), which are newer?
                var explicitHeadersUpdated  = new Bam.Core.StringArray();
                var explicitHeadersDeferred = new Bam.Core.StringArray();
                foreach (var dep in this.Dependents)
                {
                    if (!(dep is HeaderFile))
                    {
                        continue;
                    }
                    if (null == dep.ReasonToExecute)
                    {
                        continue;
                    }
                    if (dep.ReasonToExecute.Reason == Bam.Core.ExecuteReasoning.EReason.InputFileIsNewer)
                    {
                        explicitHeadersUpdated.AddUnique((dep as HeaderFile).InputPath.Parse());
                    }
                    else if (dep.ReasonToExecute.Reason == Bam.Core.ExecuteReasoning.EReason.DeferredEvaluation)
                    {
                        explicitHeadersDeferred.AddUnique((dep as HeaderFile).InputPath.Parse());
                    }
                }

                var includeSearchPaths = (this.Settings as C.ICommonCompilerSettings).IncludePaths;
                // implicitly search the same directory as the source path, as this is not needed to be explicitly on the include path list
                includeSearchPaths.AddUnique(this.CreateTokenizedString("@dir($(0))", this.InputPath));

                var filesToSearch = new System.Collections.Generic.Queue <string>();
                filesToSearch.Enqueue(sourcePath);

                var headerPathsFound = new Bam.Core.StringArray();
                while (filesToSearch.Count > 0)
                {
                    var fileToSearch = filesToSearch.Dequeue();

                    string fileContents = null;
                    using (System.IO.TextReader reader = new System.IO.StreamReader(fileToSearch))
                    {
                        fileContents = reader.ReadToEnd();
                    }

                    // never know if developers are consistent with #include "header.h" or #include <header.h> so look for both
                    // nor the amount of whitespace after #include
                    var matches = System.Text.RegularExpressions.Regex.Matches(
                        fileContents,
                        "^\\s*#include\\s*[\"<]([^\\s]*)[\">]",
                        System.Text.RegularExpressions.RegexOptions.Multiline);
                    if (0 == matches.Count)
                    {
                        // no #includes
                        return;
                    }

                    foreach (System.Text.RegularExpressions.Match match in matches)
                    {
                        var headerFile = match.Groups[1].Value;
                        bool exists    = false;
                        // search for the file on the include paths the compiler uses
                        foreach (var includePath in includeSearchPaths)
                        {
                            try
                            {
                                var potentialPath = System.IO.Path.Combine(includePath.Parse(), headerFile);
                                if (!System.IO.File.Exists(potentialPath))
                                {
                                    continue;
                                }
                                potentialPath       = System.IO.Path.GetFullPath(potentialPath);
                                var headerWriteTime = System.IO.File.GetLastWriteTime(potentialPath);

                                // early out - header is newer than generated object file
                                if (headerWriteTime > objectFileWriteTime)
                                {
                                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(
                                        this.GeneratedPaths[Key],
                                        Bam.Core.TokenizedString.CreateVerbatim(potentialPath));
                                    return;
                                }

                                // found #included header in list of explicitly dependent headers that have been updated
                                if (explicitHeadersUpdated.Contains(potentialPath))
                                {
                                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.InputFileNewer(
                                        this.GeneratedPaths[Key],
                                        Bam.Core.TokenizedString.CreateVerbatim(potentialPath));
                                    return;
                                }
                                // found #included header in list of explicitly dependent headers that require a deferred evaluation
                                if (explicitHeadersDeferred.Contains(potentialPath))
                                {
                                    this.ReasonToExecute = Bam.Core.ExecuteReasoning.DeferredUntilBuild(this.GeneratedPaths[Key]);
                                    return;
                                }

                                if (!headerPathsFound.Contains(potentialPath))
                                {
                                    headerPathsFound.Add(potentialPath);
                                    filesToSearch.Enqueue(potentialPath);
                                }

                                exists = true;
                                break;
                            }
                            catch (System.Exception ex)
                            {
                                Bam.Core.Log.MessageAll("IncludeDependency Exception: Cannot locate '{0}' on '{1}' due to {2}", headerFile, includePath, ex.Message);
                            }
                        }

                        if (!exists)
                        {
#if false
                            Bam.Core.Log.DebugMessage("***** Could not locate '{0}' on any include search path, included from {1}:\n{2}",
                                                      match.Groups[1],
                                                      fileToSearch,
                                                      entry.includePaths.ToString('\n'));
#endif
                        }
                    }
                }

                return;
            });
        }
Beispiel #54
0
        Convert(
            this C.ICommonAssemblerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            var module = (settings as Bam.Core.Settings).Module;

            switch (settings.Bits.Value)
            {
            case C.EBit.SixtyFour:
                commandLine.Add("-m64");
                break;

            case C.EBit.ThirtyTwo:
                commandLine.Add("-m32");
                break;

            default:
                throw new Bam.Core.Exception("Unknown machine bit size, {0}", settings.Bits.Value.ToString());
            }
            if (settings.DebugSymbols)
            {
                commandLine.Add("-g");
            }
            switch (settings.OutputType)
            {
            case C.ECompilerOutput.CompileOnly:
                commandLine.Add(System.String.Format("-c -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToString()));
                break;

            case C.ECompilerOutput.Preprocess:
                commandLine.Add(System.String.Format("-E -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToString()));
                break;

            default:
                throw new Bam.Core.Exception("Unknown output type, {0}", settings.OutputType.ToString());
            }
            if (settings.WarningsAsErrors)
            {
                commandLine.Add("-Werror");
            }
            else
            {
                commandLine.Add("-Wno-error");
            }
            foreach (var path in settings.IncludePaths)
            {
                commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary()));
            }
            foreach (var define in settings.PreprocessorDefines)
            {
                if (System.String.IsNullOrEmpty(define.Value))
                {
                    commandLine.Add(System.String.Format("-D{0}", define.Key));
                }
                else
                {
                    var value = define.Value;
                    if (value.Contains("\""))
                    {
                        value = value.Replace("\"", "\\\"");
                    }
                    commandLine.Add(System.String.Format("-D{0}={1}", define.Key, value));
                }
            }
        }
Beispiel #55
0
        IDiskImagePolicy.CreateDMG(
            DiskImage sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool compiler,
            Bam.Core.TokenizedString sourceFolderPath,
            Bam.Core.TokenizedString outputPath)
        {
            var volumeName = sender.CreateTokenizedString("$(OutputName)").Parse();
            var tempDiskImagePathName = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString() + ".dmg"; // must have .dmg extension
            var diskImagePathName = outputPath.ToString();

            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 dmgDir = System.IO.Path.GetDirectoryName(diskImagePathName);
            if (!System.IO.Directory.Exists(dmgDir))
            {
                System.IO.Directory.CreateDirectory(dmgDir);
            }

            // hdiutil convert myimg.dmg -format UDZO -o myoutputimg.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(diskImagePathName);
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }
        }
        Convert(
            this C.ICommonCompilerSettings settings,
            Bam.Core.StringArray commandLine)
        {
            if (settings.Bits.HasValue)
            {
                switch (settings.Bits.Value)
                {
                case C.EBit.SixtyFour:
                    commandLine.Add("-m64");
                    break;

                case C.EBit.ThirtyTwo:
                    commandLine.Add("-m32");
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown machine bit size, {0}", settings.Bits.Value.ToString());
                }
            }
            if (settings.DebugSymbols.HasValue)
            {
                if (settings.DebugSymbols.Value)
                {
                    commandLine.Add("-g");
                }
            }
            foreach (var warning in settings.DisableWarnings)
            {
                commandLine.Add(System.String.Format("-Wno-{0}", warning));
            }
            foreach (var path in settings.IncludePaths)
            {
                commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary()));
            }
            if (settings.OmitFramePointer.HasValue)
            {
                commandLine.Add(settings.OmitFramePointer.Value ? "-fomit-frame-pointer" : "-fno-omit-frame-pointer");
            }
            if (settings.Optimization.HasValue)
            {
                switch (settings.Optimization.Value)
                {
                case C.EOptimization.Off:
                    commandLine.Add("-O0");
                    break;

                case C.EOptimization.Size:
                    commandLine.Add("-Os");
                    break;

                case C.EOptimization.Speed:
                    commandLine.Add("-O1");
                    break;

                case C.EOptimization.Full:
                    commandLine.Add("-O3");
                    break;

                default:
                    throw new Bam.Core.Exception("Unknown optimization level, {0}", settings.Optimization.Value.ToString());
                }
            }
            foreach (var define in settings.PreprocessorDefines)
            {
                if (System.String.IsNullOrEmpty(define.Value))
                {
                    commandLine.Add(System.String.Format("-D{0}", define.Key));
                }
                else
                {
                    var value = define.Value;
                    if (value.Contains("\""))
                    {
                        value = value.Replace("\"", "\\\"");
                    }
                    commandLine.Add(System.String.Format("-D{0}={1}", define.Key, value));
                }
            }
            foreach (var undefine in settings.PreprocessorUndefines)
            {
                commandLine.Add(System.String.Format("-U{0}", undefine));
            }
            foreach (var path in settings.SystemIncludePaths)
            {
                commandLine.Add(System.String.Format("-I{0}", path.ParseAndQuoteIfNecessary()));
            }
            if (settings.TargetLanguage.HasValue)
            {
                switch (settings.TargetLanguage.Value)
                {
                case C.ETargetLanguage.C:
                    commandLine.Add("-x c");
                    break;

                case C.ETargetLanguage.Cxx:
                    commandLine.Add("-x c++");
                    break;

                case C.ETargetLanguage.ObjectiveC:
                    commandLine.Add("-x objective-c");
                    break;

                case C.ETargetLanguage.ObjectiveCxx:
                    commandLine.Add("-x objective-c++");
                    break;

                default:
                    throw new Bam.Core.Exception("Unsupported target language, {0}", settings.TargetLanguage.Value.ToString());
                }
            }
            if (settings.WarningsAsErrors.HasValue)
            {
                if (settings.WarningsAsErrors.Value)
                {
                    commandLine.Add("-Werror");
                }
                else
                {
                    commandLine.Add("-Wno-error");
                }
            }
            if (settings.OutputType.HasValue)
            {
                var module = (settings as Bam.Core.Settings).Module;
                switch (settings.OutputType)
                {
                case C.ECompilerOutput.CompileOnly:
                    commandLine.Add(System.String.Format("-c -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToString()));
                    break;

                case C.ECompilerOutput.Preprocess:
                    commandLine.Add(System.String.Format("-E -o {0}", module.GeneratedPaths[C.ObjectFile.Key].ToString()));
                    break;
                }
            }
        }
Beispiel #57
0
        public object Build(
            CSharp.Assembly moduleToBuild,
            out System.Boolean success)
        {
            var assemblyModule = moduleToBuild as Bam.Core.BaseModule;
            var node = assemblyModule.OwningNode;
            var target = node.Target;
            var assemblyOptions = assemblyModule.Options;
            var options = assemblyOptions as CSharp.IOptions;

            if (node.ExternalDependents != null)
            {
                var keyFilters = new Bam.Core.Array<Bam.Core.LocationKey>(
                    CSharp.Assembly.OutputFile
                    );
                var dependentAssemblies = new Bam.Core.LocationArray();
                node.ExternalDependents.FilterOutputLocations(keyFilters, dependentAssemblies);

                foreach (var loc in dependentAssemblies)
                {
                    options.References.Add(loc.GetSinglePath());
                }
            }

            var sourceFiles = new Bam.Core.StringArray();
            var fields = moduleToBuild.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
            foreach (var field in fields)
            {
                // C# files
                {
                    var sourceFileAttributes = field.GetCustomAttributes(typeof(Bam.Core.SourceFilesAttribute), false);
                    if (null != sourceFileAttributes && sourceFileAttributes.Length > 0)
                    {
                        var sourceField = field.GetValue(moduleToBuild);
                        if (sourceField is Bam.Core.Location)
                        {
                            var file = sourceField as Bam.Core.Location;
                            var absolutePath = file.GetSinglePath();
                            if (!System.IO.File.Exists(absolutePath))
                            {
                                throw new Bam.Core.Exception("Source file '{0}' does not exist", absolutePath);
                            }

                            sourceFiles.Add(absolutePath);
                        }
                        else if (sourceField is Bam.Core.FileCollection)
                        {
                            var sourceCollection = sourceField as Bam.Core.FileCollection;
                            // TODO: convert to var
                            foreach (Bam.Core.Location location in sourceCollection)
                            {
                                var absolutePath = location.AbsolutePath;
                                if (!System.IO.File.Exists(absolutePath))
                                {
                                    throw new Bam.Core.Exception("Source file '{0}' does not exist", absolutePath);
                                }

                                sourceFiles.Add(absolutePath);
                            }
                        }
                        else
                        {
                            throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString());
                        }
                    }
                }

                // WPF application definition .xaml file
                {
                    var xamlFileAttributes = field.GetCustomAttributes(typeof(CSharp.ApplicationDefinitionAttribute), false);
                    if (null != xamlFileAttributes && xamlFileAttributes.Length > 0)
                    {
                        var sourceField = field.GetValue(moduleToBuild);
                        if (sourceField is Bam.Core.Location)
                        {
                            var file = sourceField as Bam.Core.Location;
                            var absolutePath = file.GetSinglePath();
                            if (!System.IO.File.Exists(absolutePath))
                            {
                                throw new Bam.Core.Exception("Application definition file '{0}' does not exist", absolutePath);
                            }

                            var csPath = absolutePath + ".cs";
                            if (!System.IO.File.Exists(csPath))
                            {
                                throw new Bam.Core.Exception("Associated source file '{0}' to application definition file '{1}' does not exist", csPath, absolutePath);
                            }

                            sourceFiles.Add(csPath);
                        }
                        else if (sourceField is Bam.Core.FileCollection)
                        {
                            var sourceCollection = sourceField as Bam.Core.FileCollection;
                            if (sourceCollection.Count != 1)
                            {
                                throw new Bam.Core.Exception("There can be only one application definition");
                            }

                            // TODO: convert to var
                            foreach (string absolutePath in sourceCollection)
                            {
                                if (!System.IO.File.Exists(absolutePath))
                                {
                                    throw new Bam.Core.Exception("Application definition file '{0}' does not exist", absolutePath);
                                }

                                var csPath = absolutePath + ".cs";
                                if (!System.IO.File.Exists(csPath))
                                {
                                    throw new Bam.Core.Exception("Associated source file '{0}' to application definition file '{1}' does not exist", csPath, absolutePath);
                                }

                                sourceFiles.Add(csPath);
                            }
                        }
                        else
                        {
                            throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString());
                        }
                    }
                }

                // WPF page .xaml files
                {
                    var xamlFileAttributes = field.GetCustomAttributes(typeof(CSharp.PagesAttribute), false);
                    if (null != xamlFileAttributes && xamlFileAttributes.Length > 0)
                    {
                        var sourceField = field.GetValue(moduleToBuild);
                        if (sourceField is Bam.Core.Location)
                        {
                            var file = sourceField as Bam.Core.Location;
                            var absolutePath = file.GetSinglePath();
                            if (!System.IO.File.Exists(absolutePath))
                            {
                                throw new Bam.Core.Exception("Page file '{0}' does not exist", absolutePath);
                            }

                            var csPath = absolutePath + ".cs";
                            if (!System.IO.File.Exists(csPath))
                            {
                                throw new Bam.Core.Exception("Associated source file '{0}' to page file '{1}' does not exist", csPath, absolutePath);
                            }

                            sourceFiles.Add(csPath);
                        }
                        else if (sourceField is Bam.Core.FileCollection)
                        {
                            var sourceCollection = sourceField as Bam.Core.FileCollection;
                            if (sourceCollection.Count != 1)
                            {
                                throw new Bam.Core.Exception("There can be only one page file");
                            }

                            // TODO: convert to var
                            foreach (string absolutePath in sourceCollection)
                            {
                                if (!System.IO.File.Exists(absolutePath))
                                {
                                    throw new Bam.Core.Exception("Page file '{0}' does not exist", absolutePath);
                                }

                                var csPath = absolutePath + ".cs";
                                if (!System.IO.File.Exists(csPath))
                                {
                                    throw new Bam.Core.Exception("Associated source file '{0}' to page file '{1}' does not exist", csPath, absolutePath);
                                }

                                sourceFiles.Add(csPath);
                            }
                        }
                        else
                        {
                            throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString());
                        }
                    }
                }
            }

            if (0 == sourceFiles.Count)
            {
                throw new Bam.Core.Exception("There were no source files specified for the module '{0}'", node.ModuleName);
            }

            // dependency checking
            {
                var inputLocations = new Bam.Core.LocationArray();
                foreach (var source in sourceFiles)
                {
                    inputLocations.Add(Bam.Core.FileLocation.Get(source));
                }
                var outputLocations = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.File, Bam.Core.Location.EExists.WillExist);
                if (!RequiresBuilding(outputLocations, inputLocations))
                {
                    Bam.Core.Log.DebugMessage("'{0}' is up-to-date", node.UniqueModuleName);
                    success = true;
                    return null;
                }
            }

            // at this point, we know the node outputs need building

            // create all directories required
            var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist);
            foreach (var dir in dirsToCreate)
            {
                var dirPath = dir.GetSinglePath();
                NativeBuilder.MakeDirectory(dirPath);
            }

            var commandLineBuilder = new Bam.Core.StringArray();
            if (options is CommandLineProcessor.ICommandLineSupport)
            {
                var commandLineOption = options as CommandLineProcessor.ICommandLineSupport;
                commandLineOption.ToCommandLineArguments(commandLineBuilder, target, null);
            }
            else
            {
                throw new Bam.Core.Exception("Compiler options does not support command line translation");
            }

            foreach (var source in sourceFiles)
            {
                if (source.Contains(" "))
                {
                    commandLineBuilder.Add(System.String.Format("\"{0}\"", source));
                }
                else
                {
                    commandLineBuilder.Add(source);
                }
            }

            var compilerTool = target.Toolset.Tool(typeof(CSharp.ICSharpCompilerTool));

            var exitCode = CommandLineProcessor.Processor.Execute(node, compilerTool, commandLineBuilder);
            success = (0 == exitCode);

            return null;
        }
Beispiel #58
0
        IDiskImagePolicy.CreateDMG(
            DiskImage sender,
            Bam.Core.ExecutionContext context,
            Bam.Core.ICommandLineTool compiler,
            Bam.Core.TokenizedString sourceFolderPath,
            Bam.Core.TokenizedString outputPath)
        {
            var volumeName            = sender.CreateTokenizedString("$(OutputName)").Parse();
            var tempDiskImagePathName = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString() + ".dmg"; // must have .dmg extension
            var diskImagePathName     = outputPath.ToString();

            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 dmgDir = System.IO.Path.GetDirectoryName(diskImagePathName);

            Bam.Core.IOWrapper.CreateDirectoryIfNotExists(dmgDir);

            // hdiutil convert myimg.dmg -format UDZO -o myoutputimg.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(diskImagePathName);
                CommandLineProcessor.Processor.Execute(context, compiler, args);
            }
        }
Beispiel #59
0
        public object Build(
            CSharp.Assembly moduleToBuild,
            out System.Boolean success)
        {
            var assemblyModule = moduleToBuild as Bam.Core.BaseModule;
            var node = assemblyModule.OwningNode;
            var target = node.Target;
            var assemblyOptions = assemblyModule.Options;
            var options = assemblyOptions as CSharp.OptionCollection;

            var inputVariables = new MakeFileVariableDictionary();
            if (node.ExternalDependents != null)
            {
                foreach (var dependentNode in node.ExternalDependents)
                {
                    if (null != dependentNode.Data)
                    {
                        continue;
                    }

                    var keyFilters = new Bam.Core.Array<Bam.Core.LocationKey>(
                        CSharp.Assembly.OutputFile
                        );
                    var assemblyLocations = new Bam.Core.LocationArray();
                    dependentNode.FilterOutputLocations(keyFilters, assemblyLocations);
                    var data = dependentNode.Data as MakeFileData;
                    var csharpOptions = options as CSharp.IOptions;
                    foreach (var loc in assemblyLocations)
                    {
                        csharpOptions.References.Add(loc.GetSinglePath());
                        inputVariables.Add(CSharp.Assembly.OutputFile, data.VariableDictionary[CSharp.Assembly.OutputDir]);
                    }
                }
            }

            var sourceFiles = new Bam.Core.StringArray();
            var fields = moduleToBuild.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
            foreach (var field in fields)
            {
                // C# files
                {
                    var sourceFileAttributes = field.GetCustomAttributes(typeof(Bam.Core.SourceFilesAttribute), false);
                    if (null != sourceFileAttributes && sourceFileAttributes.Length > 0)
                    {
                        var sourceField = field.GetValue(moduleToBuild);
                        if (sourceField is Bam.Core.Location)
                        {
                            var file = sourceField as Bam.Core.Location;
                            var absolutePath = file.GetSinglePath();
                            if (!System.IO.File.Exists(absolutePath))
                            {
                                throw new Bam.Core.Exception("Source file '{0}' does not exist", absolutePath);
                            }

                            sourceFiles.Add(absolutePath);
                        }
                        else if (sourceField is Bam.Core.FileCollection)
                        {
                            var sourceCollection = sourceField as Bam.Core.FileCollection;
                            // TODO: convert to var
                            foreach (Bam.Core.Location location in sourceCollection)
                            {
                                var absolutePath = location.GetSinglePath();
                                if (!System.IO.File.Exists(absolutePath))
                                {
                                    throw new Bam.Core.Exception("Source file '{0}' does not exist", absolutePath);
                                }

                                sourceFiles.Add(absolutePath);
                            }
                        }
                        else
                        {
                            throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString());
                        }
                    }
                }

                // WPF application definition .xaml file
                {
                    var xamlFileAttributes = field.GetCustomAttributes(typeof(CSharp.ApplicationDefinitionAttribute), false);
                    if (null != xamlFileAttributes && xamlFileAttributes.Length > 0)
                    {
                        var sourceField = field.GetValue(moduleToBuild);
                        if (sourceField is Bam.Core.Location)
                        {
                            var file = sourceField as Bam.Core.Location;
                            var absolutePath = file.GetSinglePath();
                            if (!System.IO.File.Exists(absolutePath))
                            {
                                throw new Bam.Core.Exception("Application definition file '{0}' does not exist", absolutePath);
                            }

                            var csPath = absolutePath + ".cs";
                            if (!System.IO.File.Exists(csPath))
                            {
                                throw new Bam.Core.Exception("Associated source file '{0}' to application definition file '{1}' does not exist", csPath, absolutePath);
                            }

                            sourceFiles.Add(csPath);
                        }
                        else if (sourceField is Bam.Core.FileCollection)
                        {
                            var sourceCollection = sourceField as Bam.Core.FileCollection;
                            if (sourceCollection.Count != 1)
                            {
                                throw new Bam.Core.Exception("There can be only one application definition");
                            }

                            // TODO: convert to var
                            foreach (string absolutePath in sourceCollection)
                            {
                                if (!System.IO.File.Exists(absolutePath))
                                {
                                    throw new Bam.Core.Exception("Application definition file '{0}' does not exist", absolutePath);
                                }

                                var csPath = absolutePath + ".cs";
                                if (!System.IO.File.Exists(csPath))
                                {
                                    throw new Bam.Core.Exception("Associated source file '{0}' to application definition file '{1}' does not exist", csPath, absolutePath);
                                }

                                sourceFiles.Add(csPath);
                            }
                        }
                        else
                        {
                            throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString());
                        }
                    }
                }

                // WPF page .xaml files
                {
                    var xamlFileAttributes = field.GetCustomAttributes(typeof(CSharp.PagesAttribute), false);
                    if (null != xamlFileAttributes && xamlFileAttributes.Length > 0)
                    {
                        var sourceField = field.GetValue(moduleToBuild);
                        if (sourceField is Bam.Core.Location)
                        {
                            var file = sourceField as Bam.Core.Location;
                            var absolutePath = file.GetSinglePath();
                            if (!System.IO.File.Exists(absolutePath))
                            {
                                throw new Bam.Core.Exception("Page file '{0}' does not exist", absolutePath);
                            }

                            var csPath = absolutePath + ".cs";
                            if (!System.IO.File.Exists(csPath))
                            {
                                throw new Bam.Core.Exception("Associated source file '{0}' to page file '{1}' does not exist", csPath, absolutePath);
                            }

                            sourceFiles.Add(csPath);
                        }
                        else if (sourceField is Bam.Core.FileCollection)
                        {
                            var sourceCollection = sourceField as Bam.Core.FileCollection;
                            if (sourceCollection.Count != 1)
                            {
                                throw new Bam.Core.Exception("There can be only one page file");
                            }

                            // TODO: convert to var
                            foreach (string absolutePath in sourceCollection)
                            {
                                if (!System.IO.File.Exists(absolutePath))
                                {
                                    throw new Bam.Core.Exception("Page file '{0}' does not exist", absolutePath);
                                }

                                var csPath = absolutePath + ".cs";
                                if (!System.IO.File.Exists(csPath))
                                {
                                    throw new Bam.Core.Exception("Associated source file '{0}' to page file '{1}' does not exist", csPath, absolutePath);
                                }

                                sourceFiles.Add(csPath);
                            }
                        }
                        else
                        {
                            throw new Bam.Core.Exception("Field '{0}' of '{1}' should be of type Bam.Core.File or Bam.Core.FileCollection, not '{2}'", field.Name, node.ModuleName, sourceField.GetType().ToString());
                        }
                    }
                }
            }

            if (0 == sourceFiles.Count)
            {
                throw new Bam.Core.Exception("There were no source files specified for the module '{0}'", node.ModuleName);
            }

            // at this point, we know the node outputs need building

            // create all directories required
            var dirsToCreate = moduleToBuild.Locations.FilterByType(Bam.Core.ScaffoldLocation.ETypeHint.Directory, Bam.Core.Location.EExists.WillExist);

            var commandLineBuilder = new Bam.Core.StringArray();
            if (options is CommandLineProcessor.ICommandLineSupport)
            {
                var commandLineOption = options as CommandLineProcessor.ICommandLineSupport;
                commandLineOption.ToCommandLineArguments(commandLineBuilder, target, null);
            }
            else
            {
                throw new Bam.Core.Exception("Compiler options does not support command line translation");
            }

            foreach (var source in sourceFiles)
            {
                if (source.Contains(" "))
                {
                    commandLineBuilder.Add(System.String.Format("\"{0}\"", source));
                }
                else
                {
                    commandLineBuilder.Add(source);
                }
            }

            var compilerInstance = target.Toolset.Tool(typeof(CSharp.ICSharpCompilerTool));
            var executablePath = compilerInstance.Executable((Bam.Core.BaseTarget)target);

            var recipes = new Bam.Core.StringArray();
            if (executablePath.Contains(" "))
            {
                recipes.Add(System.String.Format("\"{0}\" {1}", executablePath, commandLineBuilder.ToString(' ')));
            }
            else
            {
                recipes.Add(System.String.Format("{0} {1}", executablePath, commandLineBuilder.ToString(' ')));
            }

            var makeFile = new MakeFile(node, this.topLevelMakeFilePath);

            var rule = new MakeFileRule(
                moduleToBuild,
                CSharp.Assembly.OutputFile,
                node.UniqueModuleName,
                dirsToCreate,
                inputVariables,
                null,
                recipes);

            var toolOutputLocKeys = compilerInstance.OutputLocationKeys(moduleToBuild);
            var outputFileLocations = moduleToBuild.Locations.Keys(Bam.Core.ScaffoldLocation.ETypeHint.File, Bam.Core.Location.EExists.WillExist);
            var outputFileLocationsOfInterest = outputFileLocations.Intersect(toolOutputLocKeys);
            rule.OutputLocationKeys = outputFileLocationsOfInterest;
            makeFile.RuleArray.Add(rule);

            var makeFilePath = MakeFileBuilder.GetMakeFilePathName(node);
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(makeFilePath));
            Bam.Core.Log.DebugMessage("Makefile : '{0}'", makeFilePath);

            using (System.IO.TextWriter makeFileWriter = new System.IO.StreamWriter(makeFilePath))
            {
                makeFile.Write(makeFileWriter);
            }

            success = true;
            var compilerTool = compilerInstance as Bam.Core.ITool;
            System.Collections.Generic.Dictionary<string, Bam.Core.StringArray> environment = null;
            if (compilerTool is Bam.Core.IToolEnvironmentVariables)
            {
                environment = (compilerTool as Bam.Core.IToolEnvironmentVariables).Variables((Bam.Core.BaseTarget)target);
            }
            var returnData = new MakeFileData(makeFilePath, makeFile.ExportedTargets, makeFile.ExportedVariables, environment);
            return returnData;
        }