gencastor 2.31 KB
Newer Older
1
#!/bin/tcsh
2
3
4
5
6
7
#
# A wrapper script for gencastor.bin, to put files in the proper places and avoid to overwrite not modified ones.
# It also manages the generated SQL scripts.
#
# @author Castor dev team, castor-dev@cern.ch
#
8
# @(#)$RCSfile: gencastor,v $ $Revision: 1.20 $ $Release$ $Date: 2009/06/30 10:45:58 $ $Author: itglp $
9
# 
's avatar
committed
10

11
if ("$1" == "-h" || "$1" == "") then
's avatar
committed
12
  echo "Usage :"
13
  echo "  $0 [-w castor_workdir] [-c topNamespace] [-h] [-v|--version] XMIFile"
14
15
  exit
else if ("$1" == "-v" || "$1" == "--version") then
16
  "$0".bin --version
's avatar
committed
17
18
19
  exit
else if ("$1" == "-w") then
  set WORKDIR=$2
20
21
22
23
24
25
26
  if ("$3" == "-c") then
    set TOPNS = $4
    set XMIFILE=$5
  else
    set TOPNS = 'castor'
    set XMIFILE=$3
  endif
's avatar
committed
27
28
else
  set WORKDIR=`pwd`
29
30
31
32
33
34
35
  if ("$1" == "-c") then
    set TOPNS = $2
    set XMIFILE=$3
  else
    set TOPNS = 'castor'
    set XMIFILE=$1
  endif
's avatar
committed
36
37
endif

38
set TMPDIR=`mktemp /tmp/gencastor-XXXXXX`
's avatar
committed
39
rm -rf ${TMPDIR}
40
41
mkdir -p ${TMPDIR}/${TOPNS}/db
cp ${WORKDIR}/${TOPNS}/db/*.sql ${TMPDIR}/${TOPNS}/db/
42

43
($0.bin -o ${TMPDIR} -c ${TOPNS} --nocrashhandler ${XMIFILE} > /dev/tty) >& /dev/null
44

45
46
47
48
if ($? > 0) then
  echo Error during code generation, exiting
  exit
endif
49

's avatar
committed
50
51
set pushdsilent
pushd ${TMPDIR}
52
rm -f ${TOPNS}/db/*Generated*
53

54
55
56
57
58
59
# Type2Obj content
echo '/* Fill Type2Obj metatable */' >> ${TOPNS}/db/oracleSchema.sql
grep OBJ_ ${WORKDIR}/${TOPNS}/Constants.hpp | grep '=' | sed 's/ *\([^ ]*\) = \([0-9]*\).*$/\2  \1/' | sed 's/OBJ_//g' | awk '{print "INSERT INTO Type2Obj (type, object) VALUES (" $1 ", '\''" $2 "'\'');" }' >> ${TOPNS}/db/oracleSchema.sql
echo 'COMMIT;' >> ${TOPNS}/db/oracleSchema.sql
echo >> ${TOPNS}/db/oracleSchema.sql

's avatar
committed
60
61
62
foreach f (`find . -type f`)
  #echo $f
  if !(-f ${WORKDIR}/${f}) then
63
64
65
    if !(-d `dirname ${WORKDIR}/${f}`) then
      mkdir -p `dirname ${WORKDIR}/${f}`
    endif
's avatar
committed
66
67
    echo "Creating $f"
    cp ${TMPDIR}/${f} ${WORKDIR}/$f
68
69
  else
    if (-f ${WORKDIR}/${f}_clone) then
70
      #echo Merging clone before upgrading $f
71
72
73
74
      `dirname $0`/codemerge.py ${TMPDIR}/${f} ${WORKDIR}/${f}_clone ${TMPDIR}/${f}_merge
      mv ${TMPDIR}/${f}_merge ${TMPDIR}/${f}
    endif
    set d = `diff -q ${WORKDIR}/${f} ${TMPDIR}/${f}`
's avatar
committed
75
76
77
78
79
80
81
    #echo "Diff gave --$d--"
    if ("$d" != "") then
      echo "Upgrading $f"
      cp ${TMPDIR}/${f} ${WORKDIR}/${f}
    endif
  endif
end
82
echo Code generation done
's avatar
committed
83
84
popd
rm -rf ${TMPDIR}