private static DependenciesInfo ParseBundleDependenciesFromRules(BundlerBuildRule buildRule, ref ReservedSharedBundleInfo reserved, ref DependencyCache cache) { buildRule.rules.Sort((a, b) => - a.shared.CompareTo(b.shared)); var depsInfo = new DependenciesInfo(); foreach (var rule in buildRule.rules) { var packType = (PackType)Enum.Parse(typeof(PackType), rule.packType); switch (packType) { case PackType.PackByFile: ParseBundleDependenciesByRuleOfPackByFile(rule, ref depsInfo, ref reserved, ref cache); break; case PackType.PackByDirectory: ParseBundleDependenciesByRuleOfPackByDirectory(rule, ref depsInfo, ref reserved, ref cache); break; case PackType.PackBySubDirectory: ParseBundleDependenciesByRuleOfPackBySubDirectory(rule, ref depsInfo, ref reserved, ref cache); break; default: throw new ArgumentOutOfRangeException(rule.packType); } } return(depsInfo); }
public void NonCachedResults() { // Just check if expression is analyzed completely. // Non cached results allow rescan with same objects DependenciesSection section = TestHelper.GetDependenciesSection(); MockDependenciesInfoBuilder builder = new MockDependenciesInfoBuilder(); builder.MockEvaluator.ReturnValues.Add("Reg1", true); builder.MockEvaluator.ReturnValues.Add("Reg2", true); builder.MockEvaluator.ReturnValues.Add("Soft1", true); builder.MockEvaluator.ResetHitsPerCheck(); DependenciesInfo info = builder.BuildDependenciesInfo(section, 200); bool checkValue1 = info.EvaluationContext.Evaluate(info.Dependencies[0].Check); bool checkValue2 = info.EvaluationContext.Evaluate(info.Dependencies[1].Check); Assert.IsTrue(checkValue1); Assert.IsTrue(checkValue2); Assert.AreEqual(2, builder.MockEvaluator.HitsPerCheck["Reg1"]); Assert.AreEqual(2, builder.MockEvaluator.HitsPerCheck["Reg2"]); Assert.AreEqual(0, builder.MockEvaluator.HitsPerCheck["Soft1"]); checkValue1 = info.EvaluationContext.Evaluate(info.Dependencies[0].Check); checkValue2 = info.EvaluationContext.Evaluate(info.Dependencies[1].Check); Assert.IsTrue(checkValue1); Assert.IsTrue(checkValue2); Assert.AreEqual(4, builder.MockEvaluator.HitsPerCheck["Reg1"]); Assert.AreEqual(4, builder.MockEvaluator.HitsPerCheck["Reg2"]); Assert.AreEqual(0, builder.MockEvaluator.HitsPerCheck["Soft1"]); }
private void InitializeConfigurationSection() { const string configurationFileName = "App.config"; string configFilePath = Path.Combine(Path.GetTempPath(), configurationFileName); TextReader configReader = new StreamReader(this.GetType().Assembly.GetManifestResourceStream(this.GetType().Namespace + "." + configurationFileName)); File.WriteAllText(configFilePath, configReader.ReadToEnd()); var map = new ExeConfigurationFileMap { ExeConfigFilename = configFilePath }; this.fileConfig = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); this.configSection = (DependenciesSection)this.fileConfig.GetSection(DependenciesSection.SectionName); try { this.dependenciesInfo = this.GetDependenciesInfoBuilder().BuildDependenciesInfo(this.configSection); } catch (NotSupportedException e) { MessageBox.Show(e.Message, @"OS Not Supported", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(-1); } }
public void LoadsDependeciesList() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); DependenciesInfo info = builder.BuildDependenciesInfo(section, 200); Assert.AreEqual(2, info.Dependencies.Count); Assert.AreEqual("MinimumRequirement", info.Dependencies[0].Title); Assert.AreEqual(true, info.Dependencies[0].Enabled); Assert.AreEqual("This might be handy in all cases", info.Dependencies[0].Explanation); Assert.AreEqual("http://www.microsoft.com", info.Dependencies[0].DownloadUrl); Assert.IsTrue(string.IsNullOrEmpty(info.Dependencies[0].InfoUrl)); Assert.IsTrue(string.IsNullOrEmpty(info.Dependencies[0].ScriptName)); Assert.AreEqual("Optional", info.Dependencies[0].Category); Assert.AreEqual("Reg2", info.Dependencies[0].Check); Assert.AreEqual("Microsoft Visual Studio 2005", info.Dependencies[1].Title); Assert.AreEqual(true, info.Dependencies[1].Enabled); Assert.AreEqual("In order to use the Guidance Package, you will need to install Visual Studio 2005", info.Dependencies[1].Explanation); Assert.AreEqual("http://www.microsoft.com/VisualStudio", info.Dependencies[1].DownloadUrl); Assert.IsTrue(string.IsNullOrEmpty(info.Dependencies[1].InfoUrl)); Assert.IsTrue(string.IsNullOrEmpty(info.Dependencies[1].ScriptName)); Assert.AreEqual("MyCategory", info.Dependencies[1].Category); Assert.AreEqual("(Reg1 || Soft1) && Exp12", info.Dependencies[1].Check); }
public void CustomOSChecksOverrideCommonChecks() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); DependenciesInfo info = builder.BuildDependenciesInfo(section, 100); Assert.AreEqual(7, TestHelper.Count(info.EvaluationContext.GetCheckNames())); }
public void CommonChecksAreIncluded() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); DependenciesInfo info = builder.BuildDependenciesInfo(section, 300); Assert.AreEqual(6, TestHelper.Count(info.EvaluationContext.GetCheckNames())); }
public void FindsExactMatch() { DependenciesSection section = TestHelper.GetDependenciesSection(); var builder = new DependenciesInfoBuilder(null); DependenciesInfo info = builder.BuildDependenciesInfo(section, 100); Assert.IsNotNull(info); Assert.AreEqual(100, info.CompatibleOsBuild); }
private static BundlesInfo GenerateBundlesInfo(ref DependenciesInfo depsInfo, ref ReservedSharedBundleInfo reserved, ref DependencyCache cache) { var sharedBundles = ParseSharedBundleInfo(ref depsInfo, ref reserved, ref cache); var noneSharedBundles = ParseNoneSharedBundleInfo(ref depsInfo, ref sharedBundles); var bundles = new BundlesInfo(); sharedBundles.Concat(noneSharedBundles).ToList().ForEach(kv => { if (kv.Value.assets.Count > 0) { bundles.Add(kv.Key, kv.Value); } }); return(bundles); }
public void CheckAnalysisIsPropagated2() { DependenciesSection section = TestHelper.GetDependenciesSection(); MockDependenciesInfoBuilder builder = new MockDependenciesInfoBuilder(); builder.MockEvaluator.ReturnValues.Add("Reg1", false); builder.MockEvaluator.ReturnValues.Add("Reg2", false); builder.MockEvaluator.ResetHitsPerCheck(); DependenciesInfo info = builder.BuildDependenciesInfo(section, 400); bool checkValue1 = info.EvaluationContext.Evaluate(info.Dependencies[0].Check); bool checkValue2 = info.EvaluationContext.Evaluate(info.Dependencies[1].Check); Assert.IsFalse(checkValue1); Assert.IsFalse(checkValue2); Assert.AreEqual(1, builder.MockEvaluator.HitsPerCheck["Reg1"]); Assert.AreEqual(1, builder.MockEvaluator.HitsPerCheck["Reg2"]); }
private static BundlesInfo ParseNoneSharedBundleInfo(ref DependenciesInfo depsInfo, ref BundlesInfo sharedBundles) { // Parse none shared bundle info var noneSharedBundles = new BundlesInfo(); foreach (var kv in depsInfo) { var assetName = kv.Key; var bundles = kv.Value.referenceInBundles; var sharedBundle = sharedBundles.FirstOrDefault(skv => skv.Value.assets.Contains(assetName)).Key ?? ""; foreach (var bundle in bundles) { if (!string.IsNullOrEmpty(sharedBundles.FirstOrDefault(skv => skv.Key == bundle).Key)) { continue; // Equals to shared bundle, pass. } if (!noneSharedBundles.ContainsKey(bundle)) { noneSharedBundles.Add(bundle, new BundleInfo()); } if (string.IsNullOrEmpty(sharedBundle)) { noneSharedBundles[bundle].assets.Add(assetName); } } } // Move *.unity files to independent bundles, because 'Cannot mark assets and scenes in one AssetBundle' var sceneBundles = new BundlesInfo(); foreach (var kv in noneSharedBundles) { var noneSharedAssets = kv.Value.assets; var removed = new List <string>(); foreach (var asset in noneSharedAssets) { if (!asset.EndsWith(".unity")) { continue; } var sceneBundleName = string.Format(BundlerBuildSettings.kSceneBundleFormatter, PathUtility.RelativeProjectPathToAbsolutePath(asset)); sceneBundleName = PathUtility.NormalizeAssetBundlePath(sceneBundleName); if (sceneBundles.ContainsKey(sceneBundleName)) { throw new BundleException("Scene asset bundle duplicated: " + sceneBundleName); } var bundle = new BundleInfo(); bundle.assets.Add(asset); sceneBundles.Add(sceneBundleName, bundle); removed.Add(asset); } removed.ForEach(v => noneSharedAssets.Remove(v)); } // Merge to none shared bundles foreach (var kv in sceneBundles) { noneSharedBundles.Add(kv.Key, kv.Value); } return(noneSharedBundles); }
private static BundlesInfo ParseSharedBundleInfo(ref DependenciesInfo depsInfo, ref ReservedSharedBundleInfo reserved, ref DependencyCache cache) { var sharedDict = new Dictionary <string, string>(); var index = 0; // Determine shared bundles foreach (var kv in depsInfo) { var asset = kv.Key; // Ignore this asset when forced build in shared bundle. if (reserved.ContainsKey(asset)) { continue; } var depSet = kv.Value; // The count of dependencies no greater than 1 means that there are no other bundles // sharing this asset if (depSet.referenceInBundles.Count <= 1) { continue; } // Otherwise, assets which depended by the same bundles will be separated to shared bundle. if (!sharedDict.ContainsKey(asset)) { sharedDict[asset] = string.Format(BundlerBuildSettings.kSharedBundleFormatter, (++index).ToString()); // Sub-assets dependencies. var deps = CollectDependencies(asset, ref cache); foreach (var dep in deps) { if (reserved.ContainsKey(dep)) { continue; } sharedDict[dep] = string.Format(BundlerBuildSettings.kSharedBundleFormatter, (++index).ToString()); } } } // Collect shared bundles info var bundlesInfo = new BundlesInfo(); foreach (var kv in sharedDict) { var name = sharedDict[kv.Key]; if (bundlesInfo.ContainsKey(name)) { throw new BundleException("Shared bundle duplicated: " + name); } bundlesInfo[name] = new BundleInfo(); bundlesInfo[name].assets.Add(kv.Key); } // Generate unique bundle name according to assets list. var sharedBundle = new BundlesInfo(); foreach (var kv in bundlesInfo) { var assets = kv.Value.assets.ToList(); assets.Sort((a, b) => string.Compare(a, b, StringComparison.Ordinal)); var bundleName = string.Join("-", assets.ToArray()); if (BundlerBuildSettings.kHashSharedBundle) { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(bundleName))) { var nameHash = CalculateMd5(stream); bundleName = string.Format(BundlerBuildSettings.kSharedBundleFormatter, nameHash); } } else { bundleName = string.Format(BundlerBuildSettings.kSharedBundleFormatter, bundleName.ToLower()); } var bundleInfo = new BundleInfo(); foreach (var asset in kv.Value.assets) { bundleInfo.assets.Add(asset); } sharedBundle.Add(bundleName, bundleInfo); } // Add reserved shared bundles info foreach (var kv in reserved) { var assetName = kv.Key; var bundle = kv.Value; if (!sharedBundle.ContainsKey(bundle)) { sharedBundle.Add(bundle, new BundleInfo()); } sharedBundle[bundle].assets.Add(assetName); } return(sharedBundle); }
private static void AddDependenciesInfo(string bundleName, string relativePath, ref DependenciesInfo info, ref ReservedSharedBundleInfo reserved, ref DependencyCache cache) { var dependencies = CollectDependencies(relativePath, ref cache); var deps = dependencies.ToList(); deps.Add(relativePath); foreach (var dependency in deps) { if (!info.ContainsKey(dependency)) { info[dependency] = new DependencyInfo(); } if (IsShader(dependency)) { if (BundlerBuildSettings.kSeparateShaderBundle) { info[dependency].referenceInBundles.Add(BundlerBuildSettings.kSeparatedShaderBundleName); reserved[dependency] = BundlerBuildSettings.kSeparatedShaderBundleName; } } info[dependency].referenceInBundles.Add(bundleName); } }
private static void ParseBundleDependenciesByRuleOfPackBySubDirectory(BundleRule rule, ref DependenciesInfo depsInfo, ref ReservedSharedBundleInfo reserved, ref DependencyCache cache) { var excludePattern = rule.excludePattern; var searchPath = PathUtility.RelativeProjectPathToAbsolutePath(rule.path); var subDirectories = Directory.GetDirectories(searchPath, "*.*", (SearchOption)rule.depth) .Where(v => !IsExclude(v, excludePattern)) .ToArray(); foreach (var subDirectory in subDirectories) { var files = Directory .GetFiles(subDirectory, rule.searchPattern, SearchOption.AllDirectories) .Where(v => !IsMeta(v)) .Where(v => !IsExclude(v, excludePattern)) .ToArray(); var bundleName = PathUtility.NormalizeAssetBundlePath(subDirectory); bundleName = string.Format(BundlerBuildSettings.kBundleFormatter, bundleName); bundleName = BundlerBuildSettings.kHashAssetBundlePath ? PathUtility.HashPath(bundleName) : bundleName; try { var index = 0; foreach (var file in files) { EditorUtility.DisplayProgressBar("Parsing Rule of Pack By Sub Directory Name", file, (float)index++ / files.Length); var relativePath = PathUtility.AbsolutePathToRelativeProjectPath(file); if (rule.shared) { TryAddToForceSharedBundle(relativePath, bundleName, ref reserved); } AddDependenciesInfo(bundleName, relativePath, ref depsInfo, ref reserved, ref cache); } } finally { EditorUtility.ClearProgressBar(); } } }