-
-
Save silky/bf304785a46db32b5cc8 to your computer and use it in GitHub Desktop.
FAKE build file example with multiple targets specified in many files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "bar_build.fsx" | |
#r @"../../tools/FAKE/FakeLib.dll" | |
#load @"common_targets.fsx" // the order is important. | |
#load @"foo_targets.fsx" | |
#load @"bar_targets.fsx" | |
open Fake | |
setEnvironVar "PROJECT_NAME" "BarProj" | |
RunTargetOrDefault "Bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "bar_targets.fsx" | |
#r @"../../tools/FAKE/FakeLib.dll" | |
#load @"CommonFuncs.fsx" | |
open Fake | |
open CommonFuncs | |
module Bar = | |
Description "Bars" | |
Target "Bar" (fun _ -> trace "And you have me building software ..." ) | |
"Env" ==> "Bar" | |
"Foo" ==> "Bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "common.fsx" | |
#r @"../../tools/FAKE/FakeLib.dll" | |
#load "CommonFuncs.fsx" | |
open Fake | |
open System.Collections.Generic | |
open System | |
open System.Threading | |
open CommonFuncs | |
open Fuchu | |
module Common = | |
Target "Env" (fun _ -> trace "Env") | |
Target "Tested" (fun _ -> | |
let k = CommonFuncs.tests |> run | |
if k = 1 then | |
failwith "Tests failed!" | |
) | |
// Horrifyingly offensive but "Fuchu" defines its own "==>" operator, | |
// so we can't use that here to express this dependency. We really ask | |
// that before anyone does anything, they check that the build script | |
// itself works. | |
Dependencies "Env" ["Tested"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "CommonFuncs.fsx" | |
#r "../../tools/FAKE/FakeLib.dll" | |
#r "../../tools/Fuchu/lib/net40-client/Fuchu.dll" | |
open Fake | |
open System.Collections.Generic | |
open System | |
open System.IO | |
open System.Threading | |
open Fuchu | |
module CommonFuncs = | |
let projectName = | |
fun _ -> environVar "PROJECT_NAME" | |
let FBoo () = | |
2 | |
/// Runs a command and, if it doesn't return 0, fails the build. | |
let ExecAndCheck (cmd : string) (dir :string) (args_list : List<string>) : unit = | |
let args = String.concat " " args_list | |
let result = execProcess (fun info -> | |
info.FileName <- cmd | |
info.WorkingDirectory <- dir | |
info.Arguments <- args) System.TimeSpan.MaxValue | |
if not result then | |
let msg = sprintf "Failed running '%s' with args '%s'." cmd args | |
raise <| new Exception(msg) | |
[<Tests>] | |
let ``tests`` = | |
TestList [ | |
testCase "Want FBoo () = 2" <| fun _ -> Assert.Equal("Foo () == 2", FBoo (), 2) | |
// testCase "Want FBoo () = 3" <| fun _ -> Assert.Equal("Foo () == 3", FBoo (), 3) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "foo_build.fsx" | |
#r @"../../tools/FAKE/FakeLib.dll" | |
#load @"common_targets.fsx" // the order is important | |
#load @"foo_targets.fsx" | |
open Fake | |
setEnvironVar "PROJECT_NAME" "FooProj" | |
RunTargetOrDefault "Foo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "foo_targets.fsx" | |
#r @"../../tools/FAKE/FakeLib.dll" | |
#load @"CommonFuncs.fsx" | |
open Fake | |
open CommonFuncs | |
module Foo = | |
Description "Foos" | |
Target "Foo" (fun _ -> | |
trace <| sprintf "Here I am, foo the size of a bar, in %s" (CommonFuncs.projectName ()) | |
) | |
"Env" ==> "Foo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "marvin_build.fsx" | |
#r @"../../tools/FAKE/FakeLib.dll" | |
#load @"common_targets.fsx" // order is important | |
#load @"foo_targets.fsx" | |
#load @"bar_targets.fsx" | |
#load @"marvin_targets.fsx" | |
open Fake | |
setEnvironVar "PROJECT_NAME" "MarvinProj" | |
RunTargetOrDefault "Marvin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "marvin_targets.fsx" | |
#r @"../../tools/FAKE/FakeLib.dll" | |
#load @"CommonFuncs.fsx" | |
open Fake | |
open CommonFuncs | |
module Marvin = | |
Target "Marvin" (fun _ -> ()) | |
"Bar" ==> "Marvin" | |
"Foo" ==> "Marvin" | |
"Foo" ==> "Bar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like your solution for the most part. I am wondering though, what is the best way to get variables defined in the primary build script into the included targets (The scripts are #load'd at the top of the main build.fsx, before the variables are even defined)?