Example #1
0
        private IEnumerable <XElement> GetConditionedValues(VcxprojFile vcxprojFile, string name, MultiValueDictionary <string, object> valuesByQualifier)
        {
            var xName   = XName.Get(name, MsBuildNamespace);
            var builder = new StringBuilder();

            HashSet <object> unconditionedValues = null;

            foreach (var qualifier in valuesByQualifier.Keys)
            {
                var values = valuesByQualifier[qualifier];
                if (unconditionedValues == null)
                {
                    unconditionedValues = new HashSet <object>(values);
                }
                else
                {
                    unconditionedValues.IntersectWith(values);
                }
            }

            if (unconditionedValues != null && unconditionedValues.Count > 0)
            {
                foreach (var dir in unconditionedValues)
                {
                    builder.Append(ValueToMsBuild(dir, vcxprojFile));
                    builder.Append(";");
                }

                yield return(new XElement(xName, builder.ToString()));
            }

            var qualifiers = new HashSet <string>();

            foreach (var qualifier in valuesByQualifier.Keys)
            {
                string qualifierComparisonValue = vcxprojFile.GetQualifierComparisonValue(qualifier);
                if (!qualifiers.Add(qualifierComparisonValue))
                {
                    continue;
                }

                var conditionedValues = valuesByQualifier[qualifier].Except(unconditionedValues);
                if (conditionedValues.Any())
                {
                    builder.Clear();
                    foreach (var conditionedValue in conditionedValues)
                    {
                        builder.Append(ValueToMsBuild(conditionedValue, vcxprojFile));
                        builder.Append(";");
                    }

                    builder.Append($"%({name})");
                    yield return(new XElement(
                                     xName,
                                     new XAttribute("Condition", $"'{vcxprojFile.UnevaluatedQualifierComparisonProperty}'=='{qualifierComparisonValue}'"),
                                     builder.ToString()));
                }
            }
        }
Example #2
0
        private IReadOnlyList <MsbuildFile> GenerateMsbuildFiles()
        {
            var msbuildFiles = new List <MsbuildFile>();

            // Retrieve Process pip nodes. Then, hydrate them and group by their spec path.
            var specFileGroupedProcessPips = m_context
                                             .ScheduledGraph
                                             .Nodes
                                             .Where(nodeId => m_context.PipGraph.PipTable.GetPipType(nodeId.ToPipId()) == PipType.Process)
                                             .Select(nodeId => m_context.PipGraph.PipTable.HydratePip(nodeId.ToPipId(), BuildXL.Pips.PipQueryContext.IdeGenerator))
                                             .GroupBy(p => p.Provenance.Token.Path);

            foreach (var processPips in specFileGroupedProcessPips)
            {
                var specFile             = processPips.Key;
                var categorizedProcesses = processPips.OfType <Process>().Select(p => ProcessWithType.Categorize(m_context, p));

                MsbuildFile msbuildFile = null;
                if (categorizedProcesses.Any(a => a.Type == ProcessType.Csc))
                {
                    msbuildFile = new CsprojFile(m_context, specFile);
                }
                else if (categorizedProcesses.Any(a => a.Type == ProcessType.Cl))
                {
                    msbuildFile = new VcxprojFile(m_context, specFile);
                }

                if (msbuildFile != null)
                {
                    msbuildFile.VisitProcesses(categorizedProcesses);

                    // SealDirectories might not be scheduled so look at the full graph to find them.
                    foreach (var directory in m_context.PipGraph.GetPipsPerSpecFile(specFile).OfType <SealDirectory>())
                    {
                        msbuildFile.VisitDirectory(directory);
                    }

                    msbuildFile.EndVisitingProject();
                    msbuildFiles.Add(msbuildFile);
                }
            }

            return(msbuildFiles);
        }