*! version 1.2.4 20261103 github.com/mdroste/stata-ctools *! Shared plugin loader and identity contract program define _ctools_load version 14.1 * Not rclass, and findfile's r() is undone, so the caller's r() survives; * identity comes back through c_local. local __os = c(os) local __machine = c(machine_type) local __is_mac = 0 if "`__os'" == "MacOSX" { local __is_mac = 1 } else if strpos(lower("`__machine'"), "mac") > 0 { local __is_mac = 1 } local __plugin = "" if "`__os'" == "Windows" { local __plugin "ctools_windows.plugin" } else if `__is_mac' { local __is_arm = 0 if strpos(lower("`__machine'"), "apple") > 0 | strpos(lower("`__machine'"), "arm") > 0 | strpos(lower("`__machine'"), "silicon") > 0 { local __is_arm = 1 } if `__is_arm' == 0 & !strpos(lower("`__machine'"), "intel") & !strpos(lower("`__machine'"), "x86") { tempfile __archfile quietly shell uname -m > "`__archfile'" 2>&1 tempname __fh file open `__fh' using "`__archfile'", read text file read `__fh' __archline file close `__fh' capture erase "`__archfile'" if strpos("`__archline'", "arm64") > 0 { local __is_arm = 1 } } if `__is_arm' { local __plugin "ctools_mac_arm.plugin" } else { local __plugin "ctools_mac_x86.plugin" } } else if "`__os'" == "Unix" { local __plugin "ctools_linux.plugin" } else { local __plugin "ctools.plugin" } * The ado/plugin argument protocol, stamped from config/release.json. local __ado_protocol "2" local __reinstall `"net install ctools, from("https://raw.githubusercontent.com/mdroste/stata-ctools/main/build") replace"' tempname __rhold _return hold `__rhold' capture findfile `__plugin' local __found = (_rc == 0) local __path `"`r(fn)'"' _return restore `__rhold' local __wanted "`__plugin'" if !`__found' & "`__plugin'" != "ctools.plugin" local __plugin "ctools.plugin" capture program ctools_plugin, plugin using("`__plugin'") local __load_rc = _rc if `__load_rc' != 0 & `__load_rc' != 110 { di as error "ctools: could not load the plugin `__plugin'" di as error `" Stata reports c(os) "`__os'" and c(machine_type) "`__machine'"; ctools selected `__wanted'."' if `__found' di as error `" The plugin file is `__path'."' else di as error " `__wanted' was not found on the ado-path; reinstall ctools." di as error " Stata's plugin loader reported:" capture noisily program ctools_plugin, plugin using("`__plugin'") if "`__os'" == "Unix" & !`__is_mac' { di as error " The Linux plugin needs x86-64 glibc 2.17 or later and libgomp.so.1 from GCC 6 or later." } else if `__is_mac' { di as error " On macOS, check that the plugin is the notarized ctools release and is not quarantined." } di as error " See https://github.com/mdroste/stata-ctools/blob/main/docs/INSTALLATION.md#troubleshooting" exit `__load_rc' } capture plugin call ctools_plugin, "version" local __id_rc = _rc if `__id_rc' | "`ctools_plugin_protocol'" != "`__ado_protocol'" { local __has = cond("`ctools_plugin_protocol'" == "", "none", "`ctools_plugin_protocol'") di as error "ctools: the plugin `__plugin' does not match the installed ado files." local __ident = cond("`ctools_plugin_version'" == "", "", " (plugin version `ctools_plugin_version', revision `ctools_plugin_revision')") di as error " The ado files need plugin protocol `__ado_protocol'; the loaded plugin reports `__has'`__ident'." di as error " Reinstall ctools so its ado files and plugins come from the same release:" di as error `" `__reinstall'"' di as error " Then restart Stata, because a plugin stays loaded until Stata exits." exit 9 } c_local __ctools_plugin "`__plugin'" c_local __ctools_plugin_version "`ctools_plugin_version'" c_local __ctools_plugin_revision "`ctools_plugin_revision'" c_local __ctools_plugin_protocol "`ctools_plugin_protocol'" capture confirm number 0 end