示例#1
0
            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()
                });
            }
示例#2
0
            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()
                });
            }
示例#3
0
            VendorSample ParseNativeBuildLog(string namelog, string SDKdir)
            {
                VendorSample  vs         = new VendorSample();
                List <string> lstFileC   = new List <string>();
                List <string> lstFileInc = new List <string>();
                List <string> splitArgs  = new List <string>();
                List <string> lstDef     = new List <string>();
                string        aCurDir    = Path.GetDirectoryName(namelog);

                foreach (var ln in File.ReadAllLines(namelog))
                {
                    if (ln.Replace('\\', '/').IndexOf(ToolchainDirectory.Replace('\\', '/'), StringComparison.InvariantCultureIgnoreCase) == -1)
                    {
                        continue;
                    }
                    // Get Arguments
                    int    munArg;
                    IntPtr ptrToSplitArgs = CommandLineToArgvW(ln, out munArg);
                    if (ptrToSplitArgs == IntPtr.Zero)
                    {
                        throw new Exception("no arg");
                    }

                    for (int i = 0; i < munArg; i++)
                    {
                        string arg = Marshal.PtrToStringUni(
                            Marshal.ReadIntPtr(ptrToSplitArgs, i * IntPtr.Size));
                        if (!splitArgs.Contains(arg))
                        {
                            splitArgs.Add(arg);
                        }
                    }
                }

                // Processing arguments
                lstFileInc.AddRange(splitArgs.Where(ar => ar.StartsWith("-I")).Select(a => a.Substring(2).Trim()));
                lstDef.AddRange(splitArgs.Where(ar => ar.StartsWith("-D")).Select(a => a.Substring(2).Trim()));

                lstFileC.AddRange(splitArgs.Where(ar => (ar.EndsWith(".c") || ar.EndsWith(".s", StringComparison.InvariantCultureIgnoreCase)) && !ar.Contains(@"components/toolchain/") &&
                                                  !ar.Contains(@"gcc_startup")));


                //arguments from file
                var fileArg = splitArgs.SingleOrDefault(ar => ar.StartsWith("@"));

                if (fileArg != null)
                {
                    var Libs = from t in File.ReadAllText(Path.Combine(aCurDir, fileArg.Substring(1))).Split(' ') where t.EndsWith(".a") orderby t select t;
                    lstFileC.AddRange(Libs);
                }

                BuildAbsolutePath(aCurDir, ref lstFileInc);
                BuildAbsolutePath(aCurDir, ref lstFileC);

                var aProjectName = File.ReadAllLines(Path.Combine(aCurDir, "Makefile")).Single(ln => ln.StartsWith("PROJECT_NAME")).Split('=')[1].Trim(' ').ToUpper();

                var fl = File.ReadAllText(Path.Combine(aCurDir, "Makefile"));

                if (!fl.Contains("SOFTDEVICE_PRESENT"))
                {
                    vs.Configuration.MCUConfiguration = new PropertyDictionary2
                    {
                        Entries = new PropertyDictionary2.KeyValue[] {
                            new PropertyDictionary2.KeyValue {
                                Key = "com.sysprogs.bspoptions.nrf5x.softdevice", Value = "nosoftdev"
                            }
                        }.ToArray()
                    };
                }
                else
                {
                    var n = lstFileC.FindIndex(fi => fi.Contains("/softdevice_handler.c"));
                    if (n >= 0)
                    {
                        lstFileC.RemoveAt(n);
                    }
                }

                if (Directory.GetFiles(aCurDir, "*.ld").Count() > 0)
                {
                    vs.LinkerScript = Directory.GetFiles(aCurDir, "*.ld")[0].Replace(SDKdir, "$$SYS:BSP_ROOT$$/nRF5x");
                }

                vs.IncludeDirectories = lstFileInc.ToArray();
                vs.PreprocessorMacros = lstDef.ToArray();
                vs.SourceFiles        = lstFileC.ToArray();
                vs.DeviceID           = File.ReadAllLines(Path.Combine(aCurDir, "Makefile")).Single(ln => ln.StartsWith("TARGETS")).Split('=')[1].Trim(' ').ToUpper();
                vs.UserFriendlyName   = aProjectName;
                return(vs);
            }
示例#4
0
            VendorSample ParseNativeBuildLog(string namelog, string SDKdir, string sampleID)
            {
                VendorSample vs = new VendorSample {
                    InternalUniqueID = sampleID
                };
                List <string> lstFileC           = new List <string>();
                List <string> lstFileInc         = new List <string>();
                List <string> splitArgs          = new List <string>();
                List <string> preprocessorMacros = new List <string>();
                string        aCurDir            = Path.GetDirectoryName(namelog);

                foreach (var ln in File.ReadAllLines(namelog))
                {
                    if (ln.Replace('\\', '/').IndexOf(ToolchainDirectory.Replace('\\', '/'), StringComparison.InvariantCultureIgnoreCase) == -1)
                    {
                        continue;
                    }
                    // Get Arguments
                    int    munArg;
                    IntPtr ptrToSplitArgs = CommandLineToArgvW(ln, out munArg);
                    if (ptrToSplitArgs == IntPtr.Zero)
                    {
                        throw new Exception("no arg");
                    }

                    for (int i = 0; i < munArg; i++)
                    {
                        string arg = Marshal.PtrToStringUni(
                            Marshal.ReadIntPtr(ptrToSplitArgs, i * IntPtr.Size));
                        if (!splitArgs.Contains(arg))
                        {
                            splitArgs.Add(arg);
                        }
                    }
                }

                // Processing arguments
                lstFileInc.AddRange(splitArgs.Where(ar => ar.StartsWith("-I")).Select(a => a.Substring(2).Trim()));
                preprocessorMacros.AddRange(splitArgs.Where(ar => ar.StartsWith("-D")).Select(a => a.Substring(2).Trim()));

                lstFileC.AddRange(splitArgs.Where(ar => (ar.EndsWith(".c") || ar.EndsWith(".s", StringComparison.InvariantCultureIgnoreCase)) && !ar.Contains(@"components/toolchain/") &&
                                                  !ar.Contains(@"gcc_startup")));
                vs.CLanguageStandard = "c99";

                //arguments from file
                var fileArg = splitArgs.SingleOrDefault(ar => ar.StartsWith("@"));

                if (fileArg != null)
                {
                    var Libs = from t in File.ReadAllText(Path.Combine(aCurDir, fileArg.Substring(1))).Split(' ') where t.EndsWith(".a") orderby t select t;
                    lstFileC.AddRange(Libs);
                }

                BuildAbsolutePath(aCurDir, ref lstFileInc);
                BuildAbsolutePath(aCurDir, ref lstFileC);

                var aProjectName = File.ReadAllLines(Path.Combine(aCurDir, "Makefile")).Single(ln => ln.StartsWith("PROJECT_NAME")).Split('=')[1].Trim(' ').ToUpper();

                vs.DeviceID = File.ReadAllLines(Path.Combine(aCurDir, "Makefile")).Single(ln => ln.StartsWith("TARGETS")).Split('=')[1].Trim(' ').ToUpper();

                var softdeviceProperty = BSP.BSP.SupportedMCUs.First(m => vs.DeviceID.StartsWith(m.ID, StringComparison.InvariantCultureIgnoreCase)).ConfigurableProperties.PropertyGroups.SelectMany(g => g.Properties).FirstOrDefault(p => p.UniqueID == "com.sysprogs.bspoptions.nrf5x.softdevice") as PropertyEntry.Enumerated;

                if (softdeviceProperty == null)
                {
                    throw new Exception("Failed to locate softdevice for property" + vs.DeviceID);
                }

                string softdevice = softdeviceProperty.SuggestionList.FirstOrDefault(e => preprocessorMacros.Contains(e.InternalValue))?.InternalValue;

                if (!preprocessorMacros.Contains("SOFTDEVICE_PRESENT"))
                {
                    //This is a special 'serialization mode' sample that defines -DSxxx, but not -DSOFTDEVICE_PRESENT, that is not supported by our BSP yet.
                    softdevice = null;
                }

                vs.Configuration.MCUConfiguration = new PropertyDictionary2
                {
                    Entries = new PropertyDictionary2.KeyValue[]
                    {
                        new PropertyDictionary2.KeyValue {
                            Key   = "com.sysprogs.bspoptions.nrf5x.softdevice",
                            Value = softdevice ?? "nosoftdev"
                        }
                    }.ToArray()
                };

                if (softdevice != null)
                {
                    var n = lstFileC.FindIndex(fi => fi.Contains("/softdevice_handler.c"));
                    if (n >= 0)
                    {
                        lstFileC.RemoveAt(n);
                    }
                }

                if (Directory.GetFiles(aCurDir, "*.ld").Count() > 0)
                {
                    vs.LinkerScript = Directory.GetFiles(aCurDir, "*.ld")[0];
                }

                vs.IncludeDirectories = lstFileInc.ToArray();
                vs.PreprocessorMacros = preprocessorMacros.ToArray();
                vs.SourceFiles        = lstFileC.ToArray();
                vs.UserFriendlyName   = aProjectName;
                vs.NoImplicitCopy     = true;
                return(vs);
            }