util.ha (1152B)
1 // SPDX-License-Identifier: GPL-3.0-only 2 // (c) Hare authors <https://harelang.org> 3 4 use ascii; 5 use dirs; 6 use hare::module; 7 use os; 8 use strings; 9 10 fn merge_tags(current: *[]str, new: str) (void | module::error) = { 11 let trimmed = strings::trimprefix(new, "^"); 12 if (trimmed != new) { 13 free(*current); 14 *current = []; 15 }; 16 let newtags = module::parse_tags(trimmed)?; 17 defer free(newtags); 18 for :new (let newtag .. newtags) { 19 for (let j = 0z; j < len(current); j += 1) { 20 if (newtag.name == current[j]) { 21 if (!newtag.include) { 22 static delete(current[j]); 23 }; 24 continue :new; 25 }; 26 }; 27 if (newtag.include) { 28 append(current, newtag.name); 29 }; 30 }; 31 }; 32 33 fn harepath() str = os::tryenv("HAREPATH", HAREPATH); 34 35 fn harecache() str = { 36 match (os::getenv("HARECACHE")) { 37 case let s: str => 38 return s; 39 case void => 40 return dirs::cache("hare"); 41 }; 42 }; 43 44 // contents of slice shouldn't be freed 45 fn default_tags() []str = { 46 let arch = os::arch_name(os::architecture()); 47 static let platform: [7]u8 = [0...]; 48 let platform = ascii::strlower_buf(os::sysname(), platform[..0]); 49 let tags: []str = alloc([arch, platform]); 50 return tags; 51 };