Don't use perl for portability
This amends commit f8be71ac6d
.
This still should resolve FS-4303.
What's going on here is that we need a portable way to access
strftime. date(1posix) doesn't provide enough. And without perl, I
can't think of a better way to get to it than just using C. So the
logic for generating the extended revision has been moved into a small
self-contained and hopefully portable C program.
This commit is contained in:
parent
9bd1c33115
commit
2c634751cc
|
@ -99,6 +99,7 @@ TAGS
|
||||||
/build/Makefile
|
/build/Makefile
|
||||||
/build/Makefile.in
|
/build/Makefile.in
|
||||||
/build/modmake.rules
|
/build/modmake.rules
|
||||||
|
/build/print_git_revision
|
||||||
|
|
||||||
/libs/curl/lib/ca-bundle.h
|
/libs/curl/lib/ca-bundle.h
|
||||||
/libs/esl/fs_cli
|
/libs/esl/fs_cli
|
||||||
|
|
14
Makefile.am
14
Makefile.am
|
@ -415,16 +415,14 @@ $(OUR_MODULES): $(switch_builddir)/modules.conf libfreeswitch.la
|
||||||
$(switch_builddir)/quiet_libtool: $(switch_builddir)/libtool
|
$(switch_builddir)/quiet_libtool: $(switch_builddir)/libtool
|
||||||
@cat libtool | sed -e 's|$$show "$$command"|if test -z "$$suppress_output" ; then $$show "Compiling $$srcfile ..." ; fi|' > $(switch_builddir)/quiet_libtool
|
@cat libtool | sed -e 's|$$show "$$command"|if test -z "$$suppress_output" ; then $$show "Compiling $$srcfile ..." ; fi|' > $(switch_builddir)/quiet_libtool
|
||||||
|
|
||||||
src/include/switch_version.h: src/include/switch_version.h.in Makefile $(libfreeswitch_la_SOURCES) $(library_include_HEADERS)
|
build/print_git_revision: build/print_git_revision.c
|
||||||
|
$(CC) -o $@ $<
|
||||||
|
|
||||||
|
src/include/switch_version.h: src/include/switch_version.h.in Makefile build/print_git_revision $(libfreeswitch_la_SOURCES) $(library_include_HEADERS)
|
||||||
@cat $< > $@; \
|
@cat $< > $@; \
|
||||||
if [ -d .git ]; then \
|
if [ -d .git ]; then \
|
||||||
xdate="$$(perl -e 'use POSIX; print strftime("%Y%m%dT%H%M%SZ",gmtime($$ARGV[0]))' "$$(git log -n1 --format='%ct' HEAD)")"; \
|
xver="$$(./build/print_git_revision)"; \
|
||||||
xcommit="$$(git rev-list -n1 --abbrev=10 --abbrev-commit HEAD)"; \
|
sed -e "/#define *SWITCH_VERSION_REVISION/{s/\"\([^\"]*\)\"/\"\1$$xver\"/}" \
|
||||||
xver="+git~$$xdate~$$xcommit"; \
|
|
||||||
if ! git diff-index --quiet HEAD; then \
|
|
||||||
xver="$$xver+unclean~$$(date -u +%Y%m%dT%H%M%SZ)"; \
|
|
||||||
fi; \
|
|
||||||
perl -ple "if (/#define *SWITCH_VERSION_REVISION/) {s/\"(.*)\"/\"\1$$xver\"/}" \
|
|
||||||
$< > $@; \
|
$< > $@; \
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/* -*- mode:c; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||||
|
* Author: Travis Cross <tc@traviscross.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int sys(char *buf, int buflen, char *cmd) {
|
||||||
|
int i, p[2];
|
||||||
|
pipe(p);
|
||||||
|
if (!(i=fork())) {
|
||||||
|
close(p[0]);
|
||||||
|
dup2(p[1],1);
|
||||||
|
close(p[1]);
|
||||||
|
execlp("sh","sh","-c",cmd,NULL);
|
||||||
|
} else {
|
||||||
|
int s, x, c=0;
|
||||||
|
close(p[1]);
|
||||||
|
waitpid(i,&s,0);
|
||||||
|
if (!(WIFEXITED(s))) return 255;
|
||||||
|
if (WEXITSTATUS(s)) return WEXITSTATUS(s);
|
||||||
|
while ((x=read(p[0],buf,buflen-1))>0) c+=x;
|
||||||
|
if (x<0) return 1;
|
||||||
|
buf[c] = 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sys1(char *buf, int buflen, char *cmd) {
|
||||||
|
int r = sys(buf,buflen,cmd);
|
||||||
|
char *c;
|
||||||
|
if (r!=0) return r;
|
||||||
|
if ((c=strstr(buf,"\n"))) *c=0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
char buf[256], xdate[256], xfdate[256], xcommit[256], xver[256];
|
||||||
|
time_t xdate_t;
|
||||||
|
struct tm *xdate_tm;
|
||||||
|
|
||||||
|
sys1(xdate,sizeof(xdate),"git log -n1 --format='%ct' HEAD");
|
||||||
|
xdate_t = (time_t) atoi(xdate);
|
||||||
|
if (!(xdate_tm = gmtime(&xdate_t))) return 1;
|
||||||
|
strftime(xfdate,sizeof(xfdate),"%Y%m%dT%H%M%SZ",xdate_tm);
|
||||||
|
sys1(xcommit,sizeof(xcommit),"git rev-list -n1 --abbrev=10 --abbrev-commit HEAD");
|
||||||
|
snprintf(xver,sizeof(xver),"+git~%s~%s",xfdate,xcommit);
|
||||||
|
if ((sys(buf,sizeof(buf),"git diff-index --quiet HEAD"))) {
|
||||||
|
time_t now_t = time(NULL);
|
||||||
|
struct tm *now_tm = gmtime(&now_t);
|
||||||
|
char now[256];
|
||||||
|
if (!now_tm) return 1;
|
||||||
|
strftime(now,sizeof(now),"%Y%m%dT%H%M%SZ",now_tm);
|
||||||
|
snprintf(buf,sizeof(buf),"%s+unclean~%s",xver,now);
|
||||||
|
strncpy(xver,buf,sizeof(xver));
|
||||||
|
}
|
||||||
|
printf("%s\n",xver);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue