Last active
July 4, 2017 21:43
-
-
Save jbtule/11181987 to your computer and use it in GitHub Desktop.
Single file Crossplatform FSharp MakeFile bootstrap
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
#!/bin/sh | |
#if run_with_bin_sh | |
# Doing this because arguments can't be used with /usr/bin/env on linux, just mac | |
exec fsharpi --define:mono_posix --exec $0 $* | |
#endif | |
#if FSharp_MakeFile | |
(* | |
* Single File Crossplatform FSharp Makefile Bootstrapper | |
* Apache licensed - Copyright 2014 Jay Tuley <[email protected]> | |
* v 2.0 https://gist.github.com/jbtule/11181987 | |
* | |
* How to use: | |
* On Windows `fsi --exec build.fsx <buildtarget> | |
* *Note:* if you have trouble first run "%vs120comntools%\vsvars32.bat" or use the "Developer Command Prompt for VS201X" | |
* or install https://github.com/Iristyle/Posh-VsVars#posh-vsvars | |
* | |
* On Mac Or Linux `./build.fsx <buildtarget>` | |
* *Note:* But if you have trouble then use `sh build.fsx <buildtarget>` | |
* | |
*) | |
#I "packages/FAKE/tools" | |
#r "FakeLib.dll" | |
open Fake | |
Target "NugetRestore" (fun () -> | |
trace " --- Nuget Restore --- " | |
) | |
Target "Clean" (fun () -> | |
trace " --- Cleaning stuff --- " | |
) | |
Target "Build" (fun () -> | |
trace " --- Building the libs --- " | |
) | |
Target "Test" (fun () -> | |
trace " --- Test the libs --- " | |
) | |
"NugetRestore" | |
==> "Build" | |
==> "Test" | |
RunTargetOrDefault "Test" | |
#else | |
open System | |
open System.IO | |
open System.Diagnostics | |
(* helper functions *) | |
#if mono_posix | |
#r "Mono.Posix.dll" | |
open Mono.Unix.Native | |
let applyExecutionPermissionUnix path = | |
let _,stat = Syscall.lstat(path) | |
Syscall.chmod(path, FilePermissions.S_IXUSR ||| stat.st_mode) |> ignore | |
#else | |
let applyExecutionPermissionUnix path = () | |
#endif | |
let doesNotExist path = | |
path |> Path.GetFullPath |> File.Exists |> not | |
let execAt (workingDir:string) (exePath:string) (args:string seq) = | |
let processStart (psi:ProcessStartInfo) = | |
let ps = Process.Start(psi) | |
ps.WaitForExit () | |
ps.ExitCode | |
let fullExePath = exePath |> Path.GetFullPath | |
applyExecutionPermissionUnix fullExePath | |
let exitCode = ProcessStartInfo( | |
fullExePath, | |
args |> String.concat " ", | |
WorkingDirectory = (workingDir |> Path.GetFullPath), | |
UseShellExecute = false) | |
|> processStart | |
if exitCode <> 0 then | |
exit exitCode | |
() | |
let exec = execAt Environment.CurrentDirectory | |
let downloadNugetTo path = | |
let fullPath = path |> Path.GetFullPath; | |
if doesNotExist fullPath then | |
printf "Downloading NuGet..." | |
use webClient = new System.Net.WebClient() | |
fullPath |> Path.GetDirectoryName |> Directory.CreateDirectory |> ignore | |
webClient.DownloadFile("https://nuget.org/nuget.exe", path |> Path.GetFullPath) | |
printfn "Done." | |
let passedArgs = fsi.CommandLineArgs.[1..] |> Array.toList | |
(* execution script customize below *) | |
let makeFsx = fsi.CommandLineArgs.[0] | |
let nugetExe = ".nuget/NuGet.exe" | |
let fakeExe = "packages/FAKE/tools/FAKE.exe" | |
downloadNugetTo nugetExe | |
if doesNotExist fakeExe then | |
exec nugetExe ["install"; "fake"; "-OutputDirectory packages"; "-ExcludeVersion"] | |
exec fakeExe ([makeFsx; "-d:FSharp_MakeFile"] @ passedArgs) | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment