aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2018-09-20 12:30:48 -0500
committertlatorre <tlatorre@uchicago.edu>2018-09-20 12:30:48 -0500
commit3e3b1fd21437a08554f59086cd201dfc48c3ffed (patch)
tree5415c9c9fbdbc375b18daeeae8d389430c431725 /src
parent92f48c17da6b8ce33a54d662a46b766ec1cc18c4 (diff)
downloadsddm-3e3b1fd21437a08554f59086cd201dfc48c3ffed.tar.gz
sddm-3e3b1fd21437a08554f59086cd201dfc48c3ffed.tar.bz2
sddm-3e3b1fd21437a08554f59086cd201dfc48c3ffed.zip
add git SHA1 hash to output file
Diffstat (limited to 'src')
-rw-r--r--src/Makefile4
-rw-r--r--src/fit.c62
-rwxr-xr-xsrc/mkreleasehdr.sh11
-rw-r--r--src/release.c44
4 files changed, 93 insertions, 28 deletions
diff --git a/src/Makefile b/src/Makefile
index e15b07d..377388c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,3 +1,5 @@
+release_hdr := $(shell sh -c './mkreleasehdr.sh')
+
CFLAGS=-O2 -Wall -g -DSWAP_BYTES
LDLIBS=-lm -lgsl -lgslcblas -lnlopt_cxx -lstdc++
@@ -24,7 +26,7 @@ test-charge: test-charge.o sno_charge.o misc.o vector.o
test-zebra: test-zebra.o zebra.o pack2b.o
-fit: fit.o zebra.o likelihood.o pmt.o vector.o misc.o muon.o optics.o quantum_efficiency.o solid_angle.o pdg.o scattering.o zdab_utils.o pack2b.o sno_charge.o db.o dqxx.o dict.o siphash.o path.o pmt_response.o
+fit: fit.o zebra.o likelihood.o pmt.o vector.o misc.o muon.o optics.o quantum_efficiency.o solid_angle.o pdg.o scattering.o zdab_utils.o pack2b.o sno_charge.o db.o dqxx.o dict.o siphash.o path.o pmt_response.o release.o
clean:
rm -f *.o calculate_limits test Makefile.dep
diff --git a/src/fit.c b/src/fit.c
index 56c58fd..328873c 100644
--- a/src/fit.c
+++ b/src/fit.c
@@ -20,6 +20,10 @@
#include "vector.h"
#include "pmt_response.h"
#include <signal.h> /* for signal() */
+#include "release.h"
+
+char *GitSHA1(void);
+char *GitDirty(void);
static int stop = 0;
static nlopt_opt opt;
@@ -5428,6 +5432,10 @@ int main(int argc, char **argv)
fprintf(stderr, "failed to open '%s': %s\n", output, strerror(errno));
return 1;
}
+
+ fprintf(fout, "git_sha1: %s\n", GitSHA1());
+ fprintf(fout, "git_dirty: %s\n", GitDirty());
+ fprintf(fout, "data:\n");
}
load_pmt_info();
@@ -5485,7 +5493,7 @@ int main(int argc, char **argv)
switch (b.name) {
case MAST_RECORD:
/* New event. */
- if (fout) fprintf(fout, "-\n");
+ if (fout) fprintf(fout, " -\n");
first_ev = 1;
first_mctk = 1;
first_mcvx = 1;
@@ -5494,11 +5502,11 @@ int main(int argc, char **argv)
/* New MC vertex. */
unpack_mcvx(b.data, &bmcvx);
if (fout) {
- if (first_mcvx) fprintf(fout, " mcvx:\n");
- fprintf(fout, " -\n");
- fprintf(fout, " posx: %.2f\n", bmcvx.x);
- fprintf(fout, " posy: %.2f\n", bmcvx.y);
- fprintf(fout, " posz: %.2f\n", bmcvx.z);
+ if (first_mcvx) fprintf(fout, " mcvx:\n");
+ fprintf(fout, " -\n");
+ fprintf(fout, " posx: %.2f\n", bmcvx.x);
+ fprintf(fout, " posy: %.2f\n", bmcvx.y);
+ fprintf(fout, " posz: %.2f\n", bmcvx.z);
}
first_mcvx = 0;
break;
@@ -5506,12 +5514,12 @@ int main(int argc, char **argv)
/* New MC track. */
unpack_mctk(b.data, &bmctk);
if (fout) {
- if (first_mctk) fprintf(fout, " mctk:\n");
- fprintf(fout, " -\n");
- fprintf(fout, " energy: %.2f\n", bmctk.ene);
- fprintf(fout, " dirx: %.4f\n", bmctk.drx);
- fprintf(fout, " diry: %.4f\n", bmctk.dry);
- fprintf(fout, " dirz: %.4f\n", bmctk.drz);
+ if (first_mctk) fprintf(fout, " mctk:\n");
+ fprintf(fout, " -\n");
+ fprintf(fout, " energy: %.2f\n", bmctk.ene);
+ fprintf(fout, " dirx: %.4f\n", bmctk.drx);
+ fprintf(fout, " diry: %.4f\n", bmctk.dry);
+ fprintf(fout, " dirz: %.4f\n", bmctk.drz);
}
first_mctk = 0;
break;
@@ -5534,21 +5542,21 @@ int main(int argc, char **argv)
long long elapsed = (tv_stop.tv_sec - tv_start.tv_sec)*1000 + (tv_stop.tv_usec - tv_start.tv_usec)/1000;
if (fout) {
- if (first_ev) fprintf(fout, " ev:\n");
- fprintf(fout, " - gtid: %i\n", ev.gtid);
- fprintf(fout, " fit:\n");
- fprintf(fout, " -\n");
- fprintf(fout, " energy: %.2f\n", xopt[0]);
- fprintf(fout, " posx: %.2f\n", xopt[1]);
- fprintf(fout, " posy: %.2f\n", xopt[2]);
- fprintf(fout, " posz: %.2f\n", xopt[3]);
- fprintf(fout, " theta: %.4f\n", xopt[4]);
- fprintf(fout, " phi: %.4f\n", xopt[5]);
- fprintf(fout, " t0: %.2f\n", xopt[6]);
- fprintf(fout, " z1: %.2f\n", xopt[7]);
- fprintf(fout, " z2: %.2f\n", xopt[8]);
- fprintf(fout, " fmin: %.2f\n", fmin);
- fprintf(fout, " time: %lld\n", elapsed);
+ if (first_ev) fprintf(fout, " ev:\n");
+ fprintf(fout, " - gtid: %i\n", ev.gtid);
+ fprintf(fout, " fit:\n");
+ fprintf(fout, " -\n");
+ fprintf(fout, " energy: %.2f\n", xopt[0]);
+ fprintf(fout, " posx: %.2f\n", xopt[1]);
+ fprintf(fout, " posy: %.2f\n", xopt[2]);
+ fprintf(fout, " posz: %.2f\n", xopt[3]);
+ fprintf(fout, " theta: %.4f\n", xopt[4]);
+ fprintf(fout, " phi: %.4f\n", xopt[5]);
+ fprintf(fout, " t0: %.2f\n", xopt[6]);
+ fprintf(fout, " z1: %.2f\n", xopt[7]);
+ fprintf(fout, " z2: %.2f\n", xopt[8]);
+ fprintf(fout, " fmin: %.2f\n", fmin);
+ fprintf(fout, " time: %lld\n", elapsed);
fflush(fout);
}
diff --git a/src/mkreleasehdr.sh b/src/mkreleasehdr.sh
new file mode 100755
index 0000000..85f32b2
--- /dev/null
+++ b/src/mkreleasehdr.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+GIT_SHA1=`(git show-ref --head --hash=8 2> /dev/null || echo 00000000) | head -n1`
+GIT_DIRTY=`git diff --no-ext-diff 2> /dev/null | wc -l`
+BUILD_ID=`uname -n`"-"`date +%s`
+test -f release.h || touch release.h
+(cat release.h | grep SHA1 | grep $GIT_SHA1) && \
+(cat release.h | grep DIRTY | grep $GIT_DIRTY) && exit 0 # Already up-to-date
+echo "#define GIT_SHA1 \"$GIT_SHA1\"" > release.h
+echo "#define GIT_DIRTY \"$GIT_DIRTY\"" >> release.h
+echo "#define BUILD_ID \"$BUILD_ID\"" >> release.h
+touch release.c # Force recompile of release.c
diff --git a/src/release.c b/src/release.c
new file mode 100644
index 0000000..f8dc46f
--- /dev/null
+++ b/src/release.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Redis nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* Every time the Redis Git SHA1 or Dirty status changes only this small
+ * file is recompiled, as we access this information in all the other
+ * files using this functions. */
+
+#include <string.h>
+
+#include "release.h"
+
+char *GitSHA1(void) {
+ return GIT_SHA1;
+}
+
+char *GitDirty(void) {
+ return GIT_DIRTY;
+}