Appearance
| 1 | namespace Driver is | |
| 2 | use IO.Path; | |
| 3 | ||
| 4 | class TARGET_FRAMEWORK_RESOLVER is | |
| 5 | init() is si | |
| 6 | ||
| 7 | resolve_tfm( | |
| 8 | target_framework_override: string?, | |
| 9 | sdk_reference_path: string?, | |
| 10 | host_target_framework: string? | |
| 11 | ) -> string is | |
| 12 | if target_framework_override? /\ target_framework_override.length > 0 then | |
| 13 | return target_framework_override; | |
| 14 | fi | |
| 15 | ||
| 16 | if sdk_reference_path? /\ sdk_reference_path.length > 0 then | |
| 17 | let from_path = _extract_tfm_from_path(sdk_reference_path); | |
| 18 | if from_path.length > 0 then | |
| 19 | return from_path; | |
| 20 | fi | |
| 21 | fi | |
| 22 | ||
| 23 | if host_target_framework? /\ host_target_framework.length > 0 then | |
| 24 | return host_target_framework; | |
| 25 | fi | |
| 26 | ||
| 27 | return "net10.0"; | |
| 28 | si | |
| 29 | ||
| 30 | resolve_framework_version(tfm: string) -> string is | |
| 31 | let body mut = tfm; | |
| 32 | ||
| 33 | if body.starts_with("netcoreapp") then | |
| 34 | body = body.substring(10, body.length - 10); | |
| 35 | elif body.starts_with("net") then | |
| 36 | body = body.substring(3, body.length - 3); | |
| 37 | else | |
| 38 | return tfm; | |
| 39 | fi | |
| 40 | ||
| 41 | let dot = body.index_of('.'); | |
| 42 | ||
| 43 | if dot <= 0 \/ dot >= body.length - 1 then | |
| 44 | return tfm; | |
| 45 | fi | |
| 46 | ||
| 47 | let major = body.substring(0, dot); | |
| 48 | let minor = body.substring(dot + 1, body.length - dot - 1); | |
| 49 | ||
| 50 | if !_is_all_digits(major) \/ !_is_all_digits(minor) then | |
| 51 | return tfm; | |
| 52 | fi | |
| 53 | ||
| 54 | return "{major}.{minor}.0"; | |
| 55 | si | |
| 56 | ||
| 57 | extract_tfm(runtime_config_content: string) -> string? is | |
| 58 | let key_index = runtime_config_content.index_of("\"tfm\""); | |
| 59 | ||
| 60 | if key_index < 0 then | |
| 61 | return null; | |
| 62 | fi | |
| 63 | ||
| 64 | let colon = runtime_config_content.index_of(':', key_index); | |
| 65 | let open = if colon >= 0 then runtime_config_content.index_of('"', colon) else -1 fi; | |
| 66 | let close = if open >= 0 then runtime_config_content.index_of('"', open + 1) else -1 fi; | |
| 67 | ||
| 68 | if close < 0 then | |
| 69 | return null; | |
| 70 | fi | |
| 71 | ||
| 72 | return runtime_config_content.substring(open + 1, close - open - 1); | |
| 73 | si | |
| 74 | ||
| 75 | _extract_tfm_from_path(path: string mut) -> string is | |
| 76 | while path.length > 0 /\ (path.ends_with('/') \/ path.ends_with('\\')) do | |
| 77 | path = path.substring(0, path.length - 1); | |
| 78 | od | |
| 79 | ||
| 80 | return Path.get_file_name(path) ?? ""; | |
| 81 | si | |
| 82 | ||
| 83 | _is_all_digits(s: string) -> bool is | |
| 84 | if s.length == 0 then | |
| 85 | return false; | |
| 86 | fi | |
| 87 | ||
| 88 | for c in s do | |
| 89 | if !char.is_digit(c) then | |
| 90 | return false; | |
| 91 | fi | |
| 92 | od | |
| 93 | ||
| 94 | return true; | |
| 95 | si | |
| 96 | si | |
| 97 | si |