Пример #1
0
            Regex rgCPUOrFPU = new Regex("(-mcpu|-mfpu)=([0-9a-zA-Z-_+]+)");    //'+' is needed for -mcpu=cortex-m33+nodsp

            private string CollectCommonFlagsFromSample(ParsedExample example)
            {
                try
                {
                    Dictionary <string, string> flags = new Dictionary <string, string>();
                    string           dir        = Path.Combine(_Directory, example.RelativePath);
                    var              cmakeLists = Path.Combine(dir, "armgcc\\CMakeLists.txt");
                    HashSet <string> moreFlags  = new HashSet <string>();
                    if (File.Exists(cmakeLists))
                    {
                        foreach (var line in File.ReadAllLines(cmakeLists))
                        {
                            var match = rgCPUOrFPU.Match(line);
                            if (match.Success)
                            {
                                if (!flags.TryGetValue(match.Groups[1].Value, out var oldValue) || oldValue == match.Groups[2].Value)
                                {
                                    flags[match.Groups[1].Value] = match.Groups[2].Value;
                                }
                                else
                                {
                                    flags[match.Groups[1].Value] = null;
                                }
                            }
                            if (line.Contains("-mthumb"))
                            {
                                moreFlags.Add("-mthumb");
                            }
                        }
                    }

                    return(string.Join(" ", flags.Where(kv => kv.Value != null).Select(kv => $"{kv.Key}={kv.Value}").Concat(moreFlags).ToArray()));
                }
                catch (Exception ex)
                {
                    _Sink.LogWarning(ex.Message);
                }

                return("");
            }
Пример #2
0
            public List <VendorSample> TranslateSampleProjects()
            {
                if (_SpecializedDevices.Count == 0)
                {
                    throw new Exception("The selected KSDK contains no families");
                }

                Dictionary <string, Dictionary <string, SpecializedDevice> > specializedDevicesByPackage = new Dictionary <string, Dictionary <string, SpecializedDevice> >();

                foreach (var dev in _SpecializedDevices)
                {
                    foreach (var pkg in dev.Device.PackageNames)
                    {
                        if (!specializedDevicesByPackage.TryGetValue(pkg, out var l2))
                        {
                            specializedDevicesByPackage[pkg] = l2 = new Dictionary <string, SpecializedDevice>();
                        }

                        l2[dev.Core.ID] = dev;
                    }
                }

                List <VendorSample> samples = new List <VendorSample>();

                foreach (XmlElement boardNode in _Manifest.DocumentElement.SelectNodes("boards/board"))
                {
                    string boardName = boardNode.GetAttribute("name");
                    string package   = boardNode.GetAttribute("package");

                    if (!specializedDevicesByPackage.TryGetValue(package, out var specializedDevicesForThisPackage))
                    {
                        _Sink.LogWarning("Unknown device package: " + package);
                        continue;
                    }

                    foreach (XmlElement directExampleNode in boardNode.SelectNodes("examples/example"))
                    {
                        try
                        {
                            var example = new ParsedExample(_Directory, directExampleNode);
                            SpecializedDevice device;
                            if (specializedDevicesForThisPackage.Count == 1)
                            {
                                device = specializedDevicesForThisPackage.First().Value;
                            }
                            else if (!specializedDevicesForThisPackage.TryGetValue(example.CoreID, out device))
                            {
                                _Sink.LogWarning($"Invalid core ({example.CoreID}) referenced by {example.ID}");
                                continue;
                            }

                            if (device.FlagsDerivedFromSamples == null && !string.IsNullOrEmpty(example.RelativePath))
                            {
                                device.FlagsDerivedFromSamples = CollectCommonFlagsFromSample(example);
                            }

                            samples.Add(example.BuildVendorSample(_Directory, boardName, device, package, _AllComponentIDs, _ImplicitlyIncludedFrameworks));
                        }
                        catch (Exception ex)
                        {
                            _Sink.LogWarning(ex.Message);
                        }
                    }
                }

                return(samples);
            }