|
| 1 | +import os |
| 2 | +import sys |
| 3 | + |
| 4 | +# --- Configuration --- |
| 5 | +# A dictionary that maps each environment variable to a set of its allowed values. |
| 6 | +# This is the single source of truth for all validation. |
| 7 | +VALIDATION_RULES = { |
| 8 | + 'SCRIPTING_BACKEND_IL2CPP_MONO': {'il2cpp', 'mono'}, |
| 9 | + 'BURST_ON_OFF': {'on', 'off'}, |
| 10 | + 'PLATFORM_WIN64_MAC_ANDROID': {'win64', 'mac', 'android'} |
| 11 | +} |
| 12 | + |
| 13 | +def main(): |
| 14 | + """ |
| 15 | + Validates Yamato environment variables using a rule-based dictionary. |
| 16 | + Exits with 1 if any variable is invalid, otherwise exits with 0. |
| 17 | + """ |
| 18 | + all_params_valid = True |
| 19 | + |
| 20 | + # Iterate through the dictionary of rules. |
| 21 | + for var_name, allowed_values in VALIDATION_RULES.items(): |
| 22 | + # Get the variable's value from the environment. |
| 23 | + actual_value = os.environ.get(var_name, '') |
| 24 | + |
| 25 | + # Check if the actual value is in the set of allowed values. |
| 26 | + if actual_value not in allowed_values: |
| 27 | + print( |
| 28 | + f"ERROR: Invalid {var_name}: '{actual_value}'. " |
| 29 | + f"Allowed values are: {list(allowed_values)}", |
| 30 | + file=sys.stderr |
| 31 | + ) |
| 32 | + all_params_valid = False |
| 33 | + |
| 34 | + # --- Validation for Invalid Combinations --- |
| 35 | + platform = os.environ.get('PLATFORM_WIN64_MAC_ANDROID') |
| 36 | + scripting_backend = os.environ.get('SCRIPTING_BACKEND_IL2CPP_MONO') |
| 37 | + |
| 38 | + if platform == 'mac' and scripting_backend == 'il2cpp': |
| 39 | + print( |
| 40 | + "ERROR: Invalid Configuration: The 'mac' platform with the 'il2cpp' " |
| 41 | + "Note that for now windows machine is used for building project and it's a known limitation that mac builds (via windows machine) can be done only with mono", |
| 42 | + file=sys.stderr |
| 43 | + ) |
| 44 | + all_params_valid = False |
| 45 | + |
| 46 | + if platform == 'android' and scripting_backend == 'mono': |
| 47 | + print( |
| 48 | + "ERROR: Invalid Configuration: The 'android' platform with the 'mono' " |
| 49 | + "Note that mobile builds are not supporting mono and need il2cpp scripting backend", |
| 50 | + file=sys.stderr |
| 51 | + ) |
| 52 | + all_params_valid = False |
| 53 | + |
| 54 | + # --- Final Result --- |
| 55 | + if not all_params_valid: |
| 56 | + print("\nOne or more parameters failed validation. Halting build.", file=sys.stderr) |
| 57 | + # Exit with a non-zero code to fail the Yamato job. |
| 58 | + sys.exit(1) |
| 59 | + |
| 60 | + print("All parameters are valid. Proceeding with the build.") |
| 61 | + |
| 62 | +if __name__ == "__main__": |
| 63 | + main() |
0 commit comments