|
1 | 1 | %% MATLAB_GIT_VERSION version of the Git2 library used by Matlab |
2 | | -% general example of access shared library version info from Matlab |
3 | | -% using loadlibrary() to call a function in a shared library without a MEX file. |
| 2 | +% version('-modules') doesn't reveal the version of Git2, so this function uses |
| 3 | +% loadlibrary() to call a function in the Git2 library without a MEX file. |
4 | 4 | % |
5 | 5 | % Input: |
6 | 6 | % libPath - Full path to the library (optional) |
|
10 | 10 |
|
11 | 11 | function v = matlab_git_version(libPath) |
12 | 12 | arguments |
13 | | - libPath {mustBeTextScalar, mustBeFile} = getMatlabGit2libPath() |
| 13 | + libPath {mustBeTextScalar} = getMatlabGit2libPath() |
14 | 14 | end |
15 | 15 |
|
16 | | -if ispc() |
17 | | - % Windows .NET |
18 | | - fileInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(libPath); |
19 | | - v = char(fileInfo.FileVersion); |
20 | | -else |
21 | | -% elseif ismac() |
22 | | -% cmd = ['otool -L "' char(libPath) '"']; |
23 | | -% pat = '(?<=current version\s+)[0-9][0-9.]+'; |
24 | | -% v = shell_regex(cmd, pat); |
| 16 | +v = library_version(libPath, fullfile(fileparts(mfilename("fullpath")), 'private/git2dummy.h'), 'git2'); |
25 | 17 |
|
26 | | - cwd = fileparts(mfilename("fullpath")); |
27 | | - hdr = fullfile(cwd, 'private/git2dummy.h'); |
28 | | - |
29 | | - if ~libisloaded('git2') |
30 | | - if isfile(libPath) |
31 | | - loadlibrary(libPath, hdr, alias='git2'); |
32 | | - else |
33 | | - v = missing; |
34 | | - return |
35 | | - end |
36 | | - end |
37 | | - |
38 | | - maj = libpointer('int32Ptr', 0); |
39 | | - min = libpointer('int32Ptr', 0); |
40 | | - rev = libpointer('int32Ptr', 0); |
41 | | - |
42 | | - calllib('git2', 'git_libgit2_version', maj, min, rev); |
43 | | - v = sprintf('%d.%d.%d', maj.Value, min.Value, rev.Value); |
44 | 18 | end |
45 | 19 |
|
46 | | - |
47 | | -end |
48 | | - |
49 | | -% function v = shell_regex(cmd, pat) |
50 | | -% [status, o] = system(cmd); |
51 | | -% assert(status == 0, 'Failed to get library version from %s\nOutput: %s', cmd, o); |
52 | | -% |
53 | | -% v = regexp(o, pat, 'match', 'once'); |
54 | | -% if iscell(v) |
55 | | -% v = v{1}; |
56 | | -% end |
57 | | -% v = char(strtrim(v)); |
58 | | -% end |
59 | | - |
60 | | - |
61 | 20 | function p = getMatlabGit2libPath() |
62 | 21 | archDir = fullfile(matlabroot, 'bin', computer('arch')); |
63 | 22 |
|
|
0 commit comments