kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/serving/tools/testdata/entries2tables.sh (about)

     1  #!/bin/bash -e
     2  set -o pipefail
     3  # Copyright 2016 The Kythe Authors. All rights reserved.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #   http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # entries2tables.sh runs write_tables over a given entries file.
    18  #
    19  # Usage: entries2tables.sh <path-to-entries> <path-to-output-leveldb>
    20  
    21  ENTRIES="$1"
    22  OUT="${2:?"ERROR: please specify out directory"}"
    23  
    24  if [[ ! -r "$ENTRIES" ]]; then
    25    echo "ERROR: unable to read entries at \"$ENTRIES\"" >&2
    26    exit 1
    27  elif [[ -e "$OUT" ]]; then
    28    echo "ERROR: \"$OUT\" already exists" >&2
    29    exit 1
    30  fi
    31  
    32  entrystream=kythe/go/platform/tools/entrystream/entrystream
    33  write_tables=kythe/go/serving/tools/write_tables/write_tables
    34  
    35  if [[ ! -x "$entrystream" || -d "$entrystream" ]]; then
    36    entrystream="$(which entrystream)"
    37  fi
    38  if [[ ! -x "$write_tables" || -d "$write_tables" ]]; then
    39    write_tables="$(which write_tables)"
    40  fi
    41  
    42  
    43  mkdir -p "$(dirname "$OUT")"
    44  
    45  cat=cat
    46  if [[ "$ENTRIES" == *.gz ]]; then
    47    cat="gunzip -c"
    48  fi
    49  
    50  $cat "$ENTRIES" | \
    51    "$entrystream" --unique | \
    52    "$write_tables" --max_page_size 75 --entries - --out "$OUT"