File: FSYacc.Build.fs

package info (click to toggle)
fsharp 3.1.1.26%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 59,244 kB
  • ctags: 4,190
  • sloc: cs: 13,398; ml: 1,098; sh: 399; makefile: 293; xml: 82
file content (124 lines) | stat: -rwxr-xr-x 3,623 bytes parent folder | download
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// (c) Microsoft Corporation 2005-2009.

namespace Microsoft.FSharp.Build

open System
open Microsoft.Build.Framework
open Microsoft.Build.Utilities
open Internal.Utilities

(**************************************
MSBuild task for fsyacc
**************************************)

type FsYacc() = 
    inherit ToolTask()

    let mutable inputFile  : string = null
    let mutable outputFile : string = null
    
    let mutable codePage   : string = null
    let mutable otherFlags : string = null
    let mutable mlCompat   = false
    
    let mutable _open  : string = null
    let mutable _module  : string = null

    let mutable toolPath : string = 
        match FSharpEnvironment.BinFolderOfFSharpPowerPack with
        | Some s -> s
        | None -> ""
#if FX_ATLEAST_35
#else
    let mutable toolExe : string = "fsyacc.exe"
#endif

    // [<Required>]
    member this.InputFile
        with get ()  = inputFile
        and  set (x) = inputFile <- x
    
    [<Microsoft.Build.Framework.Output>]
    member this.OutputFile
        with get ()  = outputFile
        and  set (x) = outputFile <- x
    
    member this.OtherFlags
        with get() = otherFlags
        and set(s) = otherFlags <- s

    // --codepage <int>: Assume input lexer specification file is encoded with the given codepage.
    member this.CodePage
        with get ()  = codePage
        and  set (x) = codePage <- x
    
    // --ml-compatibility: Support the use of the global state from the 'Parsing' module in MLLib.
    member this.MLCompatibility
        with get ()  = mlCompat
        and  set (x) = mlCompat <- x
        
    // --open
    member this.Open
        with get ()  = _open
        and  set (x) = _open <- x       

   // --module
    member this.Module
        with get ()  = _module
        and  set (x) = _module <- x             

    // For targeting other versions of fslex.exe, such as "\LKG\" or "\Prototype\"
    member this.ToolPath
        with get ()  = toolPath
        and  set (s) = toolPath <- s
        
#if FX_ATLEAST_35
#else
    // Name of the .exe to call
    member this.ToolExe
        with get ()  = toolExe
        and  set (s) = toolExe <- s        
#endif

    // ToolTask methods
    override this.ToolName = "fsyacc.exe"
    
    override this.GenerateFullPathToTool() = 
        System.IO.Path.Combine(toolPath, this.ToolExe)
        
    override this.GenerateCommandLineCommands() =
    
        let builder = new CommandLineBuilder()
        
        // CodePage
        builder.AppendSwitchIfNotNull("--codepage ", codePage)
        
        // ML Compatibility
        if mlCompat then builder.AppendSwitch("--ml-compatibility")

        // Open
        builder.AppendSwitchIfNotNull("--open ", _open)

        // Module
        builder.AppendSwitchIfNotNull("--module ", _module)

        // OutputFile
        builder.AppendSwitchIfNotNull("-o ", outputFile)

        // OtherFlags - must be second-to-last
        builder.AppendSwitchUnquotedIfNotNull("", otherFlags)

        builder.AppendSwitchIfNotNull(" ", inputFile)
        
        let args = builder.ToString()

        // when doing simple unit tests using API, no BuildEnginer/Logger is attached
        if this.BuildEngine <> null then
            let eventArgs = { new CustomBuildEventArgs(message=args,helpKeyword="",senderName="") with member x.Equals(y) = false }
            this.BuildEngine.LogCustomEvent(eventArgs)
        
        args
    
    // Expose this to internal components (for unit testing)
    member internal this.InternalGenerateCommandLineCommands() =
        this.GenerateCommandLineCommands()