• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -e
2
3# RS Invocation script to FileCheck, used to check generated Java
4# files or C++ files. This assumes that the .rs source file has the
5# Java package name "foo".
6
7print_help() {
8  help_str="Usage: %s --output=<output-dir> \
9--filecheck=<path-to-filecheck> \
10--lang=[Java/C++] \
11[--type=<typename>] \
12[--check-prefix=<prefix>] \
13<.rs file>\n"
14
15  printf "$help_str" $0
16}
17
18for arg in "$@"
19do
20  case $arg in
21  --output=*)
22    outdir="${arg#*=}"
23    ;;
24  --filecheck*)
25    filecheck="${arg#*=}"
26    ;;
27  --lang*)
28    lang="${arg#*=}"
29    ;;
30  --type*)
31    type="${arg#*=}"
32    ;;
33  --check-prefix=*)
34    check_prefix="${arg}"
35    ;;
36  --help)
37    print_help
38    exit 0
39    ;;
40  *)
41    rsfile="$arg"
42    ;;
43  esac
44done
45
46if [[ (-z $outdir) || (-z $filecheck) || (-z $rsfile) ]]
47then
48  print_help
49  exit 1
50fi
51
52if [[ ! -f $rsfile ]]
53then
54  echo "Input file $rsfile doesn't exist"
55  exit 1
56fi
57
58rsfile_basename=$(basename "$rsfile")
59
60if [[ $lang == "Java" ]]
61then
62  if [[ (-z $type) ]]
63  then
64    filecheck_inputfile=foo/ScriptC_${rsfile_basename%.*}.java
65  else
66    filecheck_inputfile=foo/ScriptField_${type}.java
67  fi
68elif [[ $lang == "C++" ]]
69then
70  if [[ (-n $type) ]]
71  then
72    echo --type not supported for C++
73    print_help
74    exit 1
75  fi
76  filecheck_inputfile=ScriptC_${rsfile_basename%.*}.h
77else
78  echo Unknown language "$lang"
79  print_help
80  exit 1
81fi
82
83if [[ ! -f $filecheck ]]
84then
85  echo "No file at supplied FileCheck path $filecheck"
86  exit 1
87fi
88
89if [[ ! -f $outdir/$filecheck_inputfile ]]
90then
91  echo "Input file $outdir/$filecheck_inputfile doesn't exist"
92  exit 1
93fi
94
95"$filecheck" -input-file "$outdir"/$filecheck_inputfile ${check_prefix} "$rsfile"
96