1#!/usr/bin/env bash
2
3# Copyright 2023 Google LLC
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#     https://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# Run this script with a number of Rust files as input. It will combine them to
18# a single file which you can compile to check the validity of the inputs.
19#
20# For a Cargo based workflow, you can run
21#
22# ./generated_files_compile.sh generated/*.rs > generated_files.rs
23#
24# followed by cargo test.
25
26for input_path in "$@"; do
27    echo "mod $(basename -s .rs "$input_path") {"
28    # The inner (module) attribute needs to be removed to produce a
29    # valid file.
30    grep -v '#!\[rustfmt::skip\]' "$input_path"
31    echo "}"
32done
33
34cat <<EOF
35#[test]
36fn generated_files_compile() {
37    // Empty test, we only want to see that things compile.
38}
39EOF
40