protected override void OnMissingSampleFile(MissingSampleFileArgs args) { string path = args.ExpandedPath; if (path.Contains("pca10040e/s112")) { string originalFn = path.Replace("pca10040e/s112", "pca10040/s132"); if (ReplaceFile(originalFn, path)) { return; } } base.OnMissingSampleFile(args); }
public IEnumerable <CopiedSample> CopySamples(IEnumerable <EmbeddedFramework> allFrameworks = null, IEnumerable <SysVarEntry> extraVariablesToValidateSamples = null) { if (Definition.SmartSamples != null) { foreach (var sample in Definition.SmartSamples) { string destFolder = Path.Combine(BSP.BSPRoot, sample.DestinationFolder); string sourceDir = sample.SourceFolder; BSP.ExpandVariables(ref sourceDir); if (sample.CopyFilters == null) { PathTools.CopyDirectoryRecursive(sourceDir, destFolder); } else { var filters = new CopyFilters(sample.CopyFilters); foreach (var fn in Directory.GetFiles(sourceDir, "*.*", SearchOption.AllDirectories)) { string relPath = fn.Substring(sourceDir.Length).TrimStart('\\'); if (filters.IsMatch(relPath)) { string targetPath = Path.Combine(destFolder, relPath); Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); File.Copy(fn, targetPath); } } } if (sample.AdditionalBuildTimeSources != null) { foreach (var src in sample.AdditionalBuildTimeSources) { string source = src; BSP.ExpandVariables(ref source); string targetPath = Path.Combine(destFolder, Path.GetFileName(source)); File.Copy(source, targetPath); } } if (sample.Patches != null) { foreach (var p in sample.Patches) { foreach (var fn in p.FilePath.Split(';')) { List <string> allLines = File.ReadAllLines(Path.Combine(destFolder, fn)).ToList(); p.Apply(allLines); File.WriteAllLines(Path.Combine(destFolder, fn), allLines); } } } var sampleObj = sample.EmbeddedSample ?? XmlTools.LoadObject <EmbeddedProjectSample>(Path.Combine(destFolder, "sample.xml")); if (sampleObj.RequiredFrameworks == null && allFrameworks != null) { sampleObj.RequiredFrameworks = allFrameworks.Where(fw => fw.DefaultEnabled).Select(fw => fw.ClassID ?? fw.ID)?.ToArray(); } if (sample.AdditionalSources != null) { sampleObj.AdditionalSourcesToCopy = sample.AdditionalSources.Select(f => { int idx = f.IndexOf("=>"); if (idx == -1) { return new AdditionalSourceFile { SourcePath = f } } ; else { return new AdditionalSourceFile { SourcePath = f.Substring(0, idx).Trim(), TargetFileName = f.Substring(idx + 2).Trim() } }; }).ToArray(); for (int i = 0; i < sampleObj.AdditionalSourcesToCopy.Length; i++) { string path = sampleObj.AdditionalSourcesToCopy[i].SourcePath.Replace("$$SYS:BSP_ROOT$$", BSP.Directories.OutputDir); if (!File.Exists(path)) { if (extraVariablesToValidateSamples != null) { foreach (var v in extraVariablesToValidateSamples) { path = path.Replace("$$" + v.Key + "$$", v.Value); } } if (!File.Exists(path)) { var args = new MissingSampleFileArgs { UnexpandedPath = sampleObj.AdditionalSourcesToCopy[i].SourcePath, ExpandedPath = path }; OnMissingSampleFile(args); if (args.SubstitutePath != null) { if (args.SubstitutePath.StartsWith(BSP.BSPRoot)) { args.SubstitutePath = "$$SYS:BSP_ROOT$$" + args.SubstitutePath.Substring(BSP.BSPRoot.Length).Replace('\\', '/'); } else if (args.SubstitutePath.StartsWith("$$")) { //Already encoded } else { throw new Exception("Invalid substitute path: " + args.SubstitutePath); } sampleObj.AdditionalSourcesToCopy[i].SourcePath = args.SubstitutePath; } } } } } if (sampleObj.MCUFilterRegex == null & allFrameworks != null && sampleObj.RequiredFrameworks != null) { string[] devices = null; foreach (var fw in allFrameworks) { if (fw.MCUFilterRegex == null) { continue; } if (sampleObj.RequiredFrameworks.Contains(fw.ID) || sampleObj.RequiredFrameworks.Contains(fw.ClassID)) { if (devices == null) { devices = fw.MCUFilterRegex.Split('|'); } else { devices = devices.Intersect(fw.MCUFilterRegex.Split('|')).ToArray(); } } } if (devices != null) { sampleObj.MCUFilterRegex = string.Join("|", devices); } } if (sampleObj.MCUFilterRegex == null && sample.MCUFilterRegex != null) { sampleObj.MCUFilterRegex = sample.MCUFilterRegex; } XmlTools.SaveObject(sampleObj, Path.Combine(destFolder, "sample.xml")); yield return(new CopiedSample { RelativePath = sample.DestinationFolder, IsTestProjectSample = sample.IsTestProjectSample }); } } }
protected virtual void OnMissingSampleFile(MissingSampleFileArgs args) { //DO NOT REPLACE THIS WITH A WARNING! If needed, override this method in specific generators. throw new Exception($"Missing sample file: {args.ExpandedPath}. Please setup fallback lookup rules."); }
protected override void OnMissingSampleFile(MissingSampleFileArgs args) { return; base.OnMissingSampleFile(args); }