Skip to content
Snippets Groups Projects
Commit fc346373 authored by Mark Winter's avatar Mark Winter
Browse files

Made the versioning more robust, falls back to a file if git unavailable and tries to find git dir.

parent 93eff1d6
Branches
Tags
No related merge requests found
......@@ -25,6 +25,17 @@
totalTime = tic();
% Try to set up git for the build, give a warning about checking the
% fallback file if we can't find git.
bFoundGit = Dev.SetupGit();
if ( ~bFoundGit )
questionStr = sprintf('%s\n%s','Cannot find git you should verify the fallback file version info before building.','Are you sure you wish to continue with the build?');
result = questdlg(questionStr,'Build Warning','Yes','No','No');
if ( strcmpi(result,'No') )
return;
end
end
% Give a messagebox warning if there are uncommitted changes.
% Note: even committed changes may not have been pushed to server.
[status,result] = system('git status --porcelain');
......@@ -36,13 +47,13 @@ if ( status == 0 && (length(result) > 1) )
end
end
Dev.MakeVersion();
vstoolroot = getenv('VS100COMNTOOLS');
if ( isempty(vstoolroot) )
error('Cannot compile MTC and mexMAT without Visual Studio 2010');
end
Dev.MakeVersion();
comparch = computer('arch');
if ( strcmpi(comparch,'win64') )
buildbits = '64';
......
......@@ -28,11 +28,18 @@ function verInfo = MakeVersion(bTransientUpdate)
'buildNumber',{'UNKNOWN'},...
'buildMachine',{'UNKNOWN'});
fallbackFile = 'version.txt';
bFoundGit = Dev.SetupGit();
if ( ~bFoundGit )
fprintf('WARNING: Could not find git directory, falling back to %s\n', fallbackFile);
end
[verTag branchName] = gitVersionAndBranch(bFoundGit, fallbackFile);
% Get version info from git tag
[status,verTag] = system('git describe --tags --match v[0-9]*.[0-9]* --abbrev=0');
if ( status ~= 0 )
fprintf('WARNING: There was an error retrieving current version information:\n %s\n', verTag);
else
if ( ~isempty(verTag) )
verTag = strtrim(verTag);
numTok = regexp(verTag, '[Vv]([0-9]+)[.]([0-9]+).*', 'tokens', 'once');
if ( length(numTok) >= 2 )
......@@ -43,18 +50,16 @@ function verInfo = MakeVersion(bTransientUpdate)
end
end
% Get a timestamp build-number
c = clock();
verInfo.buildNumber = sprintf('%d.%02d.%02d.%02d', c(1), c(2), c(3), c(4));
% Try to get a branch name
[status,branchName] = system('git rev-parse --abbrev-ref HEAD');
if ( status ~= 0 )
fprintf('WARNING: There was an error retrieving current branch information:\n %s\n', branchName);
else
if ( ~isempty(branchName) )
verInfo.branchName = strtrim(branchName);
end
% Get a timestamp build-number
c = clock();
verInfo.buildNumber = sprintf('%d.%02d.%02d.%02d', c(1), c(2), c(3), c(4));
% Get machine ID
[status,buildMachine] = system('hostname');
if ( status ~= 0 )
......@@ -80,4 +85,55 @@ function verInfo = MakeVersion(bTransientUpdate)
fclose(fid);
end
% Update fallback file if we used git to retrieve version info.
if ( bFoundGit )
fid = fopen(fallbackFile, 'wt');
if ( fid < 0 )
return;
end
fprintf(fid, '%s\n', verTag);
fprintf(fid, '%s\n', branchName);
fclose(fid);
end
end
function [verTag branchName] = gitVersionAndBranch(bUseGit, fallbackFile)
verTag = '';
branchName = '';
if ( bUseGit )
[verStatus,verTag] = system('git describe --tags --match v[0-9]*.[0-9]* --abbrev=0');
[branchStatus,branchName] = system('git rev-parse --abbrev-ref HEAD');
if ( verStatus ~= 0 )
fprintf('WARNING: There was an error retrieving tag from git:\n %s\n', verTag);
verTag = '';
end
if ( branchStatus ~= 0 )
fprintf('WARNING: There was an error retrieving branch name from git:\n %s\n', branchName);
branchName = '';
end
return;
end
if ( ~exist(fallbackFile, 'file') )
fprintf('ERROR: There is no fallback version.txt file!\n');
return;
end
fid = fopen(fallbackFile, 'rt');
if ( fid < 0 )
return;
end
verTag = fgetl(fid);
branchName = fgetl(fid);
fclose(fid);
end
function bFoundGit = SetupGit()
bFoundGit = 0;
[bGitError gitVer] = system('git version');
if ( ~bGitError )
bFoundGit = 1;
return;
end
gitPath = findGitPath();
if ( isempty(gitPath) )
return;
end
pathEnv = getenv('PATH');
idx = strfind(pathEnv,gitPath);
if ( isempty(idx) )
pathEnv = [gitPath pathsep pathEnv];
setenv('PATH', pathEnv);
end
[bGitError gitVer] = system('git version');
if ( ~bGitError )
bFoundGit = 1;
return;
end
end
function gitPath = findGitPath()
gitPath = '';
comparch = computer('arch');
progFilesPath = 'C:\Program Files (x86)';
if ( strcmpi(comparch,'win64') )
progFilesPath = getenv('ProgramFiles(x86)');
elseif ( strcmpi(comparch,'win32') )
progFilesPath = getenv('ProgramFiles');
else
return;
end
tryPaths = {fullfile(progFilesPath, 'Git');
fullfile(progFilesPath, 'msysgit');
'C:\Git';
'C:\msysgit'};
trySubdir = {'bin';'cmd'};
foundPath = '';
for i=1:length(tryPaths)
if ( exist(tryPaths{i}, 'dir') )
foundPath = tryPaths{i};
break;
end
end
if ( isempty(foundPath) )
return;
end
for i=1:length(trySubdir)
if ( exist(fullfile(foundPath,trySubdir{i},'git.exe'),'file') || exist(fullfile(foundPath,trySubdir{i},'git.cmd'),'file') )
gitPath = fullfile(foundPath,trySubdir{i});
return;
end
end
end
v7.1_MultiCell
MultiCellTypes
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment