コード例 #1
0
ファイル: KSDKManifestParser.cs プロジェクト: whinis/BSPTools
            void AttachSVDFilesAndLinkerScriptsToDevices(ISDKImportHost host)
            {
                foreach (var sd in _SpecializedDevices)
                {
                    if (_Components.FirstOrDefault(c => c.Type == ComponentType.SVDFile && c.Filter.MatchesDevice(sd)) is ParsedComponent svdComponent)
                    {
                        var svdFiles = svdComponent.LocateAllFiles(sd, _Directory).ToArray();
                        Debug.Assert(svdFiles.Length <= 1); //If we get multiple matching SVD files, we might have skipped some conditions.

                        if (svdFiles.Length > 0)
                        {
                            try
                            {
                                var fullPath = svdFiles[0].GetLocalPath(_Directory);

                                var mcuDef        = host?.TryParseSVDFile(fullPath, sd.Device.DeviceName) ?? SVDParser.ParseSVDFile(fullPath, sd.Device.DeviceName);
                                var convertedFile = new FileReference(Path.ChangeExtension(svdFiles[0].RelativePath, ".vgdbdevice"), svdFiles[0].Type);

                                XmlSerializer ser = new XmlSerializer(typeof(MCUDefinition));
                                using (var fs = File.Create(Path.ChangeExtension(convertedFile.GetLocalPath(_Directory), ".vgdbdevice.gz")))
                                    using (var gs = new GZipStream(fs, CompressionMode.Compress, true))
                                        ser.Serialize(gs, new MCUDefinition(mcuDef));

                                sd.ConvertedSVDFile = convertedFile;
                            }
                            catch (Exception ex)
                            {
                                _Sink.LogWarning($"Failed to process {svdFiles[0]}: {ex.Message}");
                            }
                        }
                    }

                    sd.DiscoveredLinkerScripts = _Components.Where(c => c.Type == ComponentType.LinkerScript && c.Filter.MatchesDevice(sd))
                                                 .SelectMany(c => c.LocateAllFiles(sd, _Directory)).ToArray();
                }
            }