2018-07-27 11:56:46 -04:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2020-12-22 11:50:27 -05:00
|
|
|
<Project DefaultTargets="Build" InitialTargets="GitVersion" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
|
|
<PropertyGroup>
|
|
|
|
<GitSkipCache>true</GitSkipCache>
|
|
|
|
</PropertyGroup>
|
2018-07-27 11:56:46 -04:00
|
|
|
<ImportGroup Label="PropertySheets">
|
|
|
|
<Import Project="basedir.props" Condition=" '$(BaseDirImported)' == ''"/>
|
2020-12-22 11:50:27 -05:00
|
|
|
<Import Project="Setup\GitInfo\GitInfo.targets" />
|
2018-07-27 11:56:46 -04:00
|
|
|
</ImportGroup>
|
|
|
|
|
|
|
|
<PropertyGroup>
|
|
|
|
<switch_versionPropsImported>true</switch_versionPropsImported>
|
|
|
|
</PropertyGroup>
|
|
|
|
|
|
|
|
<UsingTask TaskName="SwitchVersionTask"
|
|
|
|
TaskFactory="CodeTaskFactory"
|
|
|
|
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
|
2020-12-22 11:50:27 -05:00
|
|
|
<ParameterGroup>
|
|
|
|
<commits Required="true" />
|
|
|
|
<revision Required="true" />
|
|
|
|
</ParameterGroup>
|
2018-07-27 11:56:46 -04:00
|
|
|
<Task>
|
|
|
|
<Reference Include="Microsoft.Build" />
|
|
|
|
<Reference Include="Microsoft.Build.Framework" />
|
|
|
|
<Code Type="Class" Language="cs">
|
|
|
|
<![CDATA[
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using Microsoft.Build.Framework;
|
|
|
|
|
|
|
|
public class SwitchVersionTask : Microsoft.Build.Utilities.Task
|
|
|
|
{
|
2020-12-22 11:50:27 -05:00
|
|
|
[Required]
|
|
|
|
public string revision { get; set; }
|
|
|
|
public string commits { get; set; }
|
|
|
|
|
2018-07-27 11:56:46 -04:00
|
|
|
private string basedir;
|
|
|
|
private string TemplatePath;
|
|
|
|
private string DestinationPath;
|
|
|
|
|
|
|
|
public override bool Execute()
|
|
|
|
{
|
|
|
|
basedir = Path.GetFullPath(@"$(BaseDir)");
|
|
|
|
|
2020-12-22 11:50:27 -05:00
|
|
|
int commit_count = 0;
|
|
|
|
Int32.TryParse(commits, out commit_count);
|
|
|
|
|
2018-07-27 11:56:46 -04:00
|
|
|
Log.LogMessage(MessageImportance.High,
|
|
|
|
"Parsing FreeSWITCH version.");
|
|
|
|
|
|
|
|
string ConfigureAC = File.ReadAllText(@"$(BaseDir)configure.ac");
|
2019-07-16 14:23:38 -04:00
|
|
|
string pattern = @"AC_SUBST\((SWITCH_VERSION_[A-Z_]+),.*\[(.*)\]\)";
|
2018-07-27 11:56:46 -04:00
|
|
|
|
|
|
|
Dictionary<string, string> v = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
string year = DateTime.UtcNow.Year.ToString();
|
|
|
|
v.Add("SWITCH_VERSION_YEAR", year);
|
|
|
|
|
|
|
|
foreach (Match m in Regex.Matches(ConfigureAC, pattern)) {
|
2019-07-16 14:23:38 -04:00
|
|
|
string value = m.Groups[2].Value.Trim();
|
|
|
|
if (value.Contains("-")) {
|
|
|
|
string[] tokens = value.Split('-');
|
|
|
|
value = tokens[0];
|
|
|
|
}
|
2020-12-22 11:50:27 -05:00
|
|
|
var name = m.Groups[1].Value.Trim();
|
|
|
|
value = value.Trim();
|
|
|
|
|
|
|
|
if (name.StartsWith("SWITCH_VERSION_REVISION")) {
|
|
|
|
if (string.IsNullOrWhiteSpace(value)) {
|
|
|
|
value = revision;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name != "SWITCH_VERSION_REVISION_HUMAN") {
|
|
|
|
value = "~" + value;
|
|
|
|
|
|
|
|
if (commit_count > 0) {
|
|
|
|
value = "-dev-"+ commits + value;
|
|
|
|
} else {
|
|
|
|
value = "-release" + value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v.Add(name, value);
|
|
|
|
Log.LogMessage(MessageImportance.High, name + " = '" + value + "'");
|
2018-07-27 11:56:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
Log.LogMessage(MessageImportance.High,
|
|
|
|
"Generating switch_version.h");
|
|
|
|
|
|
|
|
TemplatePath = basedir + @"src\include\switch_version.h.template";
|
|
|
|
DestinationPath = basedir + @"src\include\switch_version.h";
|
|
|
|
|
|
|
|
string template = File.ReadAllText(TemplatePath);
|
|
|
|
foreach (var version_bit in v) {
|
|
|
|
template = template.Replace("@" + version_bit.Key + "@", version_bit.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
File.WriteAllText(DestinationPath, template);
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
Log.LogMessage(MessageImportance.High,
|
|
|
|
"Generating switch_version.inc");
|
|
|
|
|
|
|
|
TemplatePath = @"$(ProjectDir)\switch_version.inc.template";
|
|
|
|
DestinationPath = @"$(ProjectDir)\switch_version.inc";
|
|
|
|
|
|
|
|
template = File.ReadAllText(TemplatePath);
|
|
|
|
foreach (var version_bit in v) {
|
|
|
|
template = template.Replace("@" + version_bit.Key + "@", version_bit.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
File.WriteAllText(DestinationPath, template);
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]>
|
|
|
|
</Code>
|
|
|
|
</Task>
|
|
|
|
</UsingTask>
|
|
|
|
|
|
|
|
<Target Name="SwitchVersionTarget" BeforeTargets="CustomBuild;Build">
|
2020-12-22 11:50:27 -05:00
|
|
|
<SwitchVersionTask commits="$(GitCommits)" revision="$(GitCommit)">
|
2018-07-27 11:56:46 -04:00
|
|
|
</SwitchVersionTask>
|
|
|
|
</Target>
|
|
|
|
|
|
|
|
</Project>
|