Пример #1
0
        private static int Run(Options options, ILogger logger)
        {
            // Initialize basic command options.
            //Parser.Default.ParseArguments<Options>(args)
            //    .WithParsed(options =>
            //    {
            try
            {
                var(workingFolder, intermediateFolder, generatedCodeFolder, compilingFiles) = DeconstructPaths(options);
                var rebuildRequired        = options.RebuildRequired;
                var cachedExcludesListFile = Path.Combine(intermediateFolder, "Excludes.txt");

                // 如果可以差量编译,那么检测之前已经生成的文件,然后将其直接输出。
                if (!rebuildRequired && File.Exists(cachedExcludesListFile))
                {
                    var cachedExcludeLines = File.ReadAllLines(cachedExcludesListFile, Encoding.UTF8);
                    foreach (var exclude in cachedExcludeLines)
                    {
                        logger.Message(exclude);
                    }
                    return(0);
                }

                var assembly = new CompileAssembly(compilingFiles);

                // 分析 IPlainCodeTransformer。
                var transformer = new CodeTransformer(workingFolder, generatedCodeFolder, assembly);
                var excludes    = transformer.Transform();

                // 分析 CompileTimeTemplate。
                var templateTransformer = new TemplateTransformer(workingFolder, generatedCodeFolder, assembly);
                var templateExcludes    = templateTransformer.Transform();

                var toExcludes = excludes.Union(templateExcludes)
                                 .Select(x => PathEx.MakeRelativePath(workingFolder, x)).ToArray();

                foreach (var exclude in toExcludes)
                {
                    logger.Message(exclude);
                }

                File.WriteAllLines(cachedExcludesListFile, toExcludes, Encoding.UTF8);
            }
            catch (CompilingException ex)
            {
                foreach (var error in ex.Errors)
                {
                    logger.Error($"error:{error}");
                }
            }
            catch (Exception ex)
            {
                logger.Error($"error:{ex}");
            }
            //})
            //.WithNotParsed(errorList => { });

            return(0);
        }
Пример #2
0
        private void RunCore()
        {
            var context                = new ProjectCompilingContext(_options);
            var rebuildRequired        = _options.RebuildRequired;
            var cachedExcludesListFile = Path.Combine(context.ToolsFolder, "Excludes.txt");

            // 如果可以差量编译,那么检测之前已经生成的文件,然后将其直接输出。
            if (!rebuildRequired && File.Exists(cachedExcludesListFile))
            {
                var cachedExcludeLines = File.ReadAllLines(cachedExcludesListFile, Encoding.UTF8);
                foreach (var exclude in cachedExcludeLines)
                {
                    _logger.Message(exclude);
                }

                return;
            }

            // 分析 IPlainCodeTransformer。
            var transformer = new CodeTransformer(context);
            var excludes    = transformer.Transform();

            // 分析 CompileTimeTemplate。
            var templateTransformer = new TemplateTransformer(context);
            var templateExcludes    = templateTransformer.Transform();

            var toExcludes = excludes.Union(templateExcludes)
                             .Select(x => PathEx.MakeRelativePath(context.WorkingFolder, x)).ToArray();

            foreach (var exclude in toExcludes)
            {
                _logger.Message(exclude);
            }

            File.WriteAllLines(cachedExcludesListFile, toExcludes, Encoding.UTF8);
        }