Ejemplo n.º 1
0
        void GenerateBoardProperty(List <EmbeddedFramework> frameworks)
        {
            List <PropertyEntry.Enumerated.Suggestion> lstProp = new List <PropertyEntry.Enumerated.Suggestion>();
            var framework     = frameworks.SingleOrDefault(fr => fr.ID.Equals("com.sysprogs.arm.nordic.nrf5x.boards"));
            var propertyGroup = framework.ConfigurableProperties.PropertyGroups.
                                SingleOrDefault(pg => pg.UniqueID.Equals("com.sysprogs.bspoptions.nrf5x.board."));

            var rgBoardIfdef = new Regex("#(if|elif) defined\\(BOARD_([A-Z0-9a-z_]+)\\)");
            var rgInclude    = new Regex("#include \"([^\"]+)\"");

            var lines = File.ReadAllLines(Path.Combine(Directories.OutputDir, @"nRF5x\components\boards\boards.h"));

            lstProp.Add(new PropertyEntry.Enumerated.Suggestion()
            {
                InternalValue = "", UserFriendlyName = "None"
            });

            var reverseConditions = _Builder.ReverseFileConditions?.GetHandleForFramework(framework);

            const string BoardTypeParameter = "com.sysprogs.bspoptions.nrf5x.board.type";

            for (int i = 0; i < lines.Length; i++)
            {
                var m = rgBoardIfdef.Match(lines[i]);
                if (!m.Success)
                {
                    continue;
                }

                string boardID = m.Groups[2].Value;
                string file    = rgInclude.Match(lines[i + 1]).Groups[1].Value;

                _Builder.AddFileCondition(new FileCondition()
                {
                    ConditionToInclude = new Condition.Equals()
                    {
                        Expression    = $"$${BoardTypeParameter}$$",
                        ExpectedValue = boardID,
                        IgnoreCase    = false
                    },
                    FilePath = "nRF5x/components/boards/" + file
                });
                lstProp.Add(new PropertyEntry.Enumerated.Suggestion {
                    InternalValue = boardID
                });

                reverseConditions?.AttachPreprocessorMacro("BOARD_" + boardID, reverseConditions?.CreateSimpleCondition(BoardTypeParameter, boardID));
            }
            //--ConfigurableProperties--

            propertyGroup.Properties.Add(new PropertyEntry.Enumerated
            {
                UniqueID          = "type",
                Name              = "Board Type",
                DefaultEntryIndex = Enumerable.Range(0, lstProp.Count).First(i => lstProp[i].InternalValue == "PCA10040"),
                DefaultEntryValue = "$$com.sysprogs.bspoptions.nrf5x.mcu.default_board$$",
                SuggestionList    = lstProp.ToArray()
            });
        }