forked from fmihpc/vlasiator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_version.sh
executable file
·172 lines (120 loc) · 5.46 KB
/
generate_version.sh
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
#
# This file is part of Vlasiator.
# Copyright 2010-2016 Finnish Meteorological Institute
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
curdir=$(pwd)
. /etc/profile
# if you use client/server visit and have "cd /lustre/tmp/..." in your ~/.bashrc this workaround is needed
cd $curdir
cat > version.cpp <<EOF
#include <iostream>
#include "mpi.h"
#include <fstream>
using namespace std;
bool printVersion() {
int rank;
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
if(rank==0){
EOF
echo " cout << endl << \"----------- Compilation --------- \"<<endl;" >>version.cpp
echo " cout << \"date: $(date)\" <<endl;" >>version.cpp
echo " cout << \"folder: $PWD \"<<endl;" >>version.cpp
echo " cout << \"CMP: $1 \"<<endl;" >>version.cpp
echo " cout << \"CXXFLAGS: $2 \"<<endl;" >>version.cpp
echo " cout << \"FLAGS: $3 \"<<endl;" >>version.cpp
echo " cout << \"INC_MPI: $4 \"<<endl;" >>version.cpp
echo " cout << \"INC_DCCRG: $5 \"<<endl;" >>version.cpp
echo " cout << \"INC_ZOLTAN: $6 \"<<endl;" >>version.cpp
echo " cout << \"INC_BOOST: $7 \"<<endl;" >>version.cpp
echo " cout << endl << \"----------- git branch --------- \"<<endl;" >>version.cpp
git branch | sed 's/\"/\\"/g' | sed 's/\\\"/\\"/g' | gawk '{printf("%s\"%s\"%s\n"," cout << ",$0," << endl;")}' >> version.cpp
echo " cout << endl << \"----------- git log (last 10 commits) --------- \"<<endl;" >>version.cpp
git log --pretty=oneline | head | sed 's/\"/\\"/g' | sed 's/\\\"/\\"/g' | gawk '{printf("%s\"%s\"%s\n"," cout << ",$0," << endl;")}' >> version.cpp
echo " cout << endl << \"----------- module list --------- \"<<endl;" >>version.cpp
module list 2>&1 | gawk '{printf("%s\"%s\"%s\n"," cout << ",$0," << endl;")}' >> version.cpp
echo " cout << endl << \"----------- git status --------- \"<<endl;" >>version.cpp
git status | sed 's/\"/\\"/g' | sed 's/\\\"/\\"/g' |gawk '{printf("%s\"%s\"%s\n"," cout << ",$0," << endl;")}' >> version.cpp
echo " cout << endl << \"----------- git diff ---------- \"<<endl;" >>version.cpp
echo " const char diff_data[] = {" >> version.cpp
DIFF=$(git diff `git diff --name-only |grep -v generate_version.sh` | xxd -i)
if [[ -n $DIFF ]]; then
echo -n $DIFF >> version.cpp
echo " ,0 };" >> version.cpp
else
echo " 0 };" >> version.cpp
fi
echo " cout << diff_data << endl;" >> version.cpp
cat >> version.cpp <<EOF
}
return true;
}
EOF
cat >> version.cpp <<EOF
std::string getVersion() {
std::string versionInfo;
EOF
echo " versionInfo+=\"----------- Compilation --------- \n\";" >>version.cpp
echo " versionInfo+=\"date: $(date)\n\";" >>version.cpp
echo " versionInfo+=\"CMP: $1 \n\";" >>version.cpp
echo " versionInfo+=\"CXXFLAGS: $2 \n\";" >>version.cpp
echo " versionInfo+=\"FLAGS: $3 \n\";" >>version.cpp
echo " versionInfo+=\"INC_MPI: $4 \n\";" >>version.cpp
echo " versionInfo+=\"INC_DCCRG: $5 \n\";" >>version.cpp
echo " versionInfo+=\"INC_ZOLTAN: $6 \n\";" >>version.cpp
echo " versionInfo+=\"INC_BOOST: $7 \n\";" >>version.cpp
echo " versionInfo+= \"----------- git branch ---------n\";" >>version.cpp
git branch | sed 's/\"/\\"/g' | sed 's/\\\"/\\"/g' | gawk '{printf("%s\"%s""\"%s\n"," versionInfo+=",$0"\\n"," ;")}' >> version.cpp
echo " versionInfo+= \"----------- git log (last 10 commits) --------- \";" >>version.cpp
git log --pretty=oneline | head | sed 's/\"/\\"/g' | sed 's/\\\"/\\"/g' | gawk '{printf("%s\"%s\"%s\n"," versionInfo+= ",$0"\\n"," ;")}' >> version.cpp
echo " versionInfo+=\"----------- module list --------- \";" >>version.cpp
module list 2>&1 | gawk '{printf("%s\"%s\"%s\n"," versionInfo+= ",$0"\\n"," ;")}' >> version.cpp
echo " versionInfo+=\"----------- git status --------- \";" >>version.cpp
git status | sed 's/\"/\\"/g' | sed 's/\\\"/\\"/g' |gawk '{printf("%s\"%s\"%s\n"," versionInfo+= ",$0"\\n"," ;")}' >> version.cpp
echo " versionInfo+=\"----------- git diff ---------- \";" >>version.cpp
echo " const char diff_data[] = {" >> version.cpp
DIFF=$(git diff `git diff --name-only |grep -v generate_version.sh` | xxd -i)
if [[ -n $DIFF ]]; then
echo -n $DIFF >> version.cpp
echo " ,0 };" >> version.cpp
else
echo " 0 };" >> version.cpp
fi
echo "std::string buffer;" >> version.cpp
echo "buffer+=diff_data;" >> version.cpp
echo "versionInfo+=buffer;" >> version.cpp
cat >> version.cpp <<EOF
return versionInfo;
}
EOF
cat >> version.cpp <<EOF
std::string getConfig(const char* filename) {
std::string configInfo;
configInfo+="\n";
configInfo+="*------------Configuration File------------*\n";
configInfo+="\n";
std::ifstream file(filename);
if (file.is_open()) {
std::string line;
while (std::getline(file, line)) {
configInfo+=line.c_str();
configInfo+="\n";
}
}
file.close();
return configInfo;
}
EOF