| 1 | #!/usr/bin/env bash |
| 2 | set -exuo pipefail |
| 3 | |
| 4 | # ---------------------------------------------------------------------------- |
| 5 | # Run some CGE tests that can be done from a shell, without the need for any FPC. |
| 6 | # ---------------------------------------------------------------------------- |
| 7 | |
| 8 | cd "$CASTLE_ENGINE_PATH" |
| 9 | |
| 10 | # Test we don't have any projects with invalid qualified_name |
| 11 | # in CastleEngineManifest.xml . |
| 12 | do_test_qualified_name () |
| 13 | { |
| 14 | # For all projects: make sure they don't contain invalid qualified_name |
| 15 | # (it is OK to not have qualified_name at all, for now, for tools). |
| 16 | find . -name CastleEngineManifest.xml | while read -r CGE_MANIFEST_FILENAME; do |
| 17 | echo "Checking no invalid qualified name: ${CGE_MANIFEST_FILENAME}" |
| 18 | if grep --fixed-strings 'qualified_name="com.mycompany' "${CGE_MANIFEST_FILENAME}"; then |
| 19 | exit 1 |
| 20 | fi |
| 21 | if grep --fixed-strings 'qualified_name="net.sourceforge' "${CGE_MANIFEST_FILENAME}"; then |
| 22 | exit 1 |
| 23 | fi |
| 24 | if grep --fixed-strings 'qualified_name="io.sourceforge' "${CGE_MANIFEST_FILENAME}"; then |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | set +e # ignore wc exit code (wc may return 1 if no lines) |
| 29 | LINES=`grep --fixed-strings 'qualified_name="' "${CGE_MANIFEST_FILENAME}" | wc -l` |
| 30 | set -e |
| 31 | |
| 32 | if [ "$LINES" '!=' '1' -a "$LINES" '!=' '0' ]; then |
| 33 | echo "Error: ${CGE_MANIFEST_FILENAME} has > 1 line with qualified_name" |
| 34 | exit 1 |
| 35 | fi |
| 36 | done |
| 37 | |
| 38 | # For examples/ projects: make sure they contain valid qualified_name. |
| 39 | # |
| 40 | # The CGE examples should all have |
| 41 | # qualified_name="io.castleengine.xxx.yyy.zzz" |
| 42 | # (xxx.yyy.zzz being application name split into words and separated by dots). |
| 43 | # See https://castle-engine.io/coding_conventions#_examples . |
| 44 | find examples/ -name CastleEngineManifest.xml | while read -r CGE_MANIFEST_FILENAME; do |
| 45 | echo "Checking only valid: ${CGE_MANIFEST_FILENAME}" |
| 46 | if ! grep --fixed-strings 'qualified_name="io.castleengine' "${CGE_MANIFEST_FILENAME}"; then |
| 47 | echo "Error: ${CGE_MANIFEST_FILENAME} should have qualified_name starting with io.castleengine" |
| 48 | exit 1 |
| 49 | fi |
| 50 | done |
| 51 | } |
| 52 | |
| 53 | # Test that examples have no leftover "public domain" header. |
| 54 | # Examples are under BSD. |
| 55 | # See https://castle-engine.io/coding_conventions#_examples . |
| 56 | do_test_examples_copyright () |
| 57 | { |
| 58 | if grep --exclude='*~' --recursive --fixed-strings 'This code is in public domain, unlike most other CGE code' examples/; then |
| 59 | exit 1 |
| 60 | fi |
| 61 | if grep --exclude='*~' --recursive --fixed-strings 'This template code is in public domain, unlike most other CGE code' examples/; then |
| 62 | exit 1 |
| 63 | fi |
| 64 | } |
| 65 | |
| 66 | # Test editor template in build-tool/data/custom_editor_template/ is up-to-date. |
| 67 | # This means that tools/build-tool/data/custom_editor_template_rebuild.sh |
| 68 | # should do nothing. |
| 69 | do_test_custom_editor_template_up_to_date () |
| 70 | { |
| 71 | rm -Rf tools/build-tool/data/custom_editor_template-temptest/ |
| 72 | cp -R tools/build-tool/data/custom_editor_template/ \ |
| 73 | tools/build-tool/data/custom_editor_template-temptest/ |
| 74 | cd tools/build-tool/data/ |
| 75 | ./custom_editor_template_rebuild.sh |
| 76 | diff -ur custom_editor_template/ \ |
| 77 | custom_editor_template-temptest/ |
| 78 | cd ../../../ |
| 79 | rm -Rf tools/build-tool/data/custom_editor_template-temptest/ |
| 80 | } |
| 81 | |
| 82 | # Test running examples_regenerate_auto_files makes no change. |
| 83 | do_test_examples_up_to_date () |
| 84 | { |
| 85 | ./tools/internal/examples_regenerate_auto_files |
| 86 | git diff -w --exit-code examples/ |
| 87 | } |
| 88 | |
| 89 | # Check that Delphi packages do not refer to VCL or FMX when they should not. |
| 90 | do_test_packages_dependencies () |
| 91 | { |
| 92 | if grep --ignore-case 'vcl' packages/delphi/castle_engine.dpk; then |
| 93 | echo 'Error: packages/delphi/castle_engine.dpk should not depend on VCL' |
| 94 | exit 1 |
| 95 | fi |
| 96 | if grep --ignore-case 'fmx' packages/delphi/castle_engine.dpk; then |
| 97 | echo 'Error: packages/delphi/castle_engine.dpk should not depend on FMX' |
| 98 | exit 1 |
| 99 | fi |
| 100 | |
| 101 | if grep --ignore-case 'vcl' packages/delphi/castle_engine_fmx.dpk; then |
| 102 | echo 'Error: packages/delphi/castle_engine_fmx.dpk should not depend on VCL' |
| 103 | exit 1 |
| 104 | fi |
| 105 | |
| 106 | if grep --ignore-case 'fmx' packages/delphi/castle_engine_vcl.dpk; then |
| 107 | echo 'Error: packages/delphi/castle_engine_vcl.dpk should not depend on FMX' |
| 108 | exit 1 |
| 109 | fi |
| 110 | } |
| 111 | |
| 112 | # Check that Delphi packages do not contain invalid DeployFile config, |
| 113 | # pointing to absolute paths on specific disk (specific to given computer, |
| 114 | # and Delphi version) |
| 115 | # or relative (which are also wrong in this case, as we don't know Delphi BPL |
| 116 | # location relative to the CGE). |
| 117 | # They should instead point using env variables, defined by Delphi, |
| 118 | # like `$(BDSCOMMONDIR)\Bpl\castle_engine_design.bpl` . |
| 119 | # See packages/delphi/README.md . |
| 120 | # |
| 121 | # This intends to catch errors like this in DPROJ files: |
| 122 | # |
| 123 | # <DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\22.0\Bpl\castle_engine_design.bpl" Configuration="Debug" Class="ProjectOutput"> |
| 124 | # |
| 125 | # or |
| 126 | # |
| 127 | # <DeployFile LocalName="..\..\..\..\..\Public\Documents\Embarcadero\Studio\23.0\Bpl\castle_engine_window.bpl" Configuration="Debug" Class="ProjectOutput"> |
| 128 | # |
| 129 | # These should use |
| 130 | # |
| 131 | do_test_no_invalid_deploy_files () |
| 132 | { |
| 133 | if grep --ignore-case --fixed-strings '<DeployFile LocalName="c:' packages/delphi/*.dproj; then |
| 134 | echo 'Error: packages/delphi/*.dproj should not contain hardcoded absolute paths in DeployFile' |
| 135 | exit 1 |
| 136 | fi |
| 137 | if grep --ignore-case --fixed-strings '<DeployFile LocalName="d:' packages/delphi/*.dproj; then |
| 138 | echo 'Error: packages/delphi/*.dproj should not contain hardcoded absolute paths in DeployFile' |
| 139 | exit 1 |
| 140 | fi |
| 141 | if grep --ignore-case --fixed-strings '<DeployFile LocalName="e:' packages/delphi/*.dproj; then |
| 142 | echo 'Error: packages/delphi/*.dproj should not contain hardcoded absolute paths in DeployFile' |
| 143 | exit 1 |
| 144 | fi |
| 145 | |
| 146 | if grep --ignore-case --fixed-strings '<DeployFile LocalName="..' packages/delphi/*.dproj; then |
| 147 | echo 'Error: packages/delphi/*.dproj should not contain relative paths in DeployFile' |
| 148 | exit 1 |
| 149 | fi |
| 150 | } |
| 151 | |
| 152 | do_test_qualified_name |
| 153 | do_test_examples_copyright |
| 154 | do_test_custom_editor_template_up_to_date |
| 155 | do_test_examples_up_to_date |
| 156 | do_test_packages_dependencies |
| 157 | do_test_no_invalid_deploy_files |