예제 #1
0
파일: Program.cs 프로젝트: kmnaxin/BSPTools
            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()
                });
            }
예제 #2
0
파일: Program.cs 프로젝트: kmnaxin/BSPTools
            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()
                });
            }