aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/CommandLine/CompileCommand.cs
blob: 17847b57c4f26c280a7a0dd4765a39702f2bc525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.Core
{
    using System;
    using System.Collections.Generic;
    using WixToolset.Data;

    internal class CompileCommand : ICommand
    {
        public CompileCommand(IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables)
        {
            this.PreprocessorVariables = preprocessorVariables;
            this.SourceFiles = sources;
        }

        private IEnumerable<SourceFile> SourceFiles { get; }

        private IDictionary<string, string> PreprocessorVariables { get; }

        public int Execute()
        {
            var preprocessor = new Preprocessor();

            var compiler = new Compiler();

            foreach (var sourceFile in this.SourceFiles)
            {
                var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables);

                var intermediate = compiler.Compile(document);

                intermediate.Save(sourceFile.OutputPath);
            }

            return 0;
        }
    }
}