kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

install_links.h (2934B)


      1 #ifndef KIT_DRIVER_INSTALL_LINKS_H
      2 #define KIT_DRIVER_INSTALL_LINKS_H
      3 
      4 #include <stddef.h>
      5 
      6 #include "driver.h"
      7 #include "env.h"
      8 
      9 /* Shared tool-link laying for `kit install` (and, in future, `kit update`).
     10  *
     11  * "Installing" the kit toolchain means populating a directory with one entry
     12  * per tool, each pointing at the running kit binary, so the tools can be
     13  * invoked by their bare names (cc, ld, nm, ...). Entries are symlinks on POSIX
     14  * and hard links on Windows; either can be forced. This module owns the
     15  * mechanism (build the path, overwrite/replace policy, symlink-vs-hardlink,
     16  * dry-run/verbose printing, diagnostic on failure); callers own the policy
     17  * (which directory, which tools, how the link kind was chosen).
     18  *
     19  * Every diagnostic is emitted via driver_errf(tool_tag, ...) so the caller's
     20  * tool name appears in error lines. */
     21 
     22 /* group_mask sentinel meaning "every tool compiled into this binary",
     23  * regardless of its DriverToolGroup. Distinct from any real group-bit
     24  * combination so it cannot collide with a DRIVER_GROUP_* union. */
     25 #define DRIVER_GROUP_ALL ((unsigned)~0u)
     26 
     27 /* Options shared by every link laid in one install/update run. `target_exe` is
     28  * the link target (typically the running kit binary's absolute path).
     29  * `use_hardlink` selects hard links (1) over symlinks (0). `force` replaces an
     30  * existing entry; without it, an existing entry is an error. `dry_run` prints
     31  * what would happen and changes nothing. `verbose` prints each link as it is
     32  * created. `tool_tag` names the calling tool in diagnostics. */
     33 typedef struct DriverInstallLinkOpts {
     34   const char* target_exe;
     35   const char* tool_tag;
     36   int use_hardlink;
     37   int force;
     38   int dry_run;
     39   int verbose;
     40 } DriverInstallLinkOpts;
     41 
     42 /* Lay one link `bindir/name` -> opts->target_exe per `opts`. Returns 0 on
     43  * success, nonzero on failure (after emitting a diagnostic via
     44  * driver_errf(opts->tool_tag, ...)). Honors dry-run (prints, no change), force
     45  * (replace an existing entry), and verbose. */
     46 int driver_install_link_one(DriverEnv* env, const char* bindir,
     47                             const char* name,
     48                             const DriverInstallLinkOpts* opts);
     49 
     50 /* Lay a link in `bindir` for every tool in the centralized table whose group
     51  * set is selected by `group_mask`: a tool at index j is included iff
     52  * `group_mask == DRIVER_GROUP_ALL` or `(driver_tool_groups(j) & group_mask)`
     53  * is non-zero. Each link points at opts->target_exe. Returns 0 when every
     54  * selected link succeeded, otherwise the number of links that failed (each
     55  * already diagnosed). The count of links laid (the would-be / installed total)
     56  * is stored in *out_done when out_done is non-NULL. */
     57 unsigned driver_install_links(DriverEnv* env, const char* bindir,
     58                               unsigned group_mask,
     59                               const DriverInstallLinkOpts* opts,
     60                               unsigned* out_done);
     61 
     62 #endif