Example #1
0
        public void TestConcurrencyWriteAccess()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{99D73F8B-587A-4869-97AE-4A7185D88AC9}");
            Utils.GenerateSourceFile("input2", "{9FEABA51-4CE6-4DB0-9866-45A7492FD1B7}");
            var inputDep = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1"));

            var builder            = Utils.CreateBuilder(false);
            CommandBuildStep step1 = builder.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", InputDependencies = { inputDep }
            });
            CommandBuildStep step2 = builder.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input2")), OutputUrl = "/db/url2", InputDependencies = { inputDep }
            });
            CommandBuildStep concurrencyStep1 = builder.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.Content, "/db/url1"), OutputUrl = "/db/url", InputDependencies = { inputDep }
            });
            CommandBuildStep concurrencyStep2 = builder.Root.Add(new InputOutputTestCommand {
                Delay = 150, Source = new ObjectUrl(UrlType.Content, "/db/url2"), OutputUrl = "/db/url", InputDependencies = { inputDep }
            });

            BuildStep.LinkBuildSteps(step1, concurrencyStep1);
            BuildStep.LinkBuildSteps(step2, concurrencyStep2);

            builder.Run(Builder.Mode.Build);
            var logger = (LoggerResult)builder.Logger;

            Assert.Contains(logger.Messages, x => x.Text.Contains("Commands InputOutputTestCommand /db/url2 > /db/url and InputOutputTestCommand /db/url1 > /db/url are both writing /db/url at the same time"));
        }
Example #2
0
        public void TestSpawnCommandOutput()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{05D6BCFA-B1FE-4AD1-920F-0352A6DEC02D}");
            Utils.GenerateSourceFile("input2", "{B9D01D6C-4048-4814-A2DF-9D317A492B10}");

            var builder = Utils.CreateBuilder();
            var command = new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            };

            command.CommandsToSpawn.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input2")), OutputUrl = "/db/url2"
            });
            CommandBuildStep step = builder.Root.Add(command);

            builder.Run(Builder.Mode.Build);
            builder.WriteIndexFile(false);

            Assert.That(step.SpawnedSteps.Count(), Is.EqualTo(1));

            var indexMap = AssetIndexMap.Load();

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url2", out outputId);

            Assert.IsTrue(objectIdFound);
            Assert.That(step.SpawnedSteps.First().Result.OutputObjects[new ObjectUrl(UrlType.Internal, "/db/url2")], Is.EqualTo(outputId));
        }
Example #3
0
        public void TestConcurrencyReadWriteAccess()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{99D73F8B-587A-4869-97AE-4A7185D88AC9}");
            var inputDep = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1"));

            var builder           = Utils.CreateBuilder(false);
            CommandBuildStep step = builder.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", InputDependencies = { inputDep }
            });
            CommandBuildStep concurrencyStep1 = builder.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.Content, "/db/url1"), OutputUrl = "/db/url1", InputDependencies = { inputDep }
            });
            CommandBuildStep concurrencyStep2 = builder.Root.Add(new InputOutputTestCommand {
                Delay = 150, Source = new ObjectUrl(UrlType.Content, "/db/url1"), OutputUrl = "/db/url2", InputDependencies = { inputDep }
            });

            BuildStep.LinkBuildSteps(step, concurrencyStep1);
            BuildStep.LinkBuildSteps(step, concurrencyStep2);

            builder.Run(Builder.Mode.Build);
            var logger = (LoggerResult)builder.Logger;

            Assert.Contains("Command InputOutputTestCommand /db/url1 > /db/url1 is writing /db/url1 while command InputOutputTestCommand /db/url1 > /db/url2 is reading it", logger.Messages.Select(x => x.Text));
        }
Example #4
0
        public void TestInputDependencies()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{A7246DF6-3A68-40E2-BA58-6C9A0EFF552B}");
            Utils.GenerateSourceFile("inputDeps", "{8EE7A4BC-88E1-4CC8-B03F-1E6EA8B23955}");

            var builder  = Utils.CreateBuilder(false);
            var inputDep = new ObjectUrl(UrlType.File, Utils.GetSourcePath("inputDeps"));
            var command  = new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            };

            command.InputDependencies.Add(inputDep);
            CommandBuildStep step = builder.Root.Add(command);

            builder.Run(Builder.Mode.Build);

            var indexMap = ContentIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath);

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId inputDepId;
            bool     inputDepFound = step.Result.InputDependencyVersions.TryGetValue(inputDep, out inputDepId);

            Assert.True(inputDepFound);
        }
Example #5
0
        public void TestUseBuildCacheOutput()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{32E4EDF4-E8AA-4D13-B111-9BD8AA2A8B07}");

            var builder1 = Utils.CreateBuilder(false);

            builder1.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });
            builder1.Run(Builder.Mode.Build);

            var builder2          = Utils.CreateBuilder(true);
            CommandBuildStep step = builder2.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });

            builder2.Run(Builder.Mode.Build);
            builder2.WriteIndexFile(false);

            Assert.Equal(ResultStatus.NotTriggeredWasSuccessful, step.Status);
            Assert.Contains(new ObjectUrl(UrlType.Content, "/db/url1"), step.Result.OutputObjects.Keys);

            var indexMap = ContentIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath);

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url1", out outputId);

            Assert.True(objectIdFound);
            Assert.Equal(step.Result.OutputObjects[new ObjectUrl(UrlType.Content, "/db/url1")], outputId);
        }
Example #6
0
        public void TestSpawnCommandOutput()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{05D6BCFA-B1FE-4AD1-920F-0352A6DEC02D}");
            Utils.GenerateSourceFile("input2", "{B9D01D6C-4048-4814-A2DF-9D317A492B10}");

            var builder = Utils.CreateBuilder(true);
            var command = new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            };

            command.CommandsToSpawn.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input2")), OutputUrl = "/db/url2"
            });
            CommandBuildStep step = builder.Root.Add(command);

            builder.Run(Builder.Mode.Build);
            builder.WriteIndexFile(false);

            var indexMap = ContentIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath);

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url2", out outputId);

            Assert.True(objectIdFound);
        }
Example #7
0
        public void TestConcurrencyReadWriteAccess()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{99D73F8B-587A-4869-97AE-4A7185D88AC9}");
            var inputDep = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1"));

            var builder           = Utils.CreateBuilder();
            CommandBuildStep step = builder.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", InputDependencies = { inputDep }
            });

            builder.Root.Add(new WaitBuildStep());
            CommandBuildStep concurrencyStep1 = builder.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.Internal, "/db/url1"), OutputUrl = "/db/url1", InputDependencies = { inputDep }
            });
            CommandBuildStep concurrencyStep2 = builder.Root.Add(new InputOutputCommand {
                Delay = 150, Source = new ObjectUrl(UrlType.Internal, "/db/url1"), OutputUrl = "/db/url2", InputDependencies = { inputDep }
            });

            BuildStep.LinkBuildSteps(step, concurrencyStep1);
            BuildStep.LinkBuildSteps(step, concurrencyStep2);

            Utils.StartCapturingLog();
            builder.Run(Builder.Mode.Build);
            string log = Utils.StopCapturingLog();

            Assert.That(log.Contains("Command InputOutputCommand /db/url1 > /db/url1 is writing /db/url1 while command InputOutputCommand /db/url1 > /db/url2 is reading it"));
        }
Example #8
0
        public void TestConcurrencyWriteAccess()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{99D73F8B-587A-4869-97AE-4A7185D88AC9}");
            Utils.GenerateSourceFile("input2", "{9FEABA51-4CE6-4DB0-9866-45A7492FD1B7}");
            var inputDep = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1"));

            var builder            = Utils.CreateBuilder();
            CommandBuildStep step1 = builder.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", InputDependencies = { inputDep }
            });
            CommandBuildStep step2 = builder.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input2")), OutputUrl = "/db/url2", InputDependencies = { inputDep }
            });

            builder.Root.Add(new WaitBuildStep());
            CommandBuildStep concurrencyStep1 = builder.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.Internal, "/db/url1"), OutputUrl = "/db/url", InputDependencies = { inputDep }
            });
            CommandBuildStep concurrencyStep2 = builder.Root.Add(new InputOutputCommand {
                Delay = 150, Source = new ObjectUrl(UrlType.Internal, "/db/url2"), OutputUrl = "/db/url", InputDependencies = { inputDep }
            });

            BuildStep.LinkBuildSteps(step1, concurrencyStep1);
            BuildStep.LinkBuildSteps(step2, concurrencyStep2);

            Utils.StartCapturingLog();
            builder.Run(Builder.Mode.Build);
            string log = Utils.StopCapturingLog();

            Assert.That(log.Contains("Commands InputOutputCommand /db/url2 > /db/url and InputOutputCommand /db/url1 > /db/url are both writing /db/url at the same time"));
        }
Example #9
0
        public void TestInputFromPreviousOutput()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{E7635471-8551-4C80-9E37-A1EBAFC3869E}");

            var builder           = Utils.CreateBuilder();
            CommandBuildStep step = builder.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });

            builder.Root.Add(new WaitBuildStep());
            CommandBuildStep childStep = builder.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.Internal, "/db/url1"), OutputUrl = "/db/url2"
            });

            BuildStep.LinkBuildSteps(step, childStep);
            builder.Run(Builder.Mode.Build);
            builder.WriteIndexFile(false);

            Assert.IsTrue(step.Result.OutputObjects.Keys.Contains(new ObjectUrl(UrlType.Internal, "/db/url1")));
            Assert.IsTrue(childStep.Result.OutputObjects.Keys.Contains(new ObjectUrl(UrlType.Internal, "/db/url2")));

            var indexMap = AssetIndexMap.Load();

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url2", out outputId);

            Assert.IsTrue(objectIdFound);
            Assert.That(childStep.Result.OutputObjects[new ObjectUrl(UrlType.Internal, "/db/url2")], Is.EqualTo(outputId));
        }
Example #10
0
        public void TestRemoteSpawnCommandOutput()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{BB42A922-ED1B-4837-98D2-189EFAF6BF42}");
            Utils.GenerateSourceFile("input2", "{8B212FA9-5F0D-4D29-A68B-01D87FF04AF4}");

            var builder = Utils.CreateBuilder();
            var command = new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", ExecuteRemotely = true
            };

            command.CommandsToSpawn.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input2")), OutputUrl = "/db/url2"
            });
            CommandBuildStep step = builder.Root.Add(command);

            builder.Run(Builder.Mode.Build);
            builder.WriteIndexFile(false);

            Assert.That(step.SpawnedSteps.Count(), Is.EqualTo(1));

            var indexMap = AssetIndexMap.Load();

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url2", out outputId);

            Assert.IsTrue(objectIdFound);
            Assert.That(step.SpawnedSteps.First().Result.OutputObjects[new ObjectUrl(UrlType.Internal, "/db/url2")], Is.EqualTo(outputId));
        }
Example #11
0
        public void TestTwoCommandsSameOutput()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{3F3C2132-911E-465C-B98F-020278ED4512}");

            var builder           = Utils.CreateBuilder(true);
            CommandBuildStep step = builder.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });
            CommandBuildStep childStep = builder.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });

            BuildStep.LinkBuildSteps(step, childStep);
            builder.Run(Builder.Mode.Build);
            builder.WriteIndexFile(false);

            Assert.Contains(new ObjectUrl(UrlType.Content, "/db/url1"), step.Result.OutputObjects.Keys);
            Assert.Contains(new ObjectUrl(UrlType.Content, "/db/url1"), childStep.Result.OutputObjects.Keys);

            var indexMap = ContentIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath);

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url1", out outputId);

            Assert.True(objectIdFound);
            Assert.Equal(childStep.Result.OutputObjects[new ObjectUrl(UrlType.Content, "/db/url1")], outputId);
        }
Example #12
0
        public void TestInputFromPreviousOutputWithCache()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{E60A3248-B4D8-43F6-9A73-975FD9A653FC}");

            var builder1          = Utils.CreateBuilder();
            CommandBuildStep step = builder1.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });

            builder1.Root.Add(new WaitBuildStep());
            CommandBuildStep childStep = builder1.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.Internal, "/db/url1"), OutputUrl = "/db/url2"
            });

            BuildStep.LinkBuildSteps(step, childStep);
            builder1.Run(Builder.Mode.Build);

            VirtualFileSystem.FileDelete("/data/db/index");

            var builder2 = Utils.CreateBuilder();

            step = builder2.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });
            builder2.Root.Add(new WaitBuildStep());
            childStep = builder2.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.Internal, "/db/url1"), OutputUrl = "/db/url2"
            });
            BuildStep.LinkBuildSteps(step, childStep);
            builder2.Run(Builder.Mode.Build);
            builder2.WriteIndexFile(false);

            Assert.That(step.Status, Is.EqualTo(ResultStatus.NotTriggeredWasSuccessful));
            Assert.That(childStep.Status, Is.EqualTo(ResultStatus.NotTriggeredWasSuccessful));

            Assert.IsTrue(step.Result.OutputObjects.Keys.Contains(new ObjectUrl(UrlType.Internal, "/db/url1")));
            Assert.IsTrue(childStep.Result.OutputObjects.Keys.Contains(new ObjectUrl(UrlType.Internal, "/db/url2")));

            var indexMap = AssetIndexMap.Load();

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url2", out outputId);

            Assert.IsTrue(objectIdFound);
            Assert.That(childStep.Result.OutputObjects[new ObjectUrl(UrlType.Internal, "/db/url2")], Is.EqualTo(outputId));
        }
Example #13
0
        public void TestSingleCommandTwiceWithInputChange()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{71938BC2-6876-406E-84E9-4F4E862651D5}");

            var builder1           = Utils.CreateBuilder(false);
            CommandBuildStep step1 = builder1.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });

            builder1.Run(Builder.Mode.Build);

            // Modifying input file
            Utils.GenerateSourceFile("input1", "{5794B336-55F9-400A-B99D-DA61C9F09CCE}", true);

            var builder2           = Utils.CreateBuilder(true);
            CommandBuildStep step2 = builder2.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1"
            });

            builder2.Run(Builder.Mode.Build);
            builder2.WriteIndexFile(false);

            Assert.Contains(new ObjectUrl(UrlType.Content, "/db/url1"), step1.Result.OutputObjects.Keys);
            Assert.Contains(new ObjectUrl(UrlType.Content, "/db/url1"), step2.Result.OutputObjects.Keys);

            var indexMap = ContentIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath);

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url1", out outputId);

            Assert.True(objectIdFound);

            Assert.Equal(ResultStatus.Successful, step1.Status);
            Assert.Equal(ResultStatus.Successful, step2.Status);
            Assert.NotEqual(step1.Result.OutputObjects[new ObjectUrl(UrlType.Content, "/db/url1")], outputId);
            Assert.Equal(step2.Result.OutputObjects[new ObjectUrl(UrlType.Content, "/db/url1")], outputId);
        }
Example #14
0
        private static void CommonSingleOutput(bool executeRemotely)
        {
            var builder           = Utils.CreateBuilder(true);
            CommandBuildStep step = builder.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", ExecuteRemotely = executeRemotely
            });

            builder.Run(Builder.Mode.Build);
            builder.WriteIndexFile(false);

            Assert.Contains(new ObjectUrl(UrlType.Content, "/db/url1"), step.Result.OutputObjects.Keys);

            var indexMap = ContentIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath);

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url1", out outputId);

            Assert.True(objectIdFound);
            Assert.Equal(step.Result.OutputObjects[new ObjectUrl(UrlType.Content, "/db/url1")], outputId);
        }
Example #15
0
        void CommonSingleOutput(bool executeRemotely)
        {
            var builder           = Utils.CreateBuilder();
            CommandBuildStep step = builder.Root.Add(new InputOutputCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", ExecuteRemotely = executeRemotely
            });

            builder.Run(Builder.Mode.Build);
            builder.WriteIndexFile(false);

            Assert.Contains(new ObjectUrl(UrlType.Internal, "/db/url1"), step.Result.OutputObjects.Keys);

            var indexMap = AssetIndexMap.Load();

            indexMap.UseTransaction = true;
            indexMap.LoadNewValues();

            ObjectId outputId;
            bool     objectIdFound = indexMap.TryGetValue("/db/url1", out outputId);

            Assert.IsTrue(objectIdFound);
            Assert.That(step.Result.OutputObjects[new ObjectUrl(UrlType.Internal, "/db/url1")], Is.EqualTo(outputId));
        }
Example #16
0
        public void TestInputDependenciesChange()
        {
            Utils.CleanContext();
            Utils.GenerateSourceFile("input1", "{A7246DF6-3A68-40E2-BA58-6C9A0EFF552B}");
            Utils.GenerateSourceFile("inputDeps", "{8EE7A4BC-88E1-4CC8-B03F-1E6EA8B23955}");
            var inputDep = new ObjectUrl(UrlType.File, Utils.GetSourcePath("inputDeps"));

            var builder1           = Utils.CreateBuilder(false);
            CommandBuildStep step1 = builder1.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", InputDependencies = { inputDep }
            });

            builder1.Run(Builder.Mode.Build);

            Utils.GenerateSourceFile("inputDeps", "{E505A61B-5F2A-4BB8-8F6C-3788C76BAE5F}", true);

            var builder2           = Utils.CreateBuilder(false);
            CommandBuildStep step2 = builder2.Root.Add(new InputOutputTestCommand {
                Delay = 100, Source = new ObjectUrl(UrlType.File, Utils.GetSourcePath("input1")), OutputUrl = "/db/url1", InputDependencies = { inputDep }
            });

            builder2.Run(Builder.Mode.Build);

            var indexMap = ContentIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath);

            indexMap.LoadNewValues();

            Assert.Equal(ResultStatus.Successful, step1.Status);
            Assert.Equal(ResultStatus.Successful, step2.Status);
            ObjectId inputDepId1;
            ObjectId inputDepId2;

            Assert.True(step1.Result.InputDependencyVersions.TryGetValue(inputDep, out inputDepId1));
            Assert.True(step2.Result.InputDependencyVersions.TryGetValue(inputDep, out inputDepId2));
            Assert.NotEqual(inputDepId1, inputDepId2);
        }
Example #17
0
        protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var asset             = (AnimationAsset)assetItem.Asset;
            var assetAbsolutePath = assetItem.FullPath;
            // Get absolute path of asset source on disk
            var assetDirectory = assetAbsolutePath.GetParent();
            var assetSource    = GetAbsolutePath(assetItem, asset.Source);
            var extension      = assetSource.GetFileExtension();
            var buildStep      = new AssetBuildStep(assetItem);

            // Find skeleton asset, if any
            AssetItem skeleton = null;

            if (asset.Skeleton != null)
            {
                skeleton = assetItem.Package.FindAssetFromProxyObject(asset.Skeleton);
            }

            var sourceBuildCommand = ImportModelCommand.Create(extension);

            if (sourceBuildCommand == null)
            {
                result.Error($"No importer found for model extension '{extension}. The model '{assetSource}' can't be imported.");
                return;
            }

            sourceBuildCommand.Mode                   = ImportModelCommand.ExportMode.Animation;
            sourceBuildCommand.SourcePath             = assetSource;
            sourceBuildCommand.Location               = targetUrlInStorage;
            sourceBuildCommand.AnimationRepeatMode    = asset.RepeatMode;
            sourceBuildCommand.AnimationRootMotion    = asset.RootMotion;
            sourceBuildCommand.ImportCustomAttributes = asset.ImportCustomAttributes;
            if (asset.ClipDuration.Enabled)
            {
                sourceBuildCommand.StartFrame = asset.ClipDuration.StartAnimationTime;
                sourceBuildCommand.EndFrame   = asset.ClipDuration.EndAnimationTime;
            }
            else
            {
                sourceBuildCommand.StartFrame = TimeSpan.Zero;
                sourceBuildCommand.EndFrame   = AnimationAsset.LongestTimeSpan;
            }
            sourceBuildCommand.ScaleImport   = asset.ScaleImport;
            sourceBuildCommand.PivotPosition = asset.PivotPosition;

            if (skeleton != null)
            {
                sourceBuildCommand.SkeletonUrl = skeleton.Location;
                // Note: skeleton override values
                sourceBuildCommand.ScaleImport   = ((SkeletonAsset)skeleton.Asset).ScaleImport;
                sourceBuildCommand.PivotPosition = ((SkeletonAsset)skeleton.Asset).PivotPosition;
            }

            if (asset.Type.Type == AnimationAssetTypeEnum.AnimationClip)
            {
                // Import the main animation
                buildStep.Add(sourceBuildCommand);
            }
            else if (asset.Type.Type == AnimationAssetTypeEnum.DifferenceClip)
            {
                var diffAnimationAsset = ((DifferenceAnimationAssetType)asset.Type);
                var referenceClip      = diffAnimationAsset.BaseSource;
                var rebaseMode         = diffAnimationAsset.Mode;

                var baseUrlInStorage   = targetUrlInStorage + RefClipSuffix;
                var sourceUrlInStorage = targetUrlInStorage + SrcClipSuffix;

                var baseAssetSource = UPath.Combine(assetDirectory, referenceClip);
                var baseExtension   = baseAssetSource.GetFileExtension();

                sourceBuildCommand.Location = sourceUrlInStorage;

                var baseBuildCommand = ImportModelCommand.Create(extension);
                if (baseBuildCommand == null)
                {
                    result.Error($"No importer found for model extension '{baseExtension}. The model '{baseAssetSource}' can't be imported.");
                    return;
                }

                baseBuildCommand.FailOnEmptyAnimation = false;
                baseBuildCommand.Mode                = ImportModelCommand.ExportMode.Animation;
                baseBuildCommand.SourcePath          = baseAssetSource;
                baseBuildCommand.Location            = baseUrlInStorage;
                baseBuildCommand.AnimationRepeatMode = asset.RepeatMode;
                baseBuildCommand.AnimationRootMotion = asset.RootMotion;

                if (diffAnimationAsset.ClipDuration.Enabled)
                {
                    baseBuildCommand.StartFrame = diffAnimationAsset.ClipDuration.StartAnimationTimeBox;
                    baseBuildCommand.EndFrame   = diffAnimationAsset.ClipDuration.EndAnimationTimeBox;
                }
                else
                {
                    baseBuildCommand.StartFrame = TimeSpan.Zero;
                    baseBuildCommand.EndFrame   = AnimationAsset.LongestTimeSpan;
                }

                baseBuildCommand.ScaleImport   = asset.ScaleImport;
                baseBuildCommand.PivotPosition = asset.PivotPosition;

                if (skeleton != null)
                {
                    baseBuildCommand.SkeletonUrl = skeleton.Location;
                    // Note: skeleton override values
                    baseBuildCommand.ScaleImport   = ((SkeletonAsset)skeleton.Asset).ScaleImport;
                    baseBuildCommand.PivotPosition = ((SkeletonAsset)skeleton.Asset).PivotPosition;
                }

                // Import base and main animation
                var sourceStep = new CommandBuildStep(sourceBuildCommand);
                buildStep.Add(sourceStep);
                var baseStep = new CommandBuildStep(baseBuildCommand);
                buildStep.Add(baseStep);

                IEnumerable <ObjectUrl> InputFilesGetter()
                {
                    yield return(new ObjectUrl(UrlType.File, GetAbsolutePath(assetItem, diffAnimationAsset.BaseSource)));
                }

                var diffCommand = new AdditiveAnimationCommand(targetUrlInStorage, new AdditiveAnimationParameters(baseUrlInStorage, sourceUrlInStorage, rebaseMode), assetItem.Package)
                {
                    InputFilesGetter = InputFilesGetter
                };

                var diffStep = new CommandBuildStep(diffCommand);

                BuildStep.LinkBuildSteps(sourceStep, diffStep);
                BuildStep.LinkBuildSteps(baseStep, diffStep);

                // Generate the diff of those two animations
                buildStep.Add(diffStep);
            }
            else
            {
                throw new NotImplementedException("This type of animation asset is not supported yet!");
            }

            result.BuildSteps = buildStep;
        }
Example #18
0
        protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var asset = (SkyboxAsset)assetItem.Asset;

            var colorSpace = context.GetColorSpace();

            result.BuildSteps = new AssetBuildStep(assetItem);

            var prereqs = new Queue <BuildStep>();

            // build the textures for windows (needed for skybox compilation)
            foreach (var dependency in asset.GetDependencies())
            {
                var dependencyItem = assetItem.Package.Assets.Find(dependency.Id);
                if (dependencyItem?.Asset is TextureAsset)
                {
                    var textureAsset = (TextureAsset)dependencyItem.Asset;

                    // Get absolute path of asset source on disk
                    var assetSource = GetAbsolutePath(dependencyItem, textureAsset.Source);

                    // Create a synthetic url
                    var textureUrl = SkyboxGenerator.BuildTextureForSkyboxGenerationLocation(dependencyItem.Location);

                    var gameSettingsAsset = context.GetGameSettingsAsset();
                    var renderingSettings = gameSettingsAsset.GetOrCreate <RenderingSettings>(context.Platform);

                    // Select the best graphics profile
                    var graphicsProfile = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_10_0 ? renderingSettings.DefaultGraphicsProfile : GraphicsProfile.Level_10_0;

                    var textureAssetItem = new AssetItem(textureUrl, textureAsset);

                    // Create and add the texture command.
                    var textureParameters = new TextureConvertParameters(assetSource, textureAsset, PlatformType.Windows, GraphicsPlatform.Direct3D11, graphicsProfile, gameSettingsAsset.GetOrCreate <TextureSettings>().TextureQuality, colorSpace);
                    var prereqStep        = new AssetBuildStep(textureAssetItem);
                    prereqStep.Add(new TextureAssetCompiler.TextureConvertCommand(textureUrl, textureParameters, assetItem.Package));
                    result.BuildSteps.Add(prereqStep);
                    prereqs.Enqueue(prereqStep);
                }
            }

            // add the skybox command itself.
            IEnumerable <ObjectUrl> InputFilesGetter()
            {
                var skyboxAsset = (SkyboxAsset)assetItem.Asset;

                foreach (var dependency in skyboxAsset.GetDependencies())
                {
                    var dependencyItem = assetItem.Package.Assets.Find(dependency.Id);
                    if (dependencyItem?.Asset is TextureAsset)
                    {
                        yield return(new ObjectUrl(UrlType.Content, dependency.Location));
                    }
                }
            }

            var assetStep = new CommandBuildStep(new SkyboxCompileCommand(targetUrlInStorage, asset, assetItem.Package)
            {
                InputFilesGetter = InputFilesGetter
            });

            result.BuildSteps.Add(assetStep);
            while (prereqs.Count > 0)
            {
                var prereq = prereqs.Dequeue();
                BuildStep.LinkBuildSteps(prereq, assetStep);
            }
        }