Commit efa2e958 authored by Mark Winter's avatar Mark Winter

Moved git version builder, dependency walking and compiler helper to utilities repository.

parent 36b76fce
......@@ -25,37 +25,15 @@
function CompileLEVer(forceVersion)
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');
if ( status == 0 && (length(result) > 1) )
questionStr = sprintf('%s\n%s','There are uncommitted changes in your working directory','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
%% Build version information
if ( ~exist('forceVersion', 'var') )
Dev.MakeVersion();
else
Dev.MakeVersion(0, forceVersion);
if ( ~exist('forceVersion','var') )
forceVersion = '';
end
%% Build FrameSegmentor help information into an function for use in compiled LEVER
%% General compiler setup: Deals with version updates and pulls external dependencies
initStruct = Dev.InitCompiler('LEVER',forceVersion);
%% Build FrameSegmentor help information into a function for use in compiled LEVER
Dev.MakeSegHelp();
%% Setup visual studio for MEX compilation
......@@ -91,49 +69,19 @@ function CompileLEVer(forceVersion)
newOutput = compileEXE('MTC', vsStruct, bindir);
outputFiles = [outputFiles; {newOutput}];
%% Build a list of external and toolbox dependencies
[toolboxStruct externalStruct] = Dev.GetExternalDependencies();
if ( ~isempty(externalStruct.deps) )
fprintf('ERROR: Some local functions have external dependencies\n');
for i=1:length(externalStruct.deps)
fprintf('[%d] %s\n', i, externalStruct.deps{i});
for j=1:length(externalStruct.funcs{i})
if ( ~isempty(externalStruct.callers{i}{j}) )
for k=1:length(externalStruct.callers{i}{j})
localName = Dev.GetLocalName(externalStruct.callers{i}{j}{k});
fprintf(' %s calls: %s\n', localName, externalStruct.funcs{i}{j});
end
end
end
fprintf('------\n');
end
% error('External dependencies cannot be packaged in a MATLAB executable');
questionStr = sprintf('%s\n%s','Possible external dependencies were found in project, you should verify all these functions are local before continuing the build.','Are you sure you wish to continue?');
result = questdlg(questionStr,'External Dependency Warning','Continue','Cancel','Cancel');
if ( strcmpi(result,'Cancel') )
return;
end
end
%% Compile LEVER, Segmentor, and batch LEVER_SegAndTrackFolders.
% temporarily remove any startup scripts that would normally be run by matlabrc
enableStartupScripts(false);
addImgs = {'+UI\backFrame.png'; '+UI\forwardFrame.png'; '+UI\pause.png';'+UI\play.png';'+UI\stop.png'};
newOutput = compileMATLAB('LEVer', bindir, addImgs, toolboxStruct.deps);
newOutput = compileMATLAB('LEVer', bindir, addImgs, initStruct.toolboxList);
outputFiles = [outputFiles; {newOutput}];
newOutput = compileMATLAB('LEVER_SegAndTrackFolders', bindir, {}, toolboxStruct.deps);
newOutput = compileMATLAB('LEVER_SegAndTrackFolders', bindir, {}, initStruct.toolboxList);
outputFiles = [outputFiles; {newOutput}];
newOutput = compileMATLAB('Segmentor', bindir, {}, toolboxStruct.deps);
newOutput = compileMATLAB('Segmentor', bindir, {}, initStruct.toolboxList);
outputFiles = [outputFiles; {newOutput}];
enableStartupScripts(true);
fprintf('\n');
% mcrfile = mcrinstaller();
......@@ -142,8 +90,8 @@ function CompileLEVer(forceVersion)
bIsEXE = cellfun(@(x)(~isempty(x)), strfind(lower(outputFiles), '.exe'));
exeOutputs = outputFiles(bIsEXE);
verSuffix = Helper.GetVersion('file');
zip(fullfile(bindir,['LEVer' verSuffix '.zip']), [exeOutputs; {'*.bat'}], bindir);
% verSuffix = Dev.GetVersion('file');
% zip(fullfile(bindir,['LEVer' verSuffix '.zip']), [exeOutputs; {'*.bat'}], bindir);
toc(totalTime)
end
......@@ -213,8 +161,8 @@ function outputFile = compileMATLAB(projectName, bindir, extrasList, toolboxList
end
extrasList = vertcat({'LEVER_logo.tif';
'+Segmentation\FrameSegmentor_*.m';
'+Helper\GetVersion.m';
'+Helper\VersionInfo.m'}, extrasList);
'+Dev\GetVersion.m';
'+Dev\VersionInfo.m'}, extrasList);
extraCommand = '';
if ( ~isempty(extrasList) )
......@@ -227,10 +175,10 @@ function outputFile = compileMATLAB(projectName, bindir, extrasList, toolboxList
end
toolboxAddCommand = '';
% if ( ~isempty(toolboxList) )
% toolboxElems = cellfun(@(x)([' -p "' x '"']), toolboxList, 'UniformOutput',0);
% toolboxAddCommand = ['-N' toolboxElems{:}];
% end
if ( ~isempty(toolboxList) )
toolboxElems = cellfun(@(x)([' -p "' x '"']), toolboxList, 'UniformOutput',0);
toolboxAddCommand = ['-N' toolboxElems{:}];
end
fprintf('\nMATLAB Compiling: %s...\n', outputFile);
result = system(['mcc -v -R -startmsg -m ' projectName '.m ' toolboxAddCommand extraCommand]);
......@@ -242,45 +190,3 @@ function outputFile = compileMATLAB(projectName, bindir, extrasList, toolboxList
fprintf('Done (%f sec)\n', toc(compileTime));
end
function enableStartupScripts(bEnable)
searchPrefix = '';
renamePrefix = 'disabled_';
if ( bEnable )
searchPrefix = 'disabled_';
renamePrefix = '';
end
searchName = [searchPrefix 'startup.m'];
newName = [renamePrefix 'startup.m'];
startupScripts = findFilesInPath(searchName, userpath);
for i=1:length(startupScripts)
scriptPath = fileparts(startupScripts{i});
movefile(startupScripts{i}, fullfile(scriptPath,newName));
end
end
function fullNames = findFilesInPath(filename, searchPaths)
fullNames = {};
chkPaths = [];
while ( ~isempty(searchPaths) )
[newPath remainder] = strtok(searchPaths, pathsep);
if ( isempty(newPath) )
searchPaths = remainder;
continue;
end
chkPaths = [chkPaths; {newPath}];
searchPaths = remainder;
end
for i=1:length(chkPaths)
chkFullPath = fullfile(chkPaths{i}, filename);
if ( exist(chkFullPath, 'file') )
fullNames = [fullNames; {chkFullPath}];
end
end
end
function verInfo = MakeVersion(bTransientUpdate, forceVersion)
funcString = {
'%% versionInfo = VersionInfo()'
'%% Return the version info structure'
'%%'
'%% Note: This file is autogenerated by build script DO NOT MODIFY!!'
''
'function versionInfo = VersionInfo()'
' versionInfo = struct(...'
' ''majorVersion'',{%d},...'
' ''minorVersion'',{%d},...'
' ''branchName'',{''%s''},...'
' ''buildNumber'',{''%s''},...'
' ''buildMachine'',{''%s''},...'
' ''commitHash'',{''%s''});'
' end'};
if ( ~exist('bTransientUpdate', 'var') )
bTransientUpdate = 0;
end
if ( ~exist('forceVersion', 'var') )
forceVersion = [];
end
verInfo = struct(...
'majorVersion',{0},...
'minorVersion',{0},...
'branchName',{'UNKNOWN'},...
'buildNumber',{'UNKNOWN'},...
'buildMachine',{'UNKNOWN'},...
'commitHash',{''});
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);
if ( ~isempty(forceVersion) && ischar(forceVersion) )
verTag = ['v' forceVersion];
end
% Get version info from git tag
if ( ~isempty(verTag) )
verTag = strtrim(verTag);
numTok = regexp(verTag, '[Vv](\d+)\.(\d+(?:\.\d+)?).*', 'tokens', 'once');
if ( length(numTok) >= 2 )
verInfo.majorVersion = str2double(numTok{1});
verInfo.minorVersion = str2double(numTok{2});
end
end
% Increment version if we're getting it from tag/fallback
if ( isempty(forceVersion) )
verInfo.minorVersion = verInfo.minorVersion + 1;
end
% Try to get a branch name
[status,branchName] = system('git rev-parse --abbrev-ref HEAD');
if ( ~isempty(branchName) )
verInfo.branchName = strtrim(branchName);
end
[status commitHash] = system('git rev-parse HEAD');
if ( ~isempty(commitHash) )
verInfo.commitHash = strtrim(commitHash);
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 )
fprintf('WARNING: There was an error retrieving hostname:\n %s\n', buildMachine);
else
verInfo.buildMachine = strtrim(buildMachine);
end
if ( ~bTransientUpdate )
if ( ~bFoundGit )
error('Unable to use git to build version string for build.');
end
% Concatenate the template function lines into one giant string
templateString = [];
for i=1:length(funcString)
templateString = [templateString funcString{i} '\n'];
end
% Now insert all our arguments into the template and write to a file.
fid = fopen('+Helper\VersionInfo.m', 'wt');
if ( fid <= 0 )
error('Unable to open +Helper\VersionInfo.m for writing');
end
fprintf(fid, templateString, verInfo.majorVersion, verInfo.minorVersion, verInfo.branchName, verInfo.buildNumber, verInfo.buildMachine, verInfo.commitHash);
fclose(fid);
% Update fallback file if we used git to retrieve version info.
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 commitHash] = gitVersionAndBranch(bUseGit, fallbackFile)
verTag = '';
branchName = '';
commitHash = '';
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');
[hashStatus,commitHash] = system('git rev-parse 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
if ( hashStatus ~= 0 )
fprintf('WARNING: There was an error retrieving commit hash from git:\n %s\n', commitHash);
commitHash = '';
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);
commitHash = 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
% version = GetVersion(command)
% Get a version string or number depending on the command argument. This
% m-file serves as a single repository for all version-related information.
%
% Note: Uses autogenerated version information in +Helper\VersionInfo.m
function version = GetVersion(command)
version = [];
if ( isdeployed )
verInfo = Helper.VersionInfo();
else
verInfo = Dev.MakeVersion(1);
end
if ( ~exist('command','var') )
command = 'string';
end
cleanBranch = strrep(verInfo.branchName, '/', '_');
cleanBranch = strrep(cleanBranch, '\', '_');
if ( strcmpi(command, 'string') || strcmpi(command, 'versionString') )
version = [num2str(verInfo.majorVersion) '.' num2str(verInfo.minorVersion) ' ' cleanBranch];
return;
end
if ( strcmpi(command, 'buildString') )
version = [verInfo.buildNumber '/' verInfo.buildMachine];
return;
end
if ( strcmpi(command, 'buildHash') )
version = verInfo.commitHash;
return
end
if ( strcmpi(command, 'fullString') )
version = ['LEVER v' num2str(verInfo.majorVersion) '.' num2str(verInfo.minorVersion) ' ' verInfo.buildNumber '/' verInfo.buildMachine ' ' cleanBranch ' ' verInfo.commitHash];
return;
end
if ( strcmpi(command, 'major') )
version = verInfo.majorVersion;
return
end
if ( strcmpi(command, 'minor') )
version = verInfo.minorVersion;
return;
end
if ( strcmpi(command, 'file') )
minorStr = num2str(verInfo.minorVersion);
minorStr = strrep(minorStr, '.', '_');
version = [num2str(verInfo.majorVersion) minorStr '_' cleanBranch];
return;
end
end
......@@ -31,9 +31,9 @@
function opened = OpenData()
global Figures Colors CONSTANTS
softwareVersion = Helper.GetVersion();
softwareVersion = Dev.GetVersion();
if(isempty(Figures))
fprintf('LEVer ver %s\n***DO NOT DISTRIBUTE***\n\n', softwareVersion);
fprintf('%s\n***DO NOT DISTRIBUTE***\n\n', softwareVersion);
end
if(exist('ColorScheme.mat','file'))
......
......@@ -748,7 +748,7 @@ function urlStr = urlifyString(inStr)
end
function createBugReport(src,evnt)
verString = Helper.GetVersion('fullstring');
verString = Dev.GetVersion('fullstring');
% issueLabels = 'bug';
% issueTitle = '<ISSUE TITLE>';
......
......@@ -189,7 +189,7 @@ if(strcmp(get(Figures.cells.menuHandles.labelsMenu, 'Checked'),'on'))
'uicontextmenu', Figures.cells.contextMenuHandle,...
'ButtonDownFcn',( @(src,evt) (UI.FigureCellDown(src,evt,curHullID))),...
'LineStyle', colorStruct.edgeStyle,...
'LineWidth', colorStruct.edgeWidth);
'LineWidth', 2);
% Plot light-blue border if frozen track
if ( Helper.CheckTreeFrozen(curTrackID) )
......
......@@ -64,9 +64,9 @@ else
im=255*ones(339,608);
end
imagesc(im)
softwareVersion = Helper.GetVersion();
buildNumber = Helper.GetVersion('buildString');
buildHash = Helper.GetVersion('buildHash');
softwareVersion = Dev.GetVersion();
buildNumber = Dev.GetVersion('buildString');
buildHash = Dev.GetVersion('primaryHash');
cDate = clock();
if ( ~isempty(softwareVersion) )
set(handles.text1,'string',{['LEVER: ' softwareVersion] ; [' ' buildNumber ' '] ;[' ' buildHash(1:20) ' '] ; ['(c) ' num2str(cDate(1))] });
......
......@@ -11,7 +11,7 @@ global CONSTANTS CellPhenotypes
CONSTANTS=[];
softwareVersion = Helper.GetVersion();
softwareVersion = Dev.GetVersion();
if (isdeployed())
Load.SetWorkingDir();
......
{
"name" : "LEVER",
"majorVersion" : 7,
"minorVersion" : 14,
"branchName" : "master",
"buildNumber" : "2016.04.15.15",
"buildMachine" : "bioimage28",
"commitHash" : [
"lever.git : aecf2c8b72f7eea759eee95cfdbd0533837640ac",
"utilities.git : 25510aa37d6fde65c3ff7e0ad2d605a227123aba"
]
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment