Skip to content

Build improvements #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ tmp
bin/configlet
bin/configlet.exe
.fake/
.paket/paket.exe
.vs/
tools/
build/
packages/
TestResult.xml
Binary file added .paket/paket.bootstrapper.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: csharp

script:
- bin/fetch-configlet
- bin/configlet .
- build.sh
- ./bin/fetch-configlet
- ./bin/configlet .
- ./build.sh
4 changes: 3 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
build_script:
- ps: .\build.ps1
- ps: .\build.cmd

test: off
14 changes: 14 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@echo off
cls

.paket\paket.bootstrapper.exe
if errorlevel 1 (
exit /b %errorlevel%
)

.paket\paket.exe restore
if errorlevel 1 (
exit /b %errorlevel%
)

packages\FAKE\tools\FAKE.exe build.fsx %*
93 changes: 43 additions & 50 deletions build.fsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,61 @@
// Include Fake library
#r "tools/FAKE/tools/FakeLib.dll"
#r "./packages/FAKE/tools/FakeLib.dll"

open Fake
open Fake.CscHelper
open Fake.Testing.NUnit3

// Properties
let sourceDir = "./exercises/"
let buildDir = getBuildParamOrDefault "buildDir" "./build/"
let buildExampleDir = buildDir @@ "example"
let buildTestDir = buildDir @@ "test"
let exampleDll = buildExampleDir @@ "example.dll"
let testDll = buildTestDir @@ "test.dll"
let nunitFrameworkDll = "tools/NUnit/lib/net45/nunit.framework.dll"
// Directories
let buildDir = "./build/"
let sourceDir = "./exercises/"

let exampleSourceFiles() = !! (buildExampleDir @@ "./**/*.cs") |> List.ofSeq
let testSourceFiles() = !! (buildTestDir @@ "./**/*.cs") |> List.ofSeq

let compile output files =
files
|> Csc (fun p ->
{ p with Output = output
References = [nunitFrameworkDll]
Target = Library })
// Files
let solutionFile = buildDir @@ "/exercises.csproj"
let compiledOutput = buildDir @@ "xcsharp.dll"

// Targets
Target "CleanExamples" (fun _ -> CleanDir buildExampleDir)
Target "CleanTests" (fun _ -> CleanDir buildTestDir)
Target "PrepareUnchanged" (fun _ ->
CleanDirs [buildDir]
CopyDir buildDir sourceDir allFiles
)

Target "CopyExamples" (fun _ -> CopyDir buildExampleDir sourceDir allFiles)
Target "CopyTests" (fun _ -> CopyDir buildTestDir sourceDir allFiles)
Target "BuildUnchanged" (fun _ ->
MSBuildRelease buildDir "Build" [solutionFile]
|> Log "Build unchanged output: "
)

Target "PrepareTests" (fun _ ->
testSourceFiles()
|> ReplaceInFiles [("[Ignore(\"Remove to run test\")]", ""); (", Ignore = \"Remove to run test case\"", "")]
CleanDirs [buildDir]
CopyDir buildDir sourceDir allFiles

let ignorePattern = "(\[Ignore\(\"Remove to run test\"\)]|, Ignore = \"Remove to run test case\")"

!! (buildDir @@ "**/*Test.cs")
|> RegexReplaceInFilesWithEncoding ignorePattern "" System.Text.Encoding.UTF8
)

Target "CompileExamples" (fun _ -> exampleSourceFiles() |> compile exampleDll)
Target "CompileTests" (fun _ -> testSourceFiles() |> compile testDll)
Target "BuildTests" (fun _ ->
MSBuildRelease buildDir "Build" [solutionFile]
|> Log "Build tests output: "
)

Target "Test" (fun _ ->
Copy buildTestDir [nunitFrameworkDll]

[testDll]
|> NUnit3 (fun p ->
{ p with
ShadowCopy = false })
if getEnvironmentVarAsBool "APPVEYOR" then
[compiledOutput]
|> NUnit3 (fun p -> { p with
ShadowCopy = false
ToolPath = @"C:\Tools\NUnit3\bin\nunit3-console.exe"
ResultSpecs = ["myresults.xml;format=AppVeyor"] })
else
[compiledOutput]
|> NUnit3 (fun p -> { p with ShadowCopy = false })
)

Target "Build" (fun _ -> ())
Target "Default" (fun _ -> ())

"CleanExamples"
==> "CopyExamples"
==> "CompileExamples"
==> "Build"
// Build order
"PrepareUnchanged"
==> "BuildUnchanged"
==> "PrepareTests"
==> "BuildTests"
==> "Test"

"CleanTests"
==> "CopyTests"
==> "PrepareTests"
==> "CompileTests"
==> "Test"

"Build" ==> "Default"
"Test" ==> "Default"

RunTargetOrDefault "Default"
// start build
RunTargetOrDefault "Test"
36 changes: 0 additions & 36 deletions build.ps1

This file was deleted.

71 changes: 29 additions & 42 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,33 @@
#!/usr/bin/env bash
#!/bin/bash
if test "$OS" = "Windows_NT"
then
# use .Net

currentDirectory="$( cd "$( dirname "$0" )" && pwd )"
toolsDirectory=$currentDirectory/tools
nugetDirectory=$toolsDirectory/nuget
nugetExe=$nugetDirectory/nuget.exe
fakeExe=$toolsDirectory/FAKE/tools/FAKE.exe
nunitFrameworkDll=$toolsDirectory/NUnit/lib/net45/nunit.framework.dll
nunitConsoleExe=$toolsDirectory/NUnit.Console/tools/nunit3-console.exe
.paket/paket.bootstrapper.exe
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi

if test ! -d $nugetDirectory; then
mkdir -p $nugetDirectory
fi
.paket/paket.exe restore
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi

if test ! -f $nugetExe; then
nugetUrl="https://dist.nuget.org/win-x86-commandline/v3.3.0/nuget.exe"
wget -O $nugetExe $nugetUrl 2> /dev/null || curl -o $nugetExe --location $nugetUrl /dev/null

if test ! -f $nugetExe; then
echo "Could not find nuget.exe"
exit 1
fi

chmod 755 $nugetExe
fi
packages/FAKE/tools/FAKE.exe $@ --fsiargs build.fsx
else
# use mono
mono .paket/paket.bootstrapper.exe
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi

mono $nugetExe install FAKE -Version 4.17.1 -ExcludeVersion -OutputDirectory $toolsDirectory
if test ! -f $fakeExe; then
echo "Could not find fake.exe"
exit 1
fi

mono $nugetExe install NUnit -Version 3.0.1 -ExcludeVersion -OutputDirectory $toolsDirectory
if test ! -f $nunitFrameworkDll; then
echo "Could not find nunit.framework.dll"
exit 1
fi

mono $nugetExe install NUnit.Console -Version 3.0.1 -ExcludeVersion -OutputDirectory $toolsDirectory
if test ! -f $nunitConsoleExe; then
echo "Could not find nunit3-console.exe"
exit 1
fi

# Use FAKE to execute the build script
mono $fakeExe build.fsx $@
mono .paket/paket.exe restore
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi
mono packages/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO build.fsx
fi
1 change: 0 additions & 1 deletion exercises/atbash-cipher/AtbashTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[TestFixture]
public class AtbashTest
{
// change Ignore to false to run test case or just remove 'Ignore = true'
[TestCase("no", ExpectedResult = "ml")]
[TestCase("yes", ExpectedResult = "bvh", Ignore = "Remove to run test case")]
[TestCase("OMG", ExpectedResult = "lnt", Ignore = "Remove to run test case")]
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion exercises/binary/BinaryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[TestFixture]
public class BinaryTest
{
// change Ignore to false to run test case or just remove 'Ignore = true'
[TestCase("1", ExpectedResult = 1)]
[TestCase("10", ExpectedResult = 2, Ignore = "Remove to run test case")]
[TestCase("11", ExpectedResult = 3, Ignore = "Remove to run test case")]
Expand Down
97 changes: 97 additions & 0 deletions exercises/exercises.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FEF69435-D885-45DD-A446-04FD3BD3F593}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>xcsharp</RootNamespace>
<AssemblyName>xcsharp</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v3.0')">
<ItemGroup>
<Reference Include="NUnit.System.Linq">
<HintPath>..\packages\NUnit\lib\net20\NUnit.System.Linq.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net20\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v3.5'">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net35\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.0'">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="($(TargetFrameworkIdentifier) == 'WindowsPhoneApp') Or ($(TargetFrameworkIdentifier) == '.NETCore') Or ($(TargetFrameworkIdentifier) == '.NETStandard' And ($(TargetFrameworkVersion) == 'v1.0' Or $(TargetFrameworkVersion) == 'v1.1' Or $(TargetFrameworkVersion) == 'v1.2' Or $(TargetFrameworkVersion) == 'v1.3' Or $(TargetFrameworkVersion) == 'v1.4' Or $(TargetFrameworkVersion) == 'v1.5' Or $(TargetFrameworkVersion) == 'v1.6')) Or ($(TargetFrameworkIdentifier) == '.NETCoreApp' And $(TargetFrameworkVersion) == 'v1.0') Or ($(TargetFrameworkIdentifier) == 'WindowsPhone' And ($(TargetFrameworkVersion) == 'v8.0' Or $(TargetFrameworkVersion) == 'v8.1')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch') Or ($(TargetFrameworkIdentifier) == 'Xamarin.iOS') Or ($(TargetFrameworkIdentifier) == 'Xamarin.Mac') Or ($(TargetFrameworkProfile) == 'Profile7') Or ($(TargetFrameworkProfile) == 'Profile31') Or ($(TargetFrameworkProfile) == 'Profile32') Or ($(TargetFrameworkProfile) == 'Profile44') Or ($(TargetFrameworkProfile) == 'Profile49') Or ($(TargetFrameworkProfile) == 'Profile78') Or ($(TargetFrameworkProfile) == 'Profile84') Or ($(TargetFrameworkProfile) == 'Profile111') Or ($(TargetFrameworkProfile) == 'Profile151') Or ($(TargetFrameworkProfile) == 'Profile157') Or ($(TargetFrameworkProfile) == 'Profile259')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
</Project>
1 change: 0 additions & 1 deletion exercises/hexadecimal/HexadecimalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[TestFixture]
public class HexadecimalTest
{
// change Ignore to false to run test case or just remove 'Ignore = true'
[TestCase("1", ExpectedResult = 1)]
[TestCase("c", ExpectedResult = 12, Ignore = "Remove to run test case")]
[TestCase("10", ExpectedResult = 16, Ignore = "Remove to run test case")]
Expand Down
Loading