protected override ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter) { var SDKs = XmlTools.LoadObject <STM32SDKCollection>(Path.Combine(BSPDirectory, "SDKVersions.xml")); List <VendorSample> allSamples = new List <VendorSample>(); foreach (var sdk in SDKs.SDKs) { List <string> addInc = new List <string>(); string topLevelDir = Directory.GetDirectories(Path.Combine(SDKdir, sdk.FolderName), "STM32Cube_*")[0]; addInc.Add($@"{topLevelDir}\Drivers\CMSIS\Include"); int sampleCount = 0; Console.WriteLine($"Discovering samples for {sdk.Family}..."); foreach (var boardDir in Directory.GetDirectories(Path.Combine(topLevelDir, "Projects"))) { string boardName = Path.GetFileName(boardDir); int samplesForThisBoard = 0; foreach (var dir in Directory.GetDirectories(boardDir, "Mdk-arm", SearchOption.AllDirectories)) { string sampleName = Path.GetFileName(Path.GetDirectoryName(dir)); AppendSamplePrefixFromPath(ref sampleName, dir); if (!filter.ShouldParseSampleForAnyDevice(sampleName)) { continue; //We are only reparsing a subset of samples } var aSamples = GetInfoProjectFromMDK(dir, topLevelDir, boardName, addInc); if (aSamples.Count != 0) { Debug.Assert(aSamples[0].UserFriendlyName == sampleName); //Otherwise quick reparsing won't work. } var scriptDir = Path.Combine(dir, "..", "SW4STM32"); if (Directory.Exists(scriptDir)) { string[] linkerScripts = Directory.GetFiles(scriptDir, "*.ld", SearchOption.AllDirectories); if (linkerScripts.Length == 1) { foreach (var sample in aSamples) { sample.LinkerScript = Path.GetFullPath(linkerScripts[0]); } } else { //Some sample projects define multiple linker scripts (e.g. STM32F072RBTx_FLASH.ld vs. STM32F072VBTx_FLASH.ld). //In this case we don't pick the sample-specific linker script and instead go with the regular BSP script for the selected MCU.s } } sampleCount += aSamples.Count; samplesForThisBoard += aSamples.Count; allSamples.AddRange(aSamples); } if (samplesForThisBoard == 0) { foreach (var dir in Directory.GetDirectories(boardDir, "SW4STM32", SearchOption.AllDirectories)) { string sampleName = Path.GetFileName(Path.GetDirectoryName(dir)); AppendSamplePrefixFromPath(ref sampleName, dir); if (!filter.ShouldParseSampleForAnyDevice(sampleName)) { continue; //We are only reparsing a subset of samples } var aSamples = ProjectParsers.SW4STM32ProjectParser.ParseProjectFolder(dir, topLevelDir, boardName, addInc); if (aSamples.Count != 0) { Debug.Assert(aSamples[0].UserFriendlyName == sampleName); //Otherwise quick reparsing won't work. } sampleCount += aSamples.Count; samplesForThisBoard += aSamples.Count; allSamples.AddRange(aSamples); } } } Console.WriteLine($"Found {sampleCount} samples for {sdk.Family}."); } return(new ParsedVendorSamples { VendorSamples = allSamples.ToArray() }); }
protected abstract ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter);
protected override ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter) { _FrameworkLocator = new FrameworkLocator(SDKdir, Path.GetFullPath(BSPDirectory + @"\..\rules")); string makeExecutable = ToolchainDirectory + "/bin/make"; string baseExampleDir = Path.Combine(SDKdir, "examples"); string[] exampleDirs = Directory.GetFiles(baseExampleDir, "Makefile", SearchOption.AllDirectories). Where(s => (s.Contains("gcc") && !s.Contains("tirtos") && !File.ReadAllText(s).Contains("$(NODE_JS)") )).ToArray(); GCC_ARMCOMPILER = ((string)Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\GNUToolchains").GetValue("SysGCC-arm-eabi-7.2.0")).Replace("\\arm-eabi", ""); if (GCC_ARMCOMPILER == null) { throw new Exception("Cannot locate toolchain path from registry"); } BuildFreeRtosKernel(Path.Combine(SDKdir, @"kernel\freertos\builds\CC3220S_LAUNCHXL\release\gcc")); BuildFreeRtosKernel(Path.Combine(SDKdir, @"kernel\freertos\builds\CC3220SF_LAUNCHXL\release\gcc")); UpdateImportMakefile(SDKdir); List <VendorSample> allSamples = new List <VendorSample>(); int samplesDone = 0; string outputDir = Path.Combine(TestDirectory, "_MakeBuildLogs"); List <UnparseableVendorSample> failedSamples = new List <UnparseableVendorSample>(); foreach (var makefile in exampleDirs) { if (!makefile.Contains("gcc")) { continue; } string nameExampl = makefile.Substring(makefile.IndexOf("examples") + 9).Replace("gcc\\Makefile", ""); var nameLog = Path.Combine(Path.GetDirectoryName(makefile), "log.txt"); Console.WriteLine($"Compiling {nameExampl} ..."); string namefl = "noname"; if (File.ReadAllLines(makefile).Where(ln => ln.StartsWith("NAME")).Count() == 0) { Console.WriteLine("NO NAME IN " + makefile); } else { namefl = File.ReadAllLines(makefile).Single(ln => ln.StartsWith("NAME")).Split('=')[1].Trim(' ').ToUpper(); } var sampleID = new VendorSampleID { SampleName = namefl }; if (!filter.ShouldParseSampleForSpecificDevice(sampleID)) { continue; } var startInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/c {makeExecutable} clean", UseShellExecute = false, WorkingDirectory = Path.GetDirectoryName(makefile) }; var cleanAction = Process.Start(startInfo); cleanAction.WaitForExit(); if (cleanAction.ExitCode != 0) { throw new Exception("Failed to clean" + makefile); } startInfo.Arguments = $"/c {makeExecutable} -j{Environment.ProcessorCount} VERBOSE=1 > log.txt 2>&1"; var compiler = Process.Start(startInfo); samplesDone++; compiler.WaitForExit(); bool buildSucceeded = compiler.ExitCode == 0; Console.ForegroundColor = ConsoleColor.Green; if (Directory.GetFiles(Path.GetDirectoryName(makefile), "*.out").Count() == 0) { buildSucceeded = false; } if (!buildSucceeded) { failedSamples.Add(new UnparseableVendorSample { BuildLogFile = nameLog, ID = sampleID }); Console.ForegroundColor = ConsoleColor.Red; } LogLine($"{samplesDone}/{exampleDirs.Length}: {nameExampl.TrimEnd('\\')}: " + (buildSucceeded ? "Succeeded" : "Failed ")); Console.ForegroundColor = ConsoleColor.Gray; if (!File.Exists(nameLog)) { LogLine($"No Log file " + Path.GetDirectoryName(makefile)); Console.WriteLine($"No Log file {1}", Path.GetDirectoryName(makefile)); continue; } string relativePath = makefile.Substring(baseExampleDir.Length + 1); var vs = ParseMakFile(makefile, relativePath, SDKdir); vs.Path = Path.GetDirectoryName(makefile); while (Directory.GetFiles(vs.Path, "*.c").Length == 0) { vs.Path = Path.GetDirectoryName(vs.Path); } allSamples.Add(vs); //Clear // File.Delete(Path.Combine(compiler.StartInfo.WorkingDirectory, "log.txt")); // Directory.Delete(Path.Combine(compiler.StartInfo.WorkingDirectory, "_build"), true); } Console.ForegroundColor = ConsoleColor.Yellow; LogLine($"Total samples : {samplesDone}"); LogLine($"Failed samples : {failedSamples.Count}, {(failedSamples.Count / samplesDone) * 100} % from Total"); Console.ForegroundColor = ConsoleColor.Gray; _FrameworkLocator.ThrowIfUnresolvedLibrariesFound(); return(new ParsedVendorSamples { VendorSamples = allSamples.ToArray(), FailedSamples = failedSamples.ToArray() }); }
protected override ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter) { _FrameworkLocator = new FrameworkLocator(SDKdir, Path.GetFullPath(BSPDirectory + @"\..\rules")); string makeExecutable = ToolchainDirectory + "/bin/make"; string baseExampleDir = Path.Combine(SDKdir, "examples"); string[] exampleDirs = Directory.GetFiles(baseExampleDir, "Makefile", SearchOption.AllDirectories). Where(s => (s.Contains("gcc") && !s.Contains("tirtos") && !File.ReadAllText(s).Contains("$(NODE_JS)") )).ToArray(); GCC_ARMCOMPILER = ToolchainDirectory; if (GCC_ARMCOMPILER == null) { throw new Exception("Cannot locate toolchain path from registry"); } UpdateImportMakefile(SDKdir); foreach (var dir in Directory.GetDirectories(Path.Combine(SDKdir, @"kernel\freertos\builds"))) { BuildFreeRtosKernel(Path.Combine(dir, @"release\gcc")); } List <VendorSample> allSamples = new List <VendorSample>(); int samplesDone = 0; string outputDir = Path.Combine(TestDirectory, "_MakeBuildLogs"); List <UnparseableVendorSample> failedSamples = new List <UnparseableVendorSample>(); foreach (var makefile in exampleDirs) { if (!makefile.Contains("gcc")) { continue; } var sampleDir = Path.GetDirectoryName(makefile); string nameExampl = makefile.Substring(makefile.IndexOf("examples") + 9).Replace("gcc\\Makefile", ""); var nameLog = Path.Combine(sampleDir, "log.txt"); var markerFile = Path.Combine(sampleDir, "done.txt"); Console.WriteLine($"Compiling {nameExampl} ..."); var dir = Path.GetDirectoryName(sampleDir); var id = dir.Substring(baseExampleDir.Length + 1).Replace('\\', '-'); if (!filter.ShouldParseAnySamplesInsideDirectory(sampleDir)) { continue; } var startInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/c {makeExecutable} clean", UseShellExecute = false, WorkingDirectory = sampleDir }; bool buildSucceeded; if (!File.Exists(markerFile)) { var cleanAction = Process.Start(startInfo); cleanAction.WaitForExit(); if (cleanAction.ExitCode != 0) { throw new Exception("Failed to clean" + makefile); } startInfo.Arguments = $"/c {makeExecutable} -j{Environment.ProcessorCount} VERBOSE=1 > log.txt 2>&1"; var compiler = Process.Start(startInfo); compiler.WaitForExit(); buildSucceeded = compiler.ExitCode == 0; } else { buildSucceeded = true; } samplesDone++; CopyDriverFiles(SDKdir, sampleDir); Console.ForegroundColor = ConsoleColor.Green; if (Directory.GetFiles(sampleDir, "*.out").Count() == 0) { buildSucceeded = false; } if (buildSucceeded) { File.WriteAllText(markerFile, "build succeeded"); } if (!buildSucceeded) { failedSamples.Add(new UnparseableVendorSample { BuildLogFile = nameLog, UniqueID = id }); Console.ForegroundColor = ConsoleColor.Red; } LogLine($"{samplesDone}/{exampleDirs.Length}: {nameExampl.TrimEnd('\\')}: " + (buildSucceeded ? "Succeeded" : "Failed ")); Console.ForegroundColor = ConsoleColor.Gray; if (!File.Exists(nameLog)) { LogLine($"No Log file " + Path.GetDirectoryName(makefile)); Console.WriteLine($"No Log file {1}", Path.GetDirectoryName(makefile)); continue; } string relativePath = makefile.Substring(baseExampleDir.Length + 1); var vs = ParseMakFile(makefile, relativePath, SDKdir); vs.Path = Path.GetDirectoryName(makefile); while (Directory.GetFiles(vs.Path, "*.c").Length == 0) { vs.Path = Path.GetDirectoryName(vs.Path); } while (Path.GetFileName(vs.Path) == "gcc" || Path.GetFileName(vs.Path) == "freertos") { vs.Path = Path.GetDirectoryName(vs.Path); } vs.InternalUniqueID = id; allSamples.Add(vs); //Clear // File.Delete(Path.Combine(compiler.StartInfo.WorkingDirectory, "log.txt")); // Directory.Delete(Path.Combine(compiler.StartInfo.WorkingDirectory, "_build"), true); } Console.ForegroundColor = ConsoleColor.Yellow; LogLine($"Total samples : {samplesDone}"); LogLine($"Failed samples : {failedSamples.Count}, {(failedSamples.Count / samplesDone) * 100} % from Total"); Console.ForegroundColor = ConsoleColor.Gray; _FrameworkLocator.ThrowIfUnresolvedLibrariesFound(); return(new ParsedVendorSamples { VendorSamples = allSamples.ToArray(), FailedSamples = failedSamples.ToArray() }); }
protected override ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter) { ApplyKnownPatches(SDKdir); string makeExecutable = ToolchainDirectory + "/bin/make"; string[] ExampleDirs = Directory.GetFiles(Path.Combine(SDKdir, "examples"), "Makefile", SearchOption.AllDirectories).ToArray(); using (var sw = File.CreateText(Path.Combine(SDKdir, @"components\toolchain\gcc\Makefile.windows"))) { sw.WriteLine($"GNU_INSTALL_ROOT := {ToolchainDirectory.Replace('\\', '/')}/bin/"); sw.WriteLine($"GNU_VERSION := 7.2.0"); sw.WriteLine($"GNU_PREFIX := arm-eabi"); } List <VendorSample> allSamples = new List <VendorSample>(); int samplesDone = 0; string outputDir = Path.Combine(TestDirectory, "_MakeBuildLogs"); List <UnparseableVendorSample> failedSamples = new List <UnparseableVendorSample>(); foreach (var makefile in ExampleDirs) { string nameExampl = makefile.Substring(makefile.IndexOf("examples") + 9).Replace("armgcc\\Makefile", ""); if (makefile.Contains(@"\ant\")) { LogLine($"{samplesDone}/{ExampleDirs.Length}: {nameExampl.TrimEnd('\\')}: " + (" Skipped")); continue; } // if (!makefile.Contains(@"publisher")) // if(!makefile.Contains(@"keyboard")) // continue; // if (Directory.Exists(Path.Combine(Path.GetDirectoryName(makefile), "_build"))) // Directory.Delete(Path.Combine(Path.GetDirectoryName(makefile), "_build"), true); var nameLog = Path.Combine(Path.GetDirectoryName(makefile), "log.txt"); // if (File.Exists(nameLog)) // File.Delete(nameLog); Console.WriteLine($"Compiling {nameExampl} ..."); var sampleID = new VendorSampleID { SampleName = File.ReadAllLines(makefile).Single(ln => ln.StartsWith("PROJECT_NAME")).Split('=')[1].Trim(' ').ToUpper(), BoardNameOrDeviceID = File.ReadAllLines(makefile).Single(ln => ln.StartsWith("TARGETS")).Split('=')[1].Trim(' ').ToUpper() }; if (!filter.ShouldParseSampleForSpecificDevice(sampleID)) { continue; } var startInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/c {makeExecutable} -j{Environment.ProcessorCount} VERBOSE=1 > log.txt 2>&1", UseShellExecute = false, WorkingDirectory = Path.GetDirectoryName(makefile) }; var buildDir = Path.Combine(startInfo.WorkingDirectory, "_build"); if (Directory.Exists(buildDir)) { Directory.Delete(buildDir, true); } var compiler = Process.Start(startInfo); samplesDone++; compiler.WaitForExit(); bool buildSucceeded; buildSucceeded = compiler.ExitCode == 0; Console.ForegroundColor = ConsoleColor.Green; if (!buildSucceeded) { failedSamples.Add(new UnparseableVendorSample { BuildLogFile = nameLog, ID = sampleID }); Console.ForegroundColor = ConsoleColor.Red; } LogLine($"{samplesDone}/{ExampleDirs.Length}: {nameExampl.TrimEnd('\\')}: " + (buildSucceeded ? "Succeeded" : "Failed ")); Console.ForegroundColor = ConsoleColor.Gray; if (!File.Exists(nameLog)) { LogLine($"No Log file " + Path.GetDirectoryName(makefile)); Console.WriteLine($"No Log file {1}", Path.GetDirectoryName(makefile)); continue; } var vs = ParseNativeBuildLog(nameLog, SDKdir); vs.Path = Path.GetDirectoryName(makefile); while (Directory.GetFiles(vs.Path, "*.c").Length == 0) { vs.Path = Path.GetDirectoryName(vs.Path); } allSamples.Add(vs); //Clear // File.Delete(Path.Combine(compiler.StartInfo.WorkingDirectory, "log.txt")); // Directory.Delete(Path.Combine(compiler.StartInfo.WorkingDirectory, "_build"), true); } Console.ForegroundColor = ConsoleColor.Yellow; LogLine($"Total samples : {samplesDone}"); LogLine($"Failed samples : {failedSamples.Count}, {(failedSamples.Count / samplesDone) * 100} % from Total"); Console.ForegroundColor = ConsoleColor.Gray; return(new ParsedVendorSamples { VendorSamples = allSamples.ToArray(), FailedSamples = failedSamples.ToArray() }); }
protected override ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter) { var SDKs = XmlTools.LoadObject <STM32SDKCollection>(Path.Combine(BSPDirectory, "SDKVersions.xml")); using (var parser = new SW4STM32ProjectParser(CacheDirectory, BSP.BSP.SupportedMCUs)) { List <VendorSample> allSamples = new List <VendorSample>(); foreach (var sdk in SDKs.SDKs) { List <string> addInc = new List <string>(); string topLevelDir = Directory.GetDirectories(Path.Combine(SDKdir, sdk.FolderName), "STM32Cube_*")[0]; addInc.Add($@"{topLevelDir}\Drivers\CMSIS\Include"); if (!filter.ShouldParseAnySamplesInsideDirectory(topLevelDir)) { continue; } int sampleCount = 0; Console.WriteLine($"Discovering samples for {sdk.Family}..."); foreach (var boardDir in Directory.GetDirectories(Path.Combine(topLevelDir, "Projects"))) { string boardName = Path.GetFileName(boardDir); int samplesForThisBoard = 0; if (UseLegacySampleParser) { foreach (var dir in Directory.GetDirectories(boardDir, "Mdk-arm", SearchOption.AllDirectories)) { string sampleName = Path.GetFileName(Path.GetDirectoryName(dir)); if (!filter.ShouldParseAnySamplesInsideDirectory(dir)) { continue; //We are only reparsing a subset of samples } var aSamples = GetInfoProjectFromMDK(dir, topLevelDir, boardName, addInc); if (aSamples.Count != 0) { Debug.Assert(aSamples[0].UserFriendlyName == sampleName); //Otherwise quick reparsing won't work. } foreach (var sample in aSamples) { filter?.OnSampleParsed(sample); } var scriptDir = Path.Combine(dir, "..", "SW4STM32"); if (Directory.Exists(scriptDir)) { string[] linkerScripts = Directory.GetFiles(scriptDir, "*.ld", SearchOption.AllDirectories); if (linkerScripts.Length != 0) { var distinctLinkerScripts = linkerScripts.Select(s => File.ReadAllText(s)).Distinct().Count(); if (distinctLinkerScripts == 1) { foreach (var sample in aSamples) { sample.LinkerScript = Path.GetFullPath(linkerScripts[0]); } } else { //Some sample projects define multiple linker scripts (e.g. STM32F072RBTx_FLASH.ld vs. STM32F072VBTx_FLASH.ld). //In this case we don't pick the sample-specific linker script and instead go with the regular BSP script for the selected MCU. } } } sampleCount += aSamples.Count; samplesForThisBoard += aSamples.Count; allSamples.AddRange(aSamples); } } if (samplesForThisBoard == 0) { for (int pass = 0; pass < 2; pass++) { foreach (var dir in Directory.GetDirectories(boardDir, (pass == 0) ? "SW4STM32" : "STM32CubeIDE", SearchOption.AllDirectories)) { if (!filter.ShouldParseAnySamplesInsideDirectory(Path.GetDirectoryName(dir))) { continue; //We are only reparsing a subset of samples } SW4STM32ProjectParser.ProjectSubtype subtype; if (pass == 0) { subtype = SW4STM32ProjectParser.ProjectSubtype.SW4STM32; } else { subtype = SW4STM32ProjectParser.ProjectSubtype.STM32CubeIDE; } var aSamples = parser.ParseProjectFolder(dir, topLevelDir, boardName, addInc, subtype); foreach (var sample in aSamples) { filter?.OnSampleParsed(sample); } sampleCount += aSamples.Count; samplesForThisBoard += aSamples.Count; allSamples.AddRange(aSamples); } } } } Console.WriteLine($"Found {sampleCount} samples for {sdk.Family}."); } return(new ParsedVendorSamples { VendorSamples = allSamples.ToArray(), FailedSamples = parser.FailedSamples.ToArray() }); } }
protected override ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter) { /* * Since most of the original SDK samples only consist of a handful of files, we use a very simplified logic to enumerate them: * 1. Locate all "Makefile" and "readme.txt" files. * 2. Discard those that don't have .c files in the same directory, or have multiple directories with .c files. * 3. Depending on the config files stored in the same directory, we pick one of the 3 predefined profiles (wlan, bluetooth, periph). * The profiles come from manually created VisualGDB projects and specify a minimum viable configuration to build basic samples. * * Then, we try building all samples discovered via this simplified algorithm, and the successfully built ones into the BSP. */ var sampleBase = Path.Combine(SDKdir, "Examples"); var allFiles = Directory.GetFiles(sampleBase, "*.*", SearchOption.AllDirectories); List <VendorSample> vendorSamples = new List <VendorSample>(); var wlanConfig = XmlTools.LoadObject <EmbeddedProfile>(Path.Combine(RulesDirectory, "wlan.xml")); var bareConfig = XmlTools.LoadObject <EmbeddedProfile>(Path.Combine(RulesDirectory, "periph.xml")); var btConfig = XmlTools.LoadObject <EmbeddedProfile>(Path.Combine(RulesDirectory, "bluetooth.xml")); foreach (var dir in allFiles.Where(f => Path.GetFileName(f) == "Makefile" || Path.GetFileName(f).ToLower() == "readme.txt").Select(Path.GetDirectoryName).Distinct()) { var matchingSources = allFiles.Where(f => Path.GetExtension(f) == ".c" && f.StartsWith(dir + "\\")).ToArray(); var matchingDirs = matchingSources.Select(Path.GetDirectoryName).Distinct().ToArray(); if (matchingDirs.Length != 1) { continue; } string name = Path.GetFileName(dir); string macros = null; EmbeddedProfile matchingProfile; if (File.Exists(Path.Combine(dir, "rsi_ble_config.h"))) { matchingProfile = btConfig; macros = "BT_BDR_MODE=0"; } if (File.Exists(Path.Combine(dir, "rsi_wlan_config.h"))) { matchingProfile = wlanConfig; } else { matchingProfile = bareConfig; macros = "__SYSTICK"; } var sample = new VendorSample { DeviceID = "RS14100", SourceFiles = matchingSources, UserFriendlyName = name, InternalUniqueID = dir.Substring(SDKdir.Length).TrimStart('\\').Replace('\\', '_'), Path = dir, IncludeDirectories = new[] { dir }, VirtualPath = Path.GetDirectoryName(dir).Substring(SDKdir.Length).TrimStart('\\'), Configuration = matchingProfile.ToConfiguration(), }; if (File.Exists(Path.Combine(dir, "readme.txt"))) { sample.Description = File.ReadAllText(Path.Combine(dir, "readme.txt")); } if (macros != null) { sample.PreprocessorMacros = macros.Split(';'); } vendorSamples.Add(sample); } return(new ParsedVendorSamples { VendorSamples = vendorSamples.ToArray() }); }
protected override ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter) { ApplyKnownPatches(SDKdir); string makeExecutable = ToolchainDirectory + "/bin/make"; string[] allMakefiles = Directory.GetFiles(Path.Combine(SDKdir, "examples"), "Makefile", SearchOption.AllDirectories).ToArray(); using (var sw = File.CreateText(Path.Combine(SDKdir, @"components\toolchain\gcc\Makefile.windows"))) { sw.WriteLine($"GNU_INSTALL_ROOT := {ToolchainDirectory.Replace('\\', '/')}/bin/"); sw.WriteLine($"GNU_VERSION := 9.2.1"); sw.WriteLine($"GNU_PREFIX := arm-none-eabi"); } List <VendorSample> allSamples = new List <VendorSample>(); string outputDir = Path.Combine(TestDirectory, "_MakeBuildLogs"); List <UnparseableVendorSample> failedSamples = new List <UnparseableVendorSample>(); int samplesDone = 0, samplesWithoutBinaryFile = 0, samplesWithoutLogFile = 0; foreach (var makefile in allMakefiles) { string nameExampl = makefile.Substring(makefile.IndexOf("examples") + 9).Replace("armgcc\\Makefile", ""); if (makefile.Contains(@"\ant\")) { LogLine($"{samplesDone}/{allMakefiles.Length}: {nameExampl.TrimEnd('\\')}: " + (" Skipped")); continue; } var nameLog = Path.Combine(Path.GetDirectoryName(makefile), "log.txt"); Console.WriteLine($"Compiling {nameExampl} ..."); string sampleName = File.ReadAllLines(makefile).Single(ln => ln.StartsWith("PROJECT_NAME")).Split('=')[1].Trim(' ').ToUpper(); string boardNameOrDeviceID = File.ReadAllLines(makefile).Single(ln => ln.StartsWith("TARGETS")).Split('=')[1].Trim(' ').ToUpper(); string sampleID = $"{sampleName}-{boardNameOrDeviceID}"; string vendorSamplePath = Path.GetDirectoryName(makefile); while (Directory.GetFiles(vendorSamplePath, "*.c").Length == 0) { vendorSamplePath = Path.GetDirectoryName(vendorSamplePath); } if (!filter.ShouldParseAnySamplesInsideDirectory(vendorSamplePath)) { continue; } var startInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = $"/c {makeExecutable} -j{Environment.ProcessorCount} VERBOSE=1 > log.txt 2>&1", UseShellExecute = false, WorkingDirectory = Path.GetDirectoryName(makefile) }; samplesDone++; var buildDir = Path.Combine(startInfo.WorkingDirectory, "_build"); if (Directory.Exists(buildDir) && Directory.GetFiles(buildDir, "*.bin", SearchOption.AllDirectories).Count() > 0) { Console.ForegroundColor = ConsoleColor.Blue; LogLine($"{samplesDone}/{allMakefiles.Length}: {nameExampl.TrimEnd('\\')}: " + ("Built")); Console.ForegroundColor = ConsoleColor.Gray; } else { try { if (Directory.Exists(buildDir)) { Directory.Delete(buildDir, true); } } catch (Exception exc) { Console.WriteLine("Error delete: " + exc.Message); } var compiler = Process.Start(startInfo); compiler.WaitForExit(); bool buildSucceeded; buildSucceeded = compiler.ExitCode == 0; Console.ForegroundColor = ConsoleColor.Green; if (!buildSucceeded) { failedSamples.Add(new UnparseableVendorSample { BuildLogFile = nameLog, UniqueID = sampleID }); Console.ForegroundColor = ConsoleColor.Red; } LogLine($"{samplesDone}/{allMakefiles.Length}: {nameExampl.TrimEnd('\\')}: " + (buildSucceeded ? "Succeeded" : "Failed ")); Console.ForegroundColor = ConsoleColor.Gray; if (!buildSucceeded) { continue; } } if (!File.Exists(nameLog)) { LogLine($"No Log file " + Path.GetDirectoryName(makefile)); Console.WriteLine($"No Log file {1}", Path.GetDirectoryName(makefile)); samplesWithoutLogFile++; continue; } if (Directory.GetFiles(buildDir, "*.bin", SearchOption.AllDirectories).Count() == 0) { LogLine($"No bin file " + Path.GetDirectoryName(makefile)); Console.WriteLine($"No bin file {1}", Path.GetDirectoryName(makefile)); samplesWithoutBinaryFile++; continue; } var vs = ParseNativeBuildLog(nameLog, SDKdir, sampleID); vs.Path = vendorSamplePath; allSamples.Add(vs); } if (samplesDone > 0) { Console.ForegroundColor = ConsoleColor.Yellow; LogLine($"Total samples : {samplesDone}"); LogLine($"Samples without final binary file: {samplesWithoutBinaryFile} Samples producing no log: {samplesWithoutLogFile}"); LogLine($"Failed samples : {failedSamples.Count}, {(failedSamples.Count / samplesDone) * 100} % from Total"); Console.ForegroundColor = ConsoleColor.Gray; } return(new ParsedVendorSamples { VendorSamples = allSamples.ToArray(), FailedSamples = failedSamples.ToArray() }); }
protected override ParsedVendorSamples ParseVendorSamples(string SDKdir, IVendorSampleFilter filter) { string stm32RulesDir = @"..\..\..\..\generators\stm32\rules\families"; string[] familyDirs = Directory.GetFiles(stm32RulesDir, "stm32*.xml") .Select(f => ExtractFirstSubdir(XmlTools.LoadObject <FamilyDefinition>(f).PrimaryHeaderDir)) .ToArray(); List <VendorSample> allSamples = new List <VendorSample>(); foreach (var fam in familyDirs) { List <string> addInc = new List <string>(); addInc.Add($@"{SDKdir}\{fam}\Drivers\CMSIS\Include"); string topLevelDir = $@"{SDKdir}\{fam}"; int sampleCount = 0; Console.WriteLine($"Discovering samples for {fam}..."); foreach (var boardDir in Directory.GetDirectories(Path.Combine(SDKdir, fam, "Projects"))) { string boardName = Path.GetFileName(boardDir); foreach (var dir in Directory.GetDirectories(boardDir, "Mdk-arm", SearchOption.AllDirectories)) { string sampleName = Path.GetFileName(Path.GetDirectoryName(dir)); AppendSamplePrefixFromPath(ref sampleName, dir); if (!filter.ShouldParseSampleForAnyDevice(sampleName)) { continue; //We are only reparsing a subset of samples } var aSamples = GetInfoProjectFromMDK(dir, topLevelDir, boardName, addInc); if (aSamples.Count != 0) { Debug.Assert(aSamples[0].UserFriendlyName == sampleName); //Otherwise quick reparsing won't work. } var scriptDir = Path.Combine(dir, "..", "SW4STM32"); if (Directory.Exists(scriptDir)) { string[] linkerScripts = Directory.GetFiles(scriptDir, "*.ld", SearchOption.AllDirectories); if (linkerScripts.Length == 1) { foreach (var sample in aSamples) { sample.LinkerScript = Path.GetFullPath(linkerScripts[0]); } } else { //Some sample projects define multiple linker scripts (e.g. STM32F072RBTx_FLASH.ld vs. STM32F072VBTx_FLASH.ld). //In this case we don't pick the sample-specific linker script and instead go with the regular BSP script for the selected MCU.s } } sampleCount += aSamples.Count; allSamples.AddRange(aSamples); } } Console.WriteLine($"Found {sampleCount} samples for {fam}."); } return(new ParsedVendorSamples { VendorSamples = allSamples.ToArray() }); }