| 1 | module recompilation |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | // disabling_file returns the path to a file, which if present, will disable the automatic recompilation |
| 6 | // that V attempts, when it detects that itself is newer than a tool .v source file. |
| 7 | // That file is intended to be made by `touch cmd/tools/.disable_autorecompilation` by package managers, |
| 8 | // so that tools like `v up` and `v self` will not work anymore, instead they will direct users to install |
| 9 | // V from source. |
| 10 | pub fn disabling_file(vroot string) string { |
| 11 | tools_folder := os.join_path(vroot, 'cmd', 'tools') |
| 12 | res := os.join_path_single(tools_folder, '.disable_autorecompilation') |
| 13 | return res |
| 14 | } |
| 15 | |
| 16 | // must_be_enabled is intended to be used by tools like `v self` and `v up`, to abort them |
| 17 | // early, when they detect that the V installation is part of a distro package, that has disabled autorecompilation. |
| 18 | pub fn must_be_enabled(vroot string, error_message string) { |
| 19 | file := disabling_file(vroot) |
| 20 | is_recompilation_disabled := os.exists(file) |
| 21 | if is_recompilation_disabled { |
| 22 | eprintln('Recompilation is disabled, since there is a "${file}" file present.') |
| 23 | eprintln(error_message) |
| 24 | exit(1) |
| 25 | } |
| 26 | } |
| 27 | |