Exemple #1
0
            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()
                });
            }
Exemple #2
0
            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()
                });
            }