Пример #1
0
        /// <summary>
        /// Restores the stored files for a given builder to a file system directory
        ///
        /// <para>The cache only stores the latest stored results and this is what will be restored
        /// to the target directory. To verify if it was generated with the correct dependency fingerprint,
        /// use <see cref="IBuildCache.Contains"/>.</para>
        /// <para>To ensure thread safety, use <see cref="IBuildCache.LockForBuilder"/>.</para>
        /// </summary>
        /// <param name="builder">Builder key</param>
        /// <param name="targetRoot">Target file system directory</param>
        /// <returns>Returns the target root relative paths of all the restored files</returns>
        public ISet <TargetRelativePath> Restore(BuildKey builder, IFileSystemDirectory targetRoot)
        {
            MemoryCacheItem item;

            lock (cache)
                cache.TryGetValue(builder, out item);

            if (item != null)
            {
                var outputs = item.Outputs;
                var paths   = new HashSet <TargetRelativePath>();
                foreach (var pair in outputs)
                {
                    if (pair.Value != null)
                    {
                        using (var stream = targetRoot.CreateBinaryFile(pair.Key))
                            stream.Write(pair.Value, 0, pair.Value.Length);
                    }

                    paths.Add(pair.Key);
                }

                return(paths);
            }
            else
            {
                return(new HashSet <TargetRelativePath>());
            }
        }
Пример #2
0
        /// <summary>
        /// Copies output files to the cache directory, and also saves a '.names' file referring to he original target relative
        /// paths of these files.
        /// </summary>
        /// <param name="outputs">Build outputs to be copied</param>
        /// <param name="targetRoot">Root directory for the build outputs</param>
        /// <param name="cacheDir">Target directory for the copy operation</param>
        private void SaveOutputs(IEnumerable <TargetRelativePath> outputs, IFileSystemDirectory targetRoot, IFileSystemDirectory cacheDir)
        {
            using (var names = cacheDir.CreateTextFile(NamesFileName))
            {
                int idx = 0;
                foreach (var outputPath in outputs)
                {
                    try
                    {
                        // It is possible that the returned path is a special path and does not refer to an existing file
                        // In this case we only have to save the filename, without its contents
                        if (targetRoot.Exists(outputPath))
                        {
                            using (var source = targetRoot.ReadBinaryFile(outputPath))
                                using (var target = cacheDir.CreateBinaryFile(idx.ToString(CultureInfo.InvariantCulture)))
                                {
                                    StreamOperations.Copy(source, target);
                                }
                        }

                        names.WriteLine("{0};{1}", outputPath.RelativeRoot, outputPath.RelativePath);
                        idx++;
                    }
                    catch (IOException ex)
                    {
                        log.WarnFormat("IOException while reading {0}: {1}", outputPath, ex.Message);

                        if (!outputPath.RelativePath.ToLowerInvariant().EndsWith(".vshost.exe"))
                        {
                            throw;
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Copies a file from the FS repository to a given target directory
 /// </summary>
 /// <param name="path">Path to the file in the FS repository</param>
 /// <param name="targetDir">Target directory</param>
 /// <param name="targetFileName">Target file name</param>
 public void Copy(string path, IFileSystemDirectory targetDir, string targetFileName)
 {
     using (var source = GetDirectory(path).ReadBinaryFile(Path.GetFileName(path)))
         using (var target = targetDir.CreateBinaryFile(targetFileName))
         {
             StreamOperations.Copy(source, target);
         }
 }
 /// <summary>
 /// Copies a file from the FS repository to a given target directory
 /// </summary>
 /// <param name="path">Path to the file in the FS repository</param>
 /// <param name="targetDir">Target directory</param>
 /// <param name="targetFileName">Target file name</param>
 public void Copy(string path, IFileSystemDirectory targetDir, string targetFileName)
 {
     using (var source = GetDirectory(path).ReadBinaryFile(Path.GetFileName(path)))
     using (var target = targetDir.CreateBinaryFile(targetFileName))
     {
         StreamOperations.Copy(source, target);
     }
 }
Пример #5
0
        private void RunWithProjects(CommandTarget target, bool dumpMode, bool dumpDepsMode)
        {
            log.InfoFormat("Building...");

            var context = buildContextFactory.CreateBuildContext();

            var projects = target.Projects.ToList();

            IBuilder rootBuilder = coreBuilderFactory.Merge(
                projectBuilders
                .Select(pb => pb.Create(projects))
                .Where(b => b != null).ToArray(),
                new ProjectBuilderTag("Top level project builders", projects));

            if (rootBuilder != null)
            {
                context.AddBuilder(rootBuilder);

                var productTarget = target as ProductTarget;
                if (productTarget != null)
                {
                    rootBuilder = AddProductBuildStep(context, productTarget.Product, rootBuilder);
                }

                if (dumpMode)
                {
                    context.Dump(name => targetRoot.CreateBinaryFile("builders." + name + ".dot"), rootBuilder);
                }
                else if (dumpDepsMode)
                {
                    context.DumpDependencies(rootBuilder, output);
                }
                else
                {
                    var result = context.Run(rootBuilder);

                    if (result.Count > 0)
                    {
                        var outputs = context.GetResults(rootBuilder);
                        foreach (var outputPath in outputs)
                        {
                            log.DebugFormat("Generated output for build: {0}", outputPath);
                        }
                    }
                    else
                    {
                        log.Warn("Build produced no results");
                    }
                }
            }

            output.Message("Build completed.");
        }
Пример #6
0
        private void Copy(SuiteRelativePath sourcePath, string relativePath)
        {
            var relativeDir = Path.GetDirectoryName(relativePath);
            var fileName    = Path.GetFileName(relativePath);
            var targetDir   = targetRoot.GetChildDirectory(project.Module.Name, createIfMissing: true);

            IFileSystemDirectory realTargetDir = String.IsNullOrWhiteSpace(relativeDir)
                ? targetDir
                : targetDir.GetChildDirectory(relativeDir, createIfMissing: true);

            using (var source = suiteRoot.ReadBinaryFile(sourcePath))
                using (var target = realTargetDir.CreateBinaryFile(fileName))
                    StreamOperations.Copy(source, target);
        }
Пример #7
0
        /// <summary>
        /// Creates a binary file in the given directory, or in a subdirectory of it.
        /// If the subdirectory does not exist, it will be created.
        /// </summary>
        /// <param name="root">The root directory</param>
        /// <param name="relativePath">Relative path of the file to be created</param>
        /// <returns>Returns the stream for writing the binary file.</returns>
        public static Stream CreateBinaryFileWithDirectories(this IFileSystemDirectory root, string relativePath)
        {
            Contract.Requires(root != null);
            Contract.Requires(!String.IsNullOrWhiteSpace(relativePath));

            string dirName = Path.GetDirectoryName(relativePath);

            if (!String.IsNullOrWhiteSpace(dirName))
            {
                var subdir = root.GetChildDirectory(dirName, createIfMissing: true);
                return(subdir.CreateBinaryFile(Path.GetFileName(relativePath)));
            }
            else
            {
                return(root.CreateBinaryFile(relativePath));
            }
        }
Пример #8
0
        private IEnumerable <TargetRelativePath> RunWithProjects(IEnumerable <TestProject> projects, bool dumpMode)
        {
            var context = buildContextFactory.CreateBuildContext();

            IBuilder rootBuilder = projectBuilders.Select(pb => pb.AddToContext(context, projects))
                                   .Where(b => b != null).ToArray().Merge();

            if (dumpMode)
            {
                using (var builderGraph = targetRoot.CreateBinaryFile("builders.dot"))
                    context.Dump(builderGraph, rootBuilder);

                return(new TargetRelativePath[0]);
            }
            else
            {
                context.Run(rootBuilder);
                return(context.GetResults(rootBuilder));
            }
        }
Пример #9
0
        private IEnumerable <TargetRelativePath> RunWithProjects(IEnumerable <Project> projects, bool dumpMode, bool dumpDepsMode)
        {
            var context = buildContextFactory.CreateBuildContext();

            var prjs = projects.ToList();

            IBuilder rootBuilder = coreBuilderFactory.Merge(
                projectBuilders
                .Select(pb => pb.Create(prjs))
                .Where(b => b != null).ToArray(),
                new ProjectBuilderTag("Top level test project builders", prjs));

            context.AddBuilder(rootBuilder);

            if (dumpMode)
            {
                context.Dump(name => targetRoot.CreateBinaryFile("builders." + name + ".dot"), rootBuilder);

                return(new TargetRelativePath[0]);
            }
            else if (dumpDepsMode)
            {
                context.DumpDependencies(rootBuilder, output);

                return(new TargetRelativePath[0]);
            }
            else
            {
                var result = context.Run(rootBuilder);
                if (result.Count != 0)
                {
                    return(context.GetResults(rootBuilder));
                }
                else
                {
                    log.WarnFormat("No tests to run");
                    return(new TargetRelativePath[0]);
                }
            }
        }
Пример #10
0
        private void RunWithProjects(CommandTarget target, bool dumpMode)
        {
            log.InfoFormat("Building...");

            var context = buildContextFactory.CreateBuildContext();

            var projects = target.Projects.ToList();

            IBuilder rootBuilder = projectBuilders.Select(pb => pb.AddToContext(context, projects))
                                   .Where(b => b != null).ToArray().Merge();

            rootBuilder.AddToContext(context);

            if (dumpMode)
            {
                using (var builderGraph = targetRoot.CreateBinaryFile("builders.dot"))
                    context.Dump(builderGraph, rootBuilder);
            }
            else
            {
                context.Run(rootBuilder);

                var outputs = context.GetResults(rootBuilder);
                foreach (var outputPath in outputs)
                {
                    log.DebugFormat("Generated output for build: {0}", outputPath);
                }

                var productTarget = target as ProductTarget;
                if (productTarget != null)
                {
                    MergeOutputForProduct(productTarget.Product, outputs);
                }
            }

            output.Message("Build completed.");
        }
Пример #11
0
 /// <summary>
 /// Saves a dependency fingerprint to the cache directory
 /// </summary>
 /// <param name="fingerprint">Fingerprint to be saved</param>
 /// <param name="cacheDir">Target directory</param>
 private void SaveDependencyFingerprint(IDependencyFingerprint fingerprint, IFileSystemDirectory cacheDir)
 {
     using (var depStream = cacheDir.CreateBinaryFile(DepsFileName))
         fingerprint.Save(protocolSerializer, depStream);
 }
Пример #12
0
 /// <summary>
 /// Saves a dependency fingerprint to the cache directory
 /// </summary>
 /// <param name="fingerprint">Fingerprint to be saved</param>
 /// <param name="cacheDir">Target directory</param>
 private void SaveDependencyFingerprint(IDependencyFingerprint fingerprint, IFileSystemDirectory cacheDir)
 {
     using (var depStream = cacheDir.CreateBinaryFile(DepsFileName))
         fingerprint.Save(protocolSerializer, depStream);
 }
Пример #13
0
        /// <summary>
        /// Restores the stored files for a given builder to a file system directory
        /// 
        /// <para>The cache only stores the latest stored results and this is what will be restored
        /// to the target directory. To verify if it was generated with the correct dependency fingerprint,
        /// use <see cref="IBuildCache.Contains"/>.</para>
        /// <para>To ensure thread safety, use <see cref="IBuildCache.LockForBuilder"/>.</para>
        /// </summary>
        /// <param name="builder">Builder key</param>
        /// <param name="targetRoot">Target file system directory</param>        
        /// <param name="aggressive">If <c>true</c>, files in the target directory won't be checked by hash before overriding them</param>
        /// <param name="aggressiveExceptions">Exceptions to the aggresivve mode. Can be <c>null</c> if not used.</param>
        /// <returns>Returns the target root relative paths of all the restored files</returns>
        public ISet<TargetRelativePath> Restore(BuildKey builder, IFileSystemDirectory targetRoot, bool aggressive, Regex[] aggressiveExceptions = null)
        {
            MemoryCacheItem item;
            lock (cache)
                cache.TryGetValue(builder, out item);

            if (item != null)
            {
                var outputs = item.Outputs;
                var paths = new HashSet<TargetRelativePath>();
                foreach (var pair in outputs)
                {
                    if (pair.Value != null)
                    {
                        using (var stream = targetRoot.CreateBinaryFile(pair.Key))
                            stream.Write(pair.Value, 0, pair.Value.Length);
                    }

                    paths.Add(pair.Key);
                }

                return paths;
            }
            else
            {
                return new HashSet<TargetRelativePath>();
            }
        }
Пример #14
0
        /// <summary>
        /// Copies output files to the cache directory, and also saves a '.names' file referring to he original target relative
        /// paths of these files.
        /// </summary>
        /// <param name="outputs">Build outputs to be copied</param>
        /// <param name="targetRoot">Root directory for the build outputs</param>
        /// <param name="cacheDir">Target directory for the copy operation</param>
        private void SaveOutputs(IEnumerable<TargetRelativePath> outputs, IFileSystemDirectory targetRoot, IFileSystemDirectory cacheDir)
        {
            using (var names = cacheDir.CreateTextFile(NamesFileName))
            {
                int idx = 0;
                foreach (var outputPath in outputs)
                {
                    try
                    {
                        // It is possible that the returned path is a special path and does not refer to an existing file
                        // In this case we only have to save the filename, without its contents
                        if (targetRoot.Exists(outputPath))
                        {
                            using (var source = targetRoot.ReadBinaryFile(outputPath))
                            using (var target = cacheDir.CreateBinaryFile(idx.ToString(CultureInfo.InvariantCulture)))
                            {
                                StreamOperations.Copy(source, target);
                            }
                        }

                        names.WriteLine("{0};{1}", outputPath.RelativeRoot, outputPath.RelativePath);
                        idx++;
                    }
                    catch (IOException ex)
                    {
                        log.WarnFormat("IOException while reading {0}: {1}", outputPath, ex.Message);

                        if (!outputPath.RelativePath.ToLowerInvariant().EndsWith(".vshost.exe"))
                            throw;
                    }
                }
            }
        }
Пример #15
0
        public bool Run(Core.Model.Suite suite, string[] parameters)
        {
            var effectiveLength = parameters.Length;
            var modulesOnly     = false;

            if (effectiveLength > 0)
            {
                modulesOnly = effectiveLength >= 1 && parameters[effectiveLength - 1] == "--module";
            }

            var modules = suite.Modules;
            var target  = "suite";

            if (modulesOnly && effectiveLength > 1 || (!modulesOnly && effectiveLength > 0))
            {
                var product = parameters[0];
                if (suite.HasProduct(product))
                {
                    target  = product;
                    modules = suite.GetProduct(product).Modules;
                }
                else
                {
                    throw new InvalidCommandParameterException("dependecies", "The given project does not exist");
                }
            }

            try
            {
                using (var writer = new DotWriter(targetRoot.CreateBinaryFile("deps." + target + ".dot")))
                {
                    var edges = new HashSet <EquatableEdge <string> >();

                    writer.Rankdir         = "LR";
                    writer.RemoveSelfLoops = true;

                    foreach (var module in modules)
                    {
                        foreach (var project in module.Projects)
                        {
                            foreach (var reference in project.References)
                            {
                                EquatableEdge <string> edge = null;
                                if (modulesOnly)
                                {
                                    edge = GetModuleEdge(reference, project);
                                }
                                else
                                {
                                    edge = GetProjectEdge(reference, project);
                                }

                                if (edge != null)
                                {
                                    edges.Add(edge);
                                }
                            }
                        }
                    }
                    writer.WriteGraph(edges);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }