forked from popcornmix/omxplayer
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgen_version.pl
executable file
·99 lines (81 loc) · 2.02 KB
/
gen_version.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl
#
# Author:
# Michael J. Walsh
# based on the original by Sergio Conde <skgsergio@gmail.com>
#
# License:
# This script is part of omxplayer and it should be
# distributed under the same license.
#
use strict;
use warnings;
my $date = run("date -R");
my $hash = "UNKNOWN";
my $branch = "UNKNOWN";
my $repo = "UNKNOWN";
sub main {
my $ref = run("git symbolic-ref -q HEAD");
$hash = run("git rev-parse --short $ref");
$branch = $ref;
$branch =~ s|^refs/heads/||;
my $upstream = run("git for-each-ref --format='%(upstream:short)' $ref");
if($upstream ne "") {
my $short_repo = $upstream;
$short_repo =~ s|/$branch$||;
$repo = run("git config remote.$short_repo.url");
}
if(no_change()) {
# no need to update version_info.h
exit 0;
} else {
generate_version_info_header();
# if there are command line args execute then as a command
if(@ARGV > 0) {
compile_version_object();
exit 1;
} else {
exit 0;
}
}
}
main();
sub generate_version_info_header {
open(my $w, '>', 'version_info.h') || exit 1;
print $w <<"OUT";
#ifndef __VERSION_H__
#define __VERSION_H__
#define VERSION_DATE "$date"
#define VERSION_HASH "$hash"
#define VERSION_BRANCH "$branch"
#define VERSION_REPO "$repo"
#endif
OUT
;
}
sub compile_version_object {
# compile a new version.o since the version has changed
print join(" ", @ARGV) , "\n";
exec @ARGV;
}
sub run {
my $o = readpipe($_[0] . " 2> /dev/null");
die "command failed: $_[0]" if $? != 0;
chomp $o;
return $o;
}
sub no_change {
open(my $r, '<', 'version_info.h') || return 0;
my $content = join '', <$r>;
close $r;
if($content =~ m/VERSION_HASH "([^"]+)"/) {
return 0 if $1 ne $hash;
}
if($content =~ m/VERSION_BRANCH "([^"]+)"/) {
return 0 if $1 ne $branch;
}
if($content =~ m/VERSION_REPO "([^"]+)"/) {
return 0 if $1 ne $repo;
}
return 1;
}