Skip to content

Commit

Permalink
ccnet#271 Fix build on linux
Browse files Browse the repository at this point in the history
- use msbuild on linux instead of the default xbuild provided by msbuild NAnt task
- fix references since linux cares about upper/lower case
- add some tooling from NuGet
- Update Cake to v0.36 due to cake-build/cake#2546
- add a 'clean' cake target
  • Loading branch information
savornicesei committed Jan 19, 2020
1 parent 4b3bd16 commit bae4730
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 47 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ docgen/
wiki/
**/CommonAssemblyInfo.cs

#ignore NuGet tools
[Tt]ools/EWSoftware.SHFB*
[Tt]ools/vswhere*

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
Expand Down
2 changes: 1 addition & 1 deletion Tools/Cake/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Cake" version="0.33.0" />
<package id="Cake" version="0.36.0" />
</packages>
54 changes: 52 additions & 2 deletions Tools/ccnet-utils.inc.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,55 @@
</delete>

</target>

</project>

<!--***********************************
Determines the path to MSBuild based on the same logic as NuGet (see NuGetClient.CommandLine.MsBuildUtility)
*********************************** -->
<script language="C#" prefix="linux">
<code>
<![CDATA[
[Function("get-msbuild-path")]
public static string getMSBuildPath()
{
string msBuildPath = string.Empty;
try
{
var platform = (int)Environment.OSVersion.Platform;
var isLinux = platform == 4;
var isMono = Type.GetType("Mono.Runtime") != null;
if(isLinux && isMono)
{
var libPath = Path.GetDirectoryName(typeof(object).Assembly.Location);
//path to msbuild folder is /usr/lib/mono/msbuild
//path to xbuild folder is /usr/lib/mono/xbuild
string[] buildExecutables = new string[4]{
Path.Combine(libPath, "..", "msbuild", "15.0", "bin", "MSBuild.dll"),
Path.Combine(libPath, "..", "msbuild", "14.1", "bin", "MSBuild.dll"),
Path.Combine(libPath, "..", "xbuild", "14.0", "bin", "xbuild.exe"),
Path.Combine(libPath, "..", "xbuild", "12.0", "bin", "xbuild.exe")
};
foreach(var buildExe in buildExecutables)
{
if(File.Exists(buildExe))
{
msBuildPath = buildExe;
break;
}
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
return msBuildPath;
}
]]>
</code>
</script>

</project>
48 changes: 35 additions & 13 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
var product = "CruiseControl.NET";

var target = Argument("target", "default");
var configuration = Argument("configuration", "Debug");
var configuration = Argument("configuration", "Debug");
var verbosity = Argument("verbosity", "Normal");

var nantExe = @".\Tools\NAnt\NAnt.exe";
Expand Down Expand Up @@ -47,7 +47,7 @@ Setup(context =>
assemblySemFileVer = gitVersionResults.AssemblySemFileVer;
informationalVersion = gitVersionResults.InformationalVersion;
}
Information("Building version {0} of {1}.", informationalVersion, product);
Information("Target: {0}.", target);
});
Expand All @@ -63,18 +63,40 @@ Task("default")
.Does(() =>
{
Information("Available targets");
Information(" clean : Cleans folders created at build time (Build, Publish, Dist)");
Information(" build : Builds the project by running the clean and build targets from ccnet.build script");
Information(" build-all : Builds the project, runs tests and packages artifacts by running the all target from ccnet.build script");
Information(" run-tests : Run projects tests by executing the runTests target from ccnet.build script");
Information(" package : Packages project artifacts by running package target from ccnet.build script");
Information(" web-packages : Packages the project webdashboards by running build.packages from ccnet.build script");
});

Task("clean")
.Does(()=> {
//Tools\NAnt\NAnt.exe clean -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -nologo -logfile:nant-build.log.txt %*
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
Arguments = " clean -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build.log.txt" ,
RedirectStandardError = false,
RedirectStandardOutput = false,
Silent = false
}))
{
process.WaitForExit();
Information("Nant: build target exit code: {0}", process.GetExitCode());
if(process.GetExitCode() > 0)
{
throw new Exception("Cake: build target failed");
}
}
});

Task("build")
.Does(()=> {
//Tools\NAnt\NAnt.exe clean build -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -nologo -logfile:nant-build.log.txt %*
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
Arguments = " clean build -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build.log.txt" ,
RedirectStandardError = false,
RedirectStandardOutput = false,
Expand All @@ -94,8 +116,8 @@ Task("build")
Task("build-all")
.Does(()=> {
//Tools\NAnt\NAnt.exe clean build -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -nologo -logfile:nant-build.log.txt %*
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
Arguments = " all -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build.log.txt" ,
RedirectStandardError = false,
RedirectStandardOutput = false,
Expand All @@ -115,8 +137,8 @@ Task("build-all")
Task("run-tests")
.Does(()=>{
//Tools\NAnt\NAnt.exe runTests -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -nologo -logfile:nant-build-tests.log.txt %*
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
Arguments = " runTests -buildfile:ccnet.build -D:codemetrics.output.type=HtmlFile -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build-tests.log.txt" ,
RedirectStandardError = false,
RedirectStandardOutput = false,
Expand All @@ -135,8 +157,8 @@ Task("run-tests")
Task("package")
.Does(()=>{
//Tools\NAnt\NAnt.exe package -buildfile:ccnet.build -D:CCNetLabel=1.5.0.0 -nologo -logfile:nant-build-package.log.txt %*
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
Arguments = " package -buildfile:ccnet.build -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build-package.log.txt" ,
RedirectStandardError = false,
RedirectStandardOutput = false,
Expand All @@ -155,8 +177,8 @@ Task("package")
Task("web-packages")
.Does(()=>{
//Tools\NAnt\NAnt.exe build.packages -buildfile:ccnet.build -nologo -logfile:nant-build-web-packages.log.txt %*
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
using(var process = StartAndReturnProcess(nantExe,
new ProcessSettings{
Arguments = " build.packages -buildfile:ccnet.build -D:version=" + assemblySemVer + " -D:fversion=" + assemblySemFileVer + " -D:iversion=\"" + informationalVersion + "\" -nologo -logfile:nant-build-web-packages.log.txt" ,
RedirectStandardError = false,
RedirectStandardOutput = false,
Expand All @@ -172,4 +194,4 @@ Task("web-packages")
}
});

RunTarget(target);
RunTarget(target);
94 changes: 72 additions & 22 deletions ccnet.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@
<property name="fxcop.executable" readonly="true" value="${path::combine( path::combine(tools.dir, 'FxCop'), 'FxCopCmd.exe')}" />
<property name="nunit.executable" readonly="true" value="${path::combine( path::combine(tools.dir, 'NUnit'), 'nunit-console-x86.exe')}" />
<property name="nsis.executable" readonly="true" value="${path::combine( path::combine(tools.dir, 'NSIS'), 'makensis.exe')}" />
<property name="nuget.executable" readonly="true" value="${environment::get-variable('NUGET_EXE')}" />
<!-- If NUGET_EXE env. variable does not exist, fallback to the one provided by Cake -->
<property name="nuget.executable" value="${environment::get-variable('NUGET_EXE')}" if="${environment::variable-exists('NUGET_EXE')}" />
<property name="nuget.executable" value="${path::combine( path::combine(tools.dir, 'Cake'), 'nuget.exe')}" if="${not environment::variable-exists('NUGET_EXE')}" />

<!-- NuGet tools retrieved at restore time -->
<property name="vswhere.executable" value="${path::combine( path::combine(tools.dir, 'vswhere.2.8.4'), 'tools')}" unless="${property::exists('vswhere.path')}" />
<property name="shfb.path" value="${path::combine( path::combine(tools.dir, 'EWSoftware.SHFB.2019.11.17'), 'tools')}" unless="${property::exists('shfb.path')}" />

<!-- common assembly info properties -->
<property name="assembly.company" readonly="true" value="ThoughtWorks Inc." />
<property name="assembly.product" readonly="true" value="CruiseControl.NET" />
<property name="assembly.copyright" readonly="true" value="Copyright © 2003 - ${datetime::get-year(datetime::now())} ${assembly.company}" />
<property name="assembly.trademark" readonly="true" value="" />
<property name="assembly.version" value="${version}" />
<property name="assembly.fileversion" value="${fversion}" />
<property name="assembly.informalversion" value="${iversion}" />
<property name="assembly.fileversion" value="${fversion}" />
<property name="assembly.informalversion" value="${iversion}" />


<!-- Framework Support
http://nant.sourceforge.net/faq.html#framework-support
Expand All @@ -53,7 +59,7 @@
<include buildfile="${path::combine(tools.dir, 'ccnet-packaging.inc.build')}" />
<include buildfile="${path::combine(tools.dir, 'ccnet-help.inc.build')}" />
<include buildfile="${path::combine(tools.dir, 'ccnet-utils.inc.build')}" />
<include buildfile="${path::combine(tools.dir, 'ccnet-packaging-webdashboard-packages.inc.build')}" />
<include buildfile="${path::combine(tools.dir, 'ccnet-packaging-webdashboard-packages.inc.build')}" />

<!-- Targets -->
<target name="all" depends="clean, init, build, runTests, runCodeMetrics, package" description="" />
Expand Down Expand Up @@ -84,6 +90,30 @@
</target>

<target name="restore" description="Restore the nuget packages">
<!-- Restore NuGet tools -->
<exec program="${nuget.executable}" if="${file::exists(nuget.executable)}">
<arg value="install"/>
<arg value="vswhere" />
<arg value="-Version" />
<arg value="2.8.4" />
<arg value="-OutputDirectory"/>
<arg value="${tools.dir}"/>
<arg value="-verbosity" />
<arg value="quiet" /> <!-- Specifies the amount of detail displayed in the output: normal, quiet, detailed -->
</exec>

<exec program="${nuget.executable}" if="${file::exists(nuget.executable)}">
<arg value="install"/>
<arg value="EWSoftware.SHFB" />
<arg value="-Version" />
<arg value="2019.11.17" />
<arg value="-OutputDirectory"/>
<arg value="${tools.dir}"/>
<arg value="-verbosity" />
<arg value="quiet" /> <!-- Specifies the amount of detail displayed in the output: normal, quiet, detailed -->
</exec>

<!-- Restore NuGet packages for project -->
<if test="${not file::exists(nuget.executable)}">
<echo level="Warning" message="NuGet installation not found." />
</if>
Expand Down Expand Up @@ -112,7 +142,7 @@
<attribute type="AssemblyTrademarkAttribute" value="${assembly.trademark}" />
<attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
<attribute type="AssemblyFileVersionAttribute" value="${assembly.fileversion}" />
<attribute type="AssemblyInformationalVersionAttribute" value="${assembly.informalversion}" />
<attribute type="AssemblyInformationalVersionAttribute" value="${assembly.informalversion}" />
</attributes>
</asminfo>
</target>
Expand All @@ -124,22 +154,42 @@
<echo message="Source Directory: ${src.dir}" />
<echo message="Build Directory: ${build.dir}" />

<msbuild projectFile="${path::combine(src.dir, build.project)}" targets="${build.target}" verbosity="Minimal">
<arg value="/p:TargetFrameworkVersion=${build.target.framework};Configuration=${build.configuration}"/>
<!-- build for Linux - msbuild task still uses xbuild that was deprecated starting with mono 5.0 -->
<exec program="mono" if="${platform::is-unix()}">
<arg value="${linux::get-msbuild-path()}" />
<arg value="${path::combine(src.dir, build.project)}" />
<arg value="/t:Clean;Build" />
<arg value="/p:TargetFrameworkVersion=${build.target.framework};Configuration=${build.configuration}"/>
<!-- Ignore error CS0619: 'TestFixtureAttribute' is obsolete: 'The NUnit framework shipped with Mono is deprecated and will be removed in a future release' -->
<arg value="/p:WarningsNotAsErrors=619" />
<!-- Sandcastle help file required parameters -->
<arg value="/p:SHFBROOT=${shfb.path}" />
<!-- This is a hack until CCTrayLib uses plugins for Windows only stuff -->
<arg value="/p:DISABLE_COM=${platform::is-unix()}" />
<!-- Microsoft.JScript was deprecated and removed in mono in 2010 -->
<!-- https://github.com/mono/mono/commit/2d66a50bc6df7497e1426d693395906d31f0e490 -->
<arg value="/p:DISABLE_JSCRIPT=${framework::get-family(nant.settings.currentframework) == 'mono'}" />
<!-- Hack for current xbuild issues on Mono 2.5 -->
<arg value="/p:MONO_IOMAP=all" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
<arg value="/p:MONO_PATH=${path::get-full-path('lib')}" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</exec>

<!-- This is a hack until CCTrayLib uses plugins for Windows only stuff -->
<property name="DISABLE_COM" value="${platform::is-unix()}" />
<!-- build for Windows -->
<msbuild projectFile="${path::combine(src.dir, build.project)}" targets="${build.target}" if="${not platform::is-unix()}" verbosity="Minimal">
<arg value="/p:TargetFrameworkVersion=${build.target.framework};Configuration=${build.configuration}"/>
<!-- Sandcastle help file required parameters -->
<arg value="/p:SHFBROOT=${shfb.path}" />

<!-- Microsoft.JScript was deprecated and removed in mono in 2010 -->
<!-- https://github.com/mono/mono/commit/2d66a50bc6df7497e1426d693395906d31f0e490 -->
<property name="DISABLE_JSCRIPT" value="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
<!-- Microsoft.JScript was deprecated and removed in mono in 2010 -->
<!-- https://github.com/mono/mono/commit/2d66a50bc6df7497e1426d693395906d31f0e490 -->
<property name="DISABLE_JSCRIPT" value="${framework::get-family(nant.settings.currentframework) == 'mono'}" />

<!-- Hack for current xbuild issues on Mono 2.5 -->
<!-- Hack for current xbuild issues on Mono 2.5 -->
<environment>
<variable name="MONO_IOMAP" value="all" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
<variable name="MONO_PATH" value="${path::get-full-path('lib')}" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</environment>
</msbuild>
</msbuild>

<!-- copy ccnet.config into the server dictionary -->
<copy file="${path::combine( path::combine(src.dir, 'service'), 'ccnet.config')}" tofile="${path::combine( path::combine(build.dir, 'Server'), 'ccnet.config')}" verbose="${nant.verbosity}"/>
Expand Down Expand Up @@ -208,13 +258,13 @@
<copy file="${path::combine( path::combine(src.dir, 'UnitTests'), 'test.config')}" tofile="${path::combine( path::combine(build.dir, 'UnitTests'), 'ThoughtWorks.CruiseControl.UnitTests.dll.config')}" verbose="${nant.verbosity}" />
</if>

<!--
<!--
<nunitTest executable="${nunit.executable}" workingDirectory="${path::combine(build.dir, 'UnitTests')}" outputFile="${path::combine(build.metrics.dir, 'nunit-result.xml')}" commandLineParameterFlag="-" showLabels="true" verbose="${nant.verbosity}">
<assemblies>
<include name="${path::combine( path::combine(build.dir, 'UnitTests'), 'ThoughtWorks.CruiseControl.UnitTests.dll')}" />
</assemblies>
<environment>
<variable name="MONO_PATH" value="${path::get-full-path('lib')}" if="${framework::get-family(nant.settings.currentframework) == 'mono'}" />
</environment>
Expand All @@ -226,9 +276,9 @@
<arg value="/exclude=Integration" />
<arg value="/framework:v4.0" />
</exec>



</target>

<!-- Code analyze metric targets -->
Expand All @@ -247,13 +297,13 @@
</if>

<!-- Run FxCop -->
<!--
<!--
commented because of upgrade to .Net 4.5
fxcop is part of visual studio, and not sure if distributing that included version is legal
maybe a better way is to use fxcop cmd id the exe is found on machine
<call target="runFxCop" cascade="false" />
-->

</if>
</target>

Expand Down
Loading

0 comments on commit bae4730

Please sign in to comment.