yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
1fb60f25b
master
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 () { 9me =$( basename " $ 0" ) 10cat <<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 23case $ 1 in 24 -h| --help) 25show_help 26exit 0 27 ;; 28 --source) 29project_root =" $ 2 " 30shift 31 ;; 32 --check-only) 33check_only =1 34 ;; 35 *) 36echo "unrecognized argument: $ 1 " >&2 37show_help >&2 38exit 1 39 ;; 40esac 41shift 42done 43 44missing_bin =0 45 46require_bin () { 47 localname =" $ 1 " 48if !command -v " $ name " &>/dev/null;then 49echo "This script needs $ name , but it isn't in \$PATH" >&2 50missing_bin =1 51return 52fi 53} 54 55require_bin "mcs" 56require_bin "mono" 57 58if [" $ missing_bin " -eq 1 ];then 59exit 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{ 72class Program 73{ 74static int Main(string[] args) 75{ 76if (args.Length < 1) 77{ 78Console.WriteLine("Please provide a directory path"); 79return 1; 80} 81 82try 83{ 84Builder.Run(args[0]); 85return 0; 86} 87catch (Exception ex) 88{ 89Console.WriteLine(\$"Error: {ex.Message}"); 90return 1; 91} 92} 93} 94} 95EOL 96 97if !mcs -r:System.Core " $ temp_dir /temp_program.cs" -out: " $ temp_dir /toc-builder.exe" ;then 98echo "Compilation of $ script_dir /scripts/Program.cs failed" >&2 99exit 1 100fi 101 102for dir in "user-guide" ;do 103if [ -d" $ docs_dir / $ dir " ];then 104if [" $ check_only " -eq 1 ];then 105# Ensure working directory is clean 106if !git -C " $ project_root " diff--quiet "docs/ $ dir /toc.html" 2 > /dev/null;then 107echo "Working directory not clean, cannot check TOC" >&2 108exit 1 109fi 110fi 111 112if !mono " $ temp_dir /toc-builder.exe" " $ docs_dir / $ dir " ;then 113echo "TOC generation failed for $ dir " >&2 114exit 1 115fi 116 117if [" $ check_only " -eq 1 ];then 118if !git -C " $ project_root " diff--quiet "docs/ $ dir /toc.html" 2 > /dev/null;then 119git -C " $ project_root " diff--color "docs/ $ dir /toc.html" 120git -C " $ project_root " checkout-- "docs/ $ dir /toc.html" 2 > /dev/null 121exit 1 122fi 123fi 124else 125echo "Directory $ dir not found" >&2 126fi 127done