yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

aidanfnvDelete GFX User Guide (#7474)1fb60f25b

master
2.7 KiB127 linesraw
1#!/usr/bin/env bash
2set -e
3
4script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5project_root="$(dirname "$script_dir")"
6check_only=0
7
8show_help() {
9  me=$(basename "$0")
10  cat <<EOF
11$me: Build table of contents for documentation directories
12
13Usage: $me [--help] [--source <path>] [--check-only]
14
15Options:
16  --help           Show this help message
17  --source         Path to project root directory (defaults to parent of the script directory)
18  --check-only     Check if TOC needs updating, exit 1 if changes needed
19EOF
20}
21
22while [[ "$#" -gt 0 ]]; do
23  case $1 in
24  -h | --help)
25    show_help
26    exit 0
27    ;;
28  --source)
29    project_root="$2"
30    shift
31    ;;
32  --check-only)
33    check_only=1
34    ;;
35  *)
36    echo "unrecognized argument: $1" >&2
37    show_help >&2
38    exit 1
39    ;;
40  esac
41  shift
42done
43
44missing_bin=0
45
46require_bin() {
47  local name="$1"
48  if ! command -v "$name" &>/dev/null; then
49    echo "This script needs $name, but it isn't in \$PATH" >&2
50    missing_bin=1
51    return
52  fi
53}
54
55require_bin "mcs"
56require_bin "mono"
57
58if [ "$missing_bin" -eq 1 ]; then
59  exit 1
60fi
61
62temp_dir=$(mktemp -d)
63trap 'rm -rf "$temp_dir"' EXIT
64
65docs_dir="$project_root/docs"
66
67cat >"$temp_dir/temp_program.cs" <<EOL
68$(cat "$script_dir/scripts/Program.cs")
69
70namespace toc
71{
72    class Program
73    {
74        static int Main(string[] args)
75        {
76            if (args.Length < 1)
77            {
78                Console.WriteLine("Please provide a directory path");
79                return 1;
80            }
81
82            try
83            {
84                Builder.Run(args[0]);
85                return 0;
86            }
87            catch (Exception ex)
88            {
89                Console.WriteLine(\$"Error: {ex.Message}");
90                return 1;
91            }
92        }
93    }
94}
95EOL
96
97if ! mcs -r:System.Core "$temp_dir/temp_program.cs" -out:"$temp_dir/toc-builder.exe"; then
98  echo "Compilation of $script_dir/scripts/Program.cs failed" >&2
99  exit 1
100fi
101
102for dir in "user-guide"; do
103  if [ -d "$docs_dir/$dir" ]; then
104    if [ "$check_only" -eq 1 ]; then
105      # Ensure working directory is clean
106      if ! git -C "$project_root" diff --quiet "docs/$dir/toc.html" 2>/dev/null; then
107        echo "Working directory not clean, cannot check TOC" >&2
108        exit 1
109      fi
110    fi
111
112    if ! mono "$temp_dir/toc-builder.exe" "$docs_dir/$dir"; then
113      echo "TOC generation failed for $dir" >&2
114      exit 1
115    fi
116
117    if [ "$check_only" -eq 1 ]; then
118      if ! git -C "$project_root" diff --quiet "docs/$dir/toc.html" 2>/dev/null; then
119        git -C "$project_root" diff --color "docs/$dir/toc.html"
120        git -C "$project_root" checkout -- "docs/$dir/toc.html" 2>/dev/null
121        exit 1
122      fi
123    fi
124  else
125    echo "Directory $dir not found" >&2
126  fi
127done