Exemplo n.º 1
0
        private void ParseConfigurations(XElement configs, ConfigurationHolder holder)
        {
            handleImport(configs, (XElement elem) => {
                ParseConfigurations(elem, holder);
            });

            XElement shared = configs.Element("shared");

            if (shared != null)
            {
                Configuration config = new Configuration(holder.GetName() + "_shared");
                config.IsShared = true;
                ParseConfiguration(shared, config, holder);

                holder.SetSharedConfiguration(config);
            }

            foreach (XElement configElem in configs.Elements("configuration"))
            {
                Configuration config = new Configuration((string)configElem.Attribute("name"));

                ParseConfiguration(configElem, config, holder);

                holder.AddConfiguration(config);
            }
        }
Exemplo n.º 2
0
        private void ParseConfiguration(XElement configElem, Configuration config, ConfigurationHolder holder)
        {
            handleImport(configElem, (XElement elem) => {
                ParseConfiguration(elem, config, holder);
            });

            foreach (XElement elem in configElem.Elements())
            {
                if (elem.Name.LocalName.ToLower() == "compile")
                {
                    var cfg           = config;
                    var patternAttrib = elem.Attribute("files");
                    if (patternAttrib != null)
                    {
                        string sourceRoot = holder.SourceRootRelative();
                        if (sourceRoot == null)
                        {
                            sourceRoot = m_currentWorkingDirectory;
                        }

                        string            pattern = Path.Combine(sourceRoot, (string)patternAttrib);
                        ConfigurationRule rule    = holder.FindOrCreateRule(pattern);
                        cfg = new Configuration(config.Name);
                        if (config.IsShared)
                        {
                            rule.SetSharedConfiguration(cfg);
                        }
                        else
                        {
                            rule.AddConfiguration(cfg);
                        }
                    }

                    ParseCompileOptions(elem, cfg);
                }
                else if (elem.Name.LocalName.ToLower() == "link")
                {
                    foreach (XElement linkElem in elem.Elements())
                    {
                        if (!config.AddLinkOption(linkElem.Name.LocalName, (string)linkElem.Value))
                        {
                            m_errors = true;
                        }
                    }
                }
                else if (!config.AddOption(elem.Name.LocalName, (string)elem.Value))
                {
                    m_errors = true;
                }
            }
        }
Exemplo n.º 3
0
        /// This assumes that shared is already merged in (in this, not parent)
        /// It also assumes that all available configurations have already been added to this
        /// rule before the merge
        public void Merge(ConfigurationHolder parent)
        {
            foreach (Configuration thisConfig in Configurations)
            {
                Configuration parentConfig = parent.FindConfiguration(thisConfig.Name);
                if (parentConfig != null)
                {
                    thisConfig.Merge(parentConfig);
                }

                if (parent.SharedConfiguration != null)
                {
                    thisConfig.Merge(parent.SharedConfiguration);
                }
            }
        }
Exemplo n.º 4
0
        private bool AddSourceToTarget(Source source, Target target, ref List <Source> targetSources)
        {
            if (source.Target != null)
            {
                Utils.WriteLine("Warning, source " + source.Path + " matches multiple targets. " + source.Target.Name + " and " + target.Name);
                return(false);
            }

            source.Target = target;

            if (source.Filter == null)
            {
                Utils.WriteLine("Error, source " + source.Path + " have no filter.");
                return(false);
            }

            targetSources.Add(source);

            m_writer.WriteStartElement(target.BuildElementName);
            m_writer.WriteAttributeString("Include", Utils.RelativePath(source.Path, m_project.Path));

            // Write custom build options
            if (target.BuildConfiguration != null)
            {
                foreach (Configuration config in m_project.Configurations)
                {
                    CustomBuildOptions configOptions;
                    if (target.BuildConfiguration.Configurations.TryGetValue(config.Name, out configOptions))
                    {
                        configOptions = configOptions.Merge(target.BuildConfiguration.Shared);
                    }
                    else
                    {
                        configOptions = target.BuildConfiguration.Shared;
                    }

                    if (configOptions != null)
                    {
                        WriteCustomBuildOption(config, "Command", configOptions.Command);
                        WriteCustomBuildOption(config, "Outputs", configOptions.Outputs);
                        WriteCustomBuildOption(config, "Message", configOptions.Message);
                        WriteCustomBuildOption(config, "AdditionalInputs", configOptions.Inputs);
                        WriteCustomBuildOption(config, "LinkObjects", configOptions.Link);
                        WriteCustomBuildOption(config, "TreatOutputAsContent", configOptions.IsContent);
                    }
                    else
                    {
                        Utils.WriteLine("Warning, build target " + target.Name + " specifies no build options for configuration " + config.Name);
                    }
                }
            }

            // Match specific build rules:
            string solutionRelPath = Utils.RelativePath(source.Path, m_project.Solution.Path);

            ConfigurationHolder mergedFileConfig = new ConfigurationHolder();

            // Add empty configurations for all project configurations
            foreach (Configuration config in m_project.Configurations)
            {
                mergedFileConfig.AddConfiguration(new Configuration(config.Name));
            }

            // First, match from the project
            foreach (ConfigurationRule rule in m_project.ConfigurationRules)
            {
                if (rule.Pattern.IsMatch(solutionRelPath))
                {
                    mergedFileConfig.Merge(rule);
                }
            }

            // Then solution
            foreach (ConfigurationRule rule in m_project.Solution.ConfigurationRules)
            {
                if (rule.Pattern.IsMatch(solutionRelPath))
                {
                    mergedFileConfig.Merge(rule);
                }
            }

            foreach (Configuration config in mergedFileConfig.Configurations)
            {
                if (config.ExcludedFromBuild)
                {
                    m_writer.WriteStartElement("ExcludedFromBuild");
                    WriteConfigurationCondition(config);
                    m_writer.WriteValue(true);
                    m_writer.WriteEndElement();
                }
                foreach (KeyValuePair <ClCompileOption, object> val in config.ClCompileOptions)
                {
                    m_writer.WriteStartElement(val.Key.ToString());
                    WriteConfigurationCondition(config);
                    m_writer.WriteValue(config.ValueToString(val.Key, val.Value));
                    m_writer.WriteEndElement();
                }
            }

            m_writer.WriteEndElement();
            return(true);
        }