From 934ce04a23c6e6e20de0b12f5014469edb5f5034 Mon Sep 17 00:00:00 2001 From: Arkerthan <arkerthan@gmail.com> Date: Thu, 14 Mar 2019 21:56:50 +0100 Subject: [PATCH] java compilefiles --- compile-git+java-sanityCheck.bat | 39 +++++++++++ compile-git+java-sanityCheck.sh | 44 ++++++++++++ java+gitGrep-sanityCheck.sh | 111 +++++++++++++++++++++++++++++++ sanityCheck-java | 1 - sanityCheck-java.bat | 1 - 5 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 compile-git+java-sanityCheck.bat create mode 100755 compile-git+java-sanityCheck.sh create mode 100755 java+gitGrep-sanityCheck.sh delete mode 100755 sanityCheck-java delete mode 100644 sanityCheck-java.bat diff --git a/compile-git+java-sanityCheck.bat b/compile-git+java-sanityCheck.bat new file mode 100644 index 00000000000..b1050a2d7d8 --- /dev/null +++ b/compile-git+java-sanityCheck.bat @@ -0,0 +1,39 @@ +@echo off +:: Free Cities Basic Compiler - Windows + +:: Set working directory +pushd %~dp0 + +:: See if we can find a git installation +setlocal enabledelayedexpansion + +for %%k in (HKCU HKLM) do ( + for %%w in (\ \Wow6432Node\) do ( + for /f "skip=2 delims=: tokens=1*" %%a in ('reg query "%%k\SOFTWARE%%wMicrosoft\Windows\CurrentVersion\Uninstall\Git_is1" /v InstallLocation 2^> nul') do ( + for /f "tokens=3" %%z in ("%%a") do ( + set GIT=%%z:%%b + set GITFOUND=yes + goto FOUND + ) + ) + ) +) +:FOUND +if %GITFOUND% == yes ( + set "PATH=%GIT%bin;%PATH%" + bash --login -c ./java+gitGrep-sanityCheck.sh +) + +:: Compile the game +call "%~dp0compile.bat" + +if %GITFOUND% == yes ( + :: Make the output prettier, replacing \t with a tab and \n with a newline + bash -c "sed -i -e '/^.*<div id=\"store-area\".*$/s/\\\t/\t/g' -e '/^.*<div id=\"store-area\".*$/s/\\\n/\n/g' bin/FC_pregmod.html" + + :: Revert ./src/init/storyInit.tw for next compilation + git checkout -- ./src/init/storyInit.tw +) + +popd +PAUSE diff --git a/compile-git+java-sanityCheck.sh b/compile-git+java-sanityCheck.sh new file mode 100755 index 00000000000..53f1ec1f7aa --- /dev/null +++ b/compile-git+java-sanityCheck.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# Run sanity check. +./java+gitGrep-sanityCheck.sh + +HASH="$(git rev-list -n 1 --abbrev-commit HEAD)" + +export TWEEGO_PATH=devTools/tweeGo/storyFormats +TWEEGO_EXE="tweego" + +if hash $TWEEGO_EXE 2>/dev/null; then + echo "system tweego binary" +else + case "$(uname -m)" in + x86_64|amd64) + echo "x64 arch" + if [ "$(uname -s)" = "Darwin" ]; then + TWEEGO_EXE="./devTools/tweeGo/tweego_osx64" + else + TWEEGO_EXE="./devTools/tweeGo/tweego_nix64" + fi + ;; + x86|i[3-6]86) + echo "x86 arch" + if [ "$(uname -s)" = "Darwin" ]; then + TWEEGO_EXE="./devTools/tweeGo/tweego_osx86" + else + TWEEGO_EXE="./devTools/tweeGo/tweego_nix86" + fi + ;; + *) + echo "No system tweego binary found, and no precompiled binary for your platform available" + echo "Please compile tweego and put the executable in PATH" + exit 2 + esac +fi + +$TWEEGO_EXE -o "bin/FC_pregmod_${HASH}_tmp.html" src/ + +#Make the output prettier, replacing \t with a tab and \n with a newline +sed -i -e '/^<div id="store-area".*$/s/\\t/\t/g' -e '/^<div id="store-area".*$/s/\\n/\n/g' "bin/FC_pregmod_${HASH}_tmp.html" \ + && mv "bin/FC_pregmod_${HASH}_tmp.html" "bin/FC_pregmod_${HASH}.html" + +echo "FC_pregmod_$HASH.html compilation finished." diff --git a/java+gitGrep-sanityCheck.sh b/java+gitGrep-sanityCheck.sh new file mode 100755 index 00000000000..02e5e085312 --- /dev/null +++ b/java+gitGrep-sanityCheck.sh @@ -0,0 +1,111 @@ +#!/bin/bash +if [ ! -d ".git" ]; then + #not running in git repo, so can't use git commands :-) + echo "No .git repo found - skipping sanity checks" + exit 0 +fi + +WARNING='\033[93m' +WARNING='\033[93m' +ENDC='\033[0m' + +myprint() { + while read data; do + echo -n -e "[$1]$WARNING" + echo "$data" + done +} + +GREP="git grep -n --color" +# Check for missing right angle bracket: <</if> +#$GREP "<</[^>]*>[^>]" -- 'src/*' | myprint "MissingClosingAngleBracket" +#$GREP "<<[^>()]*>[^()<>"$'\r]*\r'"\?$" -- 'src/*' | myprint "MissingClosingAngleBracket" +# Check for missing left angle bracket: </if>> +#$GREP "\([^<]\|^\)</\?\(if\|else\|case\|set\|print\|elseif\)" -- 'src/*' | myprint "MissingOpeningAngleBracket2" +# Check for accidental assignment. e.g.: <<if $foo = "hello">> +$GREP "<<[ ]*if[^>=]*[^><\!=]=[^=][^>]*>>" -- 'src/*' | myprint "AccidentalAssignmentInIf" +# Check for accidental assignment. e.g.: <<elseif $foo = "hello">> +$GREP "<<[ ]*elseif[^>=]*[^><\!=]=[^=][^>]*>>" -- 'src/*' | myprint "AccidentalAssignmentInElseIf" +# Check for missing ". e.g.: <<if $foo == "hello>> +$GREP "<<[^\"<>]*\"[^\"<>]*>>" -- 'src/*' | myprint "MissingSpeechMark" +# Check for missing ". e.g.: <<if $foo = "hello) +$GREP -e "<<[^\"<>]*\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\"\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\([^\"<>]\| [<>] \)*>>" --and --not -e "*[^']*" -- 'src/*' | myprint "MissingSpeechMark2" +# Check for colors like: @@color:red - should be @@.red +$GREP -e "@@color:" --and --not -e "@@color:rgb([0-9 ]\+,[0-9 ]\+,[0-9 ]\+)" -- "src/*" | myprint "UseCssColors" +# Check for missing $ in activeSlave or PC +$GREP "<<[ ]*[^\$><_\[]*\(activeSlave\|PC\)[.]" -- "src/*" | myprint "MissingDollar" +# Check for closing bracket without opening bracket. e.g.: <<if foo)>> (but <<case "foo")>> is valid, so ignore those +$GREP -e "<<[ a-zA-Z]\+\([^()<>]\|[^()<>][<>][^()<>]\)*)" --and --not -e "<< *case" -- "src/*" | myprint "MissingOpeningBracket" +# Check for opening bracket without closing bracket. e.g.: <<if (foo>> +$GREP -e "<<[ a-zA-Z]\([^<>]\|[^<>][<>][^<>]\)\+(\([^()<>]\|[^<>()][<>][^<>()]\|([^<>()]*])\)*>>" -- "src/*" | myprint "MissingClosingBracket" +# Check for two closing brackets but one opening bracket. e.g.: <<if (foo))>> +$GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*)[^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingOpeningBracket2" +# Check for one closing bracket but two opening brackets. e.g.: <<if ((foo)>> +$GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*([^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingClosingBracket2" +$GREP -e "<<.*[(][^<>)]*[(][^<>)]*)\?[^<>)]*>>" -- "src/*" | myprint "MissingClosingBracket3" +# Check for missing >>. e.g.: <<if $foo +#$GREP "<<[^<>]*[^,\"\[{"$'\r]\r'"\?$" -- 'src/*' | myprint "MissingClosingAngleBrackets" +# Check for too many >>>. e.g.: <</if>>> +$GREP "<<[^<>]*[<>]\?[^<>]*>>>" -- "src/*.tw" | myprint "TooManyAngleBrackets" +# Check for too many <<<. e.g.: <<</if>> +#$GREP "<<<[^<>]*[<>]\?[^<>]*>>" -- "src/*.tw" | myprint "TooManyAngleBrackets" +# Check for wrong capitalization on 'activeslave' and other common typos +$GREP -e "\$act" --and --not -e "\$\(activeSlave\|activeChild\|activeArcology\|activeStandard\|activeOrgan\|activeLimbs\|activeUnits\|activeCanine\|activeHooved\|activeFeline\)" -- "src/*" | myprint "WrongCapitilization" +$GREP "\(csae\|[a-z] She \|attepmts\|youreslf\|advnaces\|canAcheive\|setBellySize\|SetbellySize\|setbellySize\|bellypreg\|pregBelly\|bellyimplant\|bellyfluid\|pronounCaps\|carress\|hormonebalance\|fetishknown\)" -- 'src/*' | myprint "SpellCheck" +$GREP "\(recieve\|recieves\)" -- 'src/*' | myprint "PregmodderCannotSpellReceive" +$GREP "\$slave\[" -- 'src/*' | myprint "ShouldBeSlaves" +# Check for strange spaces e.g. $slaves[$i]. lips +$GREP "\$slaves\[\$i\]\. " -- 'src/*' | myprint "MissingPropertyAfterSlaves" +# Check using refreshmentType instead of refreshment +$GREP "\$PC.refreshmentType[^ =]" -- 'src/*' | myprint "ShouldBeRefreshment" +# Check, e.g., <<//if>> +$GREP "<</[a-zA-Z]*[^a-zA-Z<>]\+[a-zA-Z]*>>" -- 'src/*' | myprint "DoubleSlash" +# Check, e.g. <<else $foo==4 +#$GREP "<<else >\?[^>]" -- 'src/*' | myprint "ShouldBeElseIf" +# Check, e.g., =to +$GREP "=to" -- 'src/*' | myprint "EqualAndTo" +# Check doing $slaves.foo instead of $slaves[i].foo +$GREP -e "[$]slaves[.]" --and --not -e '[$]slaves[.]\(length\|random\|map\|filter\|deleteAt\|push\|find\|includes\|delete\|forEach\)' -- 'src/*' | myprint "MissingSlavesIndex" +# Try to check for accidentally mixing slaves[] and activeSlave. This can have a lot of false matches, but has caught a lot of bugs so it's worth the pain +$GREP -e "activeSlave[.]" --and -e "slaves\[..\?\][.]" --and --not -e '[.]ID' --and --not -e 'slaves\[..\?\][.]\(slaveName\|slaveSurname\|actualAge\|relation\|assignment\|age\|devotion\|trust\|vagina\|mother\|father\|training\)' -- 'src/*' | myprint "MaybeAccidentalMixingOfSlavesAndActiveSlave" +# Check, e.g. <<set foo == 4>> +$GREP "<<set[^{>=]*==" -- 'src/*' | myprint "DoubleEqualsInSet" +# Check for, e.g <<if slaves[foo]>> +$GREP "<<\([^>]\|[^>]>[^>]\)*[^$]slaves\[" -- 'src/*' | myprint "MissingDollar" +# Check for missing $ or _ in variable name: +$GREP -e "<<[a-zA-Z]\([^>\"]\|[^>]>[^>]\|\"[^\"]*\"\)* [a-zA-Z]\+ * =" -- src/*.tw | myprint "MissingDollar2" +# Check for missing command, e.g. <<foo = +$GREP -e "<<[a-zA-Z]* = *" -- src/*.tw | myprint "BadCommand" +# Check for duplicate words, e.g. with with +$GREP -e " \(\b[a-zA-Z][a-zA-Z]\+\) \1\b " --and --not -e " her her " --and --not -e " you you " --and --not -e " New New " --and --not -e "Slave Slave " --and --not -e " that that " --and --not -e " in in " --and --not -e " is is " -- 'src/*' | myprint "Duplicate words" +# Check for obsolete SugarCube macros +$GREP -E "<<display |<<click|<<.*\.contains" -- src/*.tw | myprint "ObsoleteMacro" +# Check for double articles +$GREP -E "\Wa an\W" -- src/*.tw | myprint "DoubleArticle" +# Check for incorrect articles +$GREP -i -E "\Wa (a|e|i|o|u)." -- src/*.tw | grep -a -i -vE "\Wa (un|eu|us|ut|on|ur|in)." | grep -a -i -vE "(&|<<s>>|UM)." | myprint "IncorrectArticle" +$GREP -i -E "\Wan (b|c|d|f|g|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z)\w." -- src/*.tw | grep -a -i -vE "[A-Z]{3}" | myprint "IncorrectArticle" +# Check for $ sign mid-word +$GREP -i "\w$\w" -- src/*.tw | myprint "VarSignMidWord" +# check for $ sign at beginning of macro +$GREP '<<\s*\$' -- 'src/*' | myprint "VarSignAtMacroStart" +# check for missing ; before statement +$GREP 'if $ ' -- 'src/*' | myprint "missing ; before statement" +$GREP 'elseif $ ' -- 'src/*' | myprint "missing ; before statement" +# Check for a . inside a <<>> +$GREP "<<[a-zA-Z]\([^\"'>]\|[^\"'>]>[^\"'>]\)*[a-zA-Z][.][^a-zA-Z]" | myprint "StrangeCharacterAfterDot" +# Check for @@. instead of .@@ +$GREP -E "@@(\.|,|;|:)\s" -- src/*.tw | myprint "WrongSelectorPunctuation" + +# Check that we do not have any variables that we use only once. e.g. $onlyUsedOnce +# Ignore *Nationalities +( +cd src/ +cat $(find . -name "*.tw" ) | tr -c '$a-zA-Z' '\n' | sed -n '/^[$]/p' | grep -v "Nationalities" | sort | uniq -u | sed 's/^[$]/-e[$]/' | sed 's/$/\\\\W/' | xargs -r git grep -n --color | myprint "OnlyUsedOnce" +cat $(find . -name "*.tw" ) | tr -c '.$a-zA-Z[]_' '\n' | sed 's/SugarCube\.State\.variables\./$/g' | sed -n -e 's/^[$]\(PC\|activeSlave\|\(slaves\|tanks\)\[[^]]*\]*\)[.]\([a-zA-Z]\+\).*$/[.]\3/p' | sort | uniq -u |sed 's/^\(.*\)$/-e\1\\\\\b/' | xargs -r git grep -n --color | myprint "SlaveAttributeUsedOnce" +$GREP "\$\(PC\|activeSlave\|slaves\|tanks\)[.][^a-zA-Z]" | myprint "UnexpectedCharAfterDot" + +) + +#run the java sanity check +java -jar SanityCheck.jar diff --git a/sanityCheck-java b/sanityCheck-java deleted file mode 100755 index 455bbfbc243..00000000000 --- a/sanityCheck-java +++ /dev/null @@ -1 +0,0 @@ -java -jar SanityCheck.jar diff --git a/sanityCheck-java.bat b/sanityCheck-java.bat deleted file mode 100644 index 455bbfbc243..00000000000 --- a/sanityCheck-java.bat +++ /dev/null @@ -1 +0,0 @@ -java -jar SanityCheck.jar -- GitLab