NASA Logo
Ocean Color Science Software

ocssw V2022
build_manifest_ocssw.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 """
4 Created on Wed Nov 20 15:56:47 EST 2019
5 
6 @author: dshea
7 """
8 
9 import sys
10 import argparse
11 import subprocess
12 import multiprocessing as mp
13 
14 machineInfo = [
15  # RHEL 8
16  {
17  "name" : "linux_64",
18  "login" : "-p 10022 gs616-container103",
19  "initStr" : "source .bash_profile",
20  "exitStr" : ""
21  },
22  # Ubuntu 20.04
23  {
24  "name" : "odps",
25  "login" : "analysis701",
26  "initStr" : "source .profile",
27  "exitStr" : ""
28  },
29  # macOS intel
30  {
31  "name" : "macosx_intel",
32  "login" : "seadas4",
33  "initStr" : "source .bash_profile",
34  "exitStr" : " && fix_mac_rpath.py"
35  },
36  # macOS arm64
37  {
38  "name" : "macosx_arm64",
39  "login" : "seadas5",
40  "initStr" : "source .zshrc",
41  "exitStr" : ""
42  },
43  # Poseidon HPC, RHEL 8
44  {
45  "name" : "linux_hpc",
46  "login" : "poseidon",
47  "initStr" : "source .bash_profile",
48  "exitStr" : ""
49  },
50 ]
51 
52 firstRunStr = " && cd \$OCSSWROOT/.. && if [ ! -d ocssw ]; then mkdir ocssw; fi && if [ ! -d ocssw/share ]; then mkdir ocssw/share; fi && if [ ! -d ocssw/testdata ]; then mkdir ocssw/testdata; fi && if [ ! -d ocssw/var ]; then mkdir ocssw/var; fi && if [ ! -d ocssw/opt ]; then mkdir ocssw/opt; fi && if [ ! -d polarimetry ]; then mkdir polarimetry; fi"
53 saveOcsswStr = " && rm -rf saveOcssw && mkdir saveOcssw && cd ocssw && mv share testdata var ../saveOcssw"
54 restoreOcsswStr = " && rm -rf share/modis && mv ../saveOcssw/share ../saveOcssw/testdata ../saveOcssw/var ."
55 saveOptStr = " && mv opt ../saveOcssw"
56 restoreOptStr = " && mv ../saveOcssw/opt ."
57 getOcsswStr = " && cd \$OCSSWROOT/.. && rm -rf ocssw && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/obpg/ocssw.git && cd ocssw && source OCSSW_bash.env"
58 getSubmodulesStr = " && git submodule init && git submodule update"
59 buildOptStr = " && ./get_lib3_src.sh && cd opt/src && ./BuildIt.py && cd ../.."
60 buildOcsswStr = " && mkdir build && cd build && cmake .. -DBUILD_ALL=1 && make -j 20 install"
61 getViirsStr = " && cd \$OCSSWROOT/.. && rm -rf viirs_l1 && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/viirs/viirs_l1.git && cd viirs_l1"
62 buildViirsStr = " && mkdir build && cd build && cmake .. && make -j 20 install"
63 getFocsStr = " && cd \$OCSSWROOT/.. && rm -rf focs && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/obpg/focs.git && cd focs"
64 buildFocsStr = " && mkdir build && cd build && cmake .. && make -j 20 install"
65 getDtdbStr = " && cd \$OCSSWROOT/.. && rm -rf dtdb && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/aerosol/dtdb.git && cd dtdb"
66 buildDtdbStr = " && mkdir build && cd build && cmake .. && make -j 20 install"
67 
68 getHarp2Str = " && cd \$OCSSWROOT/../polarimetry && rm -rf harp && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/polarimetry/harp.git && cd harp"
69 buildHarp2HippStr = " && cd hipp && mkdir build && cd build && cmake .. && make install && cd .."
70 
71 getL1bcgen_spexoneStr = " && cd \$OCSSWROOT/../polarimetry && rm -rf spex && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/polarimetry/spex.git && cd spex"
72 buildL1bcgen_spexoneStr = " && mkdir build && cd build && cmake .. -DCMAKE_EXE_LINKER_FLAGS=\\\"-Wl,-rpath,\\\\\$ORIGIN/../opt/lib -L\$LIB3_DIR/lib -lnetcdf_c++4 -lnetcdf -lhdf5 -llapack -lblas\\\" -DCMAKE_PREFIX_PATH=\$LIB3_DIR -DL1BC_ONLY=1 -DCMAKE_BUILD_TYPE=Release && make -j 20 && cp spexone \$OCSSWROOT/bin/l1bcgen_spexone"
73 
74 getFastmapolStr = " && cd \$OCSSWROOT/../polarimetry && rm -rf fastmapol && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/polarimetry/fastmapol.git && cd fastmapol"
75 buildFastmapolStr = " && mkdir build && cd build && cmake .. && make install"
76 
77 getUaaStr = " && cd \$OCSSWROOT/../sat && rm -rf unified_dtdb_aerosol && git clone https://oceandata.sci.gsfc.nasa.gov/rcs/sat/unified_dtdb_aerosol.git && cd unified_dtdb_aerosol"
78 buildUaaStr = " && mkdir build && cd build && cmake .. && make install"
79 
80 
81 def doIt(cmd, logFilename):
82  logFile = open(logFilename, "w")
83  result = subprocess.run(cmd, shell=True, stderr=subprocess.STDOUT, stdout=logFile)
84  logFile.close()
85  sys.exit(result.returncode)
86 
87 
88 def run():
89  processes = []
90 
91  parser = argparse.ArgumentParser(description="Build OCSSW on all of our architectures")
92  parser.add_argument("-t", "--tag", default=None,
93  help="git tag or branch that you want to build")
94  parser.add_argument("-a", "--arch", default=None,
95  help="comma separated list of architectures that you want to build (linux_64,linux_hpc,odps,macosx_intel,macosx_arm64)")
96  parser.add_argument("--build_opt", default=False, action="store_true",
97  help="build opt (lib3) first")
98 
99 
100  args = parser.parse_args()
101 
102  # make sure the arch list is valid
103  if args.arch:
104  machineList = []
105  for info in machineInfo:
106  machineList.append(info["name"])
107  archList = args.arch.split(',')
108  for arch in archList:
109  if arch not in machineList:
110  print("Architecture", arch, "is not in the list of supported architectures")
111  sys.exit(1)
112 
113  runList = []
114 
115  archFound = False
116  for info in machineInfo:
117  if args.arch:
118  if info["name"] not in args.arch:
119  continue
120  archFound = True
121 
122  runList.append(info["name"])
123  print("\n---making", info["name"])
124 
125  commandLine = "ssh " + info["login"] + ' "set -x; ' + info["initStr"] + firstRunStr + saveOcsswStr
126  if not args.build_opt:
127  commandLine += saveOptStr
128  commandLine += getOcsswStr
129  if args.tag:
130  commandLine += " && git checkout " + args.tag
131  commandLine += getSubmodulesStr
132  if args.build_opt:
133  commandLine += buildOptStr
134  else:
135  commandLine += restoreOptStr
136  commandLine += restoreOcsswStr
137  commandLine += " && rm -rf ../saveOcssw"
138 
139  # build VIIRS
140  commandLine += getViirsStr
141  if args.tag:
142  commandLine += " && git checkout " + args.tag
143  commandLine += getSubmodulesStr
144  commandLine += buildViirsStr
145 
146  # build FOCS
147  # temporary exclusion for the tensor flow on macs
148  if (info["name"] != "macosx_intel") and (info["name"] != "macosx_arm64"):
149  commandLine += getFocsStr
150  if args.tag:
151  commandLine += " && git checkout " + args.tag
152  commandLine += getSubmodulesStr
153  commandLine += buildFocsStr
154 
155  # build dtdb
156  commandLine += getDtdbStr
157  if args.tag:
158  commandLine += " && git checkout " + args.tag
159  commandLine += getSubmodulesStr
160  commandLine += buildDtdbStr
161 
162  # build OCSSW
163  commandLine += " && cd \$OCSSWROOT"
164  commandLine += buildOcsswStr
165 
166  # for now only build for ODPS
167  if info["name"] == "odps":
168  # get harp2 and build hipp
169  commandLine += getHarp2Str
170  if args.tag:
171  commandLine += " && git checkout " + args.tag
172  commandLine += buildHarp2HippStr
173 
174  # get fasstmapol and build
175  commandLine += getFastmapolStr
176  if args.tag:
177  commandLine += " && git checkout " + args.tag
178  commandLine += buildFastmapolStr
179 
180  # get UAA and build
181  commandLine += getUaaStr
182  if args.tag:
183  commandLine += " && git checkout " + args.tag
184  commandLine += buildUaaStr
185 
186  #
187  # for now only build on poseidon
188  #
189  if info["name"] == "linux_hpc":
190  # build l1bcgen_spexone
191  commandLine += getL1bcgen_spexoneStr
192  if args.tag:
193  commandLine += " && git checkout " + args.tag
194  commandLine += buildL1bcgen_spexoneStr
195 
196 
197  commandLine += info["exitStr"]
198  commandLine += '"'
199 
200  logFilename = "build." + info["name"] + ".log"
201 
202  processes.append(mp.Process(target=doIt, name=info["name"], args=(commandLine, logFilename)))
203 
204  if not archFound:
205  print("Architecture", args.arch, "is not valid")
206  sys.exit(1)
207 
208  print("Starting Processes")
209 
210  # Run processes
211  for p in processes:
212  p.start()
213 
214  print("Waiting for Processes")
215 
216  # Exit the completed processes
217  for p in processes:
218  p.join()
219 
220  print("Checking results")
221 
222  # check the return result
223  result = True
224  for p in processes:
225  if p.exitcode != 0:
226  result = False
227  print(p.name, "return code =", p.exitcode)
228  else:
229  print(p.name, "Success")
230 
231  if result:
232  print()
233  print("Everyting completed successfully.")
234  return 0
235 
236  return 1
237 
238 
239 if __name__ == "__main__":
240  sys.exit(run())
void print(std::ostream &stream, const char *format)
Definition: PrintDebug.hpp:38
def doIt(cmd, logFilename)