coc-autark
Version:
Autark build-script completion for coc.nvim
258 lines (247 loc) • 14.3 kB
JavaScript
;
// Static knowledge about the Autark build-script DSL used for completion.
//
// The tables below follow the upstream Autark documentation
// (https://github.com/Softmotions/autark) and the check scripts shipped in
// `check_scripts/`. Autark itself accepts any rule name, so this data only
// supplies *suggestions*; it never rejects anything the user types.
// Primary directives: meaningful at the top level and, because Autark allows
// nesting, inside most rule bodies.
export const DIRECTIVES = [
['meta', 'Defines META_* variables from nested rules.'],
['option', 'Documents a build option; listed by `./build.sh -l`.'],
['env', 'Exports an environment variable to spawned build processes.'],
['set', 'Defines a lazily evaluated variable in the current scope.'],
['let', 'Defines a variable that is reevaluated on every access.'],
['check', 'Runs check scripts from `.autark/` before the build.'],
['configure', 'Substitutes @VAR@ placeholders of a template into the cache.'],
['include', 'Processes another Autark script in a child source/cache context.'],
['cc', 'Compiles C sources; the object list is stored in CC_OBJS.'],
['cxx', 'Compiles C++ sources; the object list is stored in CXX_OBJS.'],
['host-cc', 'Compiles C sources for the build host (cross builds).'],
['host-cxx', 'Compiles C++ sources for the build host (cross builds).'],
['run', 'Defines a custom action with `consumes`/`produces` dependencies.'],
['run-on-install', 'Action executed only during installation.'],
['install', 'Copies artifacts into the installation prefix.'],
['install-sources', 'Copies project sources into the installation prefix.'],
['in-sources', 'Evaluates its body inside the project source directory.'],
['foreach', 'Repeats a `run` rule for every item of a list.'],
['macro', 'Defines a reusable script macro invoked by `call`.'],
['call', 'Invokes a macro defined by the `macro` rule.'],
['library', 'Resolves a library file by name into a variable.'],
['echo', 'Prints values to stdout, optionally per build phase.'],
['error', 'Aborts the build with an error message.'],
['if', 'Conditional group resolved during the init phase.'],
['else', 'Alternative branch of the preceding `if`.'],
];
// Conditions valid inside `if` and inside `and`/`or` groups. Each one also
// exists in a negated form (see `CONDITIONS` below).
export const CONDITION_NAMES = [
['defined', 'defined { VAR ... } — true if any variable is defined.'],
['eq', 'eq { EXPR1 EXPR2 } — true if both values are equal.'],
['prefix', 'prefix { EXPR1 EXPR2 } — true if EXPR2 is a prefix of EXPR1.'],
['contains', 'contains { EXPR1 EXPR2 } — true if EXPR1 contains EXPR2.'],
['in', 'in { EXPR1 EXPR2 ... } — true if EXPR1 equals one of the values.'],
['and', 'and { EXPR ... } — true if all expressions are truthy.'],
['or', 'or { EXPR ... } — true if any expression is truthy.'],
];
export const CONDITIONS = [];
for (const [name, doc] of CONDITION_NAMES) {
CONDITIONS.push([name, doc]);
CONDITIONS.push([`!${name}`, `Negated form: ${doc}`]);
}
// Contextual child fields, offered inside the matching rule body.
export const RULE_FIELDS = {
set: [
['parent', 'Writes the variable into the parent script scope.'],
['root', 'Writes the variable into the root script scope.'],
['_', 'Anonymous inline set; usable inside other rules.'],
],
let: [
['parent', 'Writes the variable into the parent script scope.'],
['root', 'Writes the variable into the root script scope.'],
['_', 'Anonymous inline set; usable inside other rules.'],
],
library: [
['parent', 'Stores the resolved library path in the parent scope.'],
['root', 'Stores the resolved library path in the root scope.'],
],
cc: [
['objects', 'Variable that receives the object file list (default CC_OBJS).'],
['consumes', 'Extra files this rule depends on, e.g. generated headers.'],
],
cxx: [
['objects', 'Variable that receives the object file list (default CXX_OBJS).'],
['consumes', 'Extra files this rule depends on, e.g. generated headers.'],
['modules', 'Sources treated as C++20 module units.'],
],
'host-cc': [
['objects', 'Variable that receives the object list (default HOST_CC_OBJS).'],
['consumes', 'Extra files this rule depends on, e.g. generated headers.'],
],
'host-cxx': [
['objects', 'Variable that receives the object list (default HOST_CXX_OBJS).'],
['consumes', 'Extra files this rule depends on, e.g. generated headers.'],
['modules', 'Sources treated as C++20 module units.'],
],
run: [
['exec', 'Executes a command directly (no shell interpretation).'],
['shell', 'Executes a command through /bin/sh.'],
['consumes', 'Input files/variables; changes rerun the rule.'],
['produces', 'Output files produced by the rule.'],
['always', 'Runs the action unconditionally on every build.'],
['host', 'Builds a host tool (cross builds only).'],
],
'run-on-install': [
['exec', 'Executes a command directly (no shell interpretation).'],
['shell', 'Executes a command through /bin/sh.'],
['consumes', 'Input files/variables; changes rerun the rule.'],
['produces', 'Output files produced by the rule.'],
['always', 'Runs the action unconditionally on every build.'],
['host', 'Builds a host tool (cross builds only).'],
],
echo: [
['init', 'Prints the message during the init phase.'],
['setup', 'Prints the message during the setup phase.'],
['build', 'Prints the message during the build phase (default).'],
],
meta: [
['name', 'Project name; exposed as META_NAME.'],
['artifact', 'Artifact name; exposed as META_ARTIFACT.'],
['version', 'Project version; exposed as META_VERSION.'],
['version_major', 'Major version component; exposed as META_VERSION_MAJOR.'],
['version_minor', 'Minor version component; exposed as META_VERSION_MINOR.'],
['version_patch', 'Patch version component; exposed as META_VERSION_PATCH.'],
['description', 'Short description; exposed as META_DESCRIPTION.'],
['website', 'Project website; exposed as META_WEBSITE.'],
['author', 'Project author; exposed as META_AUTHOR.'],
['vendor', 'Project vendor; exposed as META_VENDOR.'],
['maintainer', 'Package maintainer; exposed as META_MAINTAINER.'],
['sources', 'Source location; exposed as META_SOURCES.'],
['license', 'License name; exposed as META_LICENSE.'],
['let', 'Defines a variable without the META_ prefix.'],
],
toolchain: [
['id', 'Target id; SYSTEM_TARGET and SYSTEM_TOOLCHAIN.'],
['system', 'Target OS name; SYSTEM_NAME and SYSTEM_<OS>.'],
['arch', 'Target architecture; SYSTEM_ARCH.'],
['arch-alt', 'Alternative architecture name; SYSTEM_ARCH_ALT.'],
['bits', 'Target bitness; SYSTEM_BITNESS_<bits>.'],
['endian', 'Target endianness; SYSTEM_<ENDIAN>_ENDIAN.'],
['cc', 'Target C compiler; CC.'],
['cxx', 'Target C++ compiler; CXX.'],
['ar', 'Target archiver; AR.'],
['cflags', 'Target C flags; CFLAGS_TARGET.'],
['ldflags', 'Target linker flags; LDFLAGS_TARGET.'],
['sysroot', 'Target sysroot.'],
['host-cc', 'Host C compiler; HOST_CC.'],
['host-cxx', 'Host C++ compiler; HOST_CXX.'],
['host-ar', 'Host archiver; HOST_AR.'],
['host-cflags', 'Host C flags; HOST_CFLAGS.'],
['host-cxxflags', 'Host C++ flags; HOST_CXXFLAGS.'],
['host-ldflags', 'Host linker flags; HOST_LDFLAGS.'],
['runner', 'Command prefix used to run target binaries; RUNNER.'],
],
};
// Well-known script variables. Values are documentation strings only.
export const VARIABLES = [
['AUTARK_ROOT_DIR', 'Absolute path of the project root.'],
['AUTARK_CACHE_DIR', 'Absolute path of the project cache directory.'],
['AUTARK_EXTERNS_DIR', 'Directory holding fetched external projects.'],
['UNIT_DIR', 'Source directory of the current build unit (script).'],
['UNIT_CACHE_DIR', 'Cache directory of the current build unit (script).'],
['INSTALL_ENABLED', '1 when installation was requested.'],
['INSTALL_PREFIX', 'Absolute installation prefix.'],
['INSTALL_BIN_DIR', 'Executable destination, relative to INSTALL_PREFIX.'],
['INSTALL_LIB_DIR', 'Library destination, relative to INSTALL_PREFIX.'],
['INSTALL_DATA_DIR', 'Data destination, relative to INSTALL_PREFIX.'],
['INSTALL_INCLUDE_DIR', 'Header destination, relative to INSTALL_PREFIX.'],
['INSTALL_PKGCONFIG_DIR', 'pkg-config destination, relative to INSTALL_PREFIX.'],
['INSTALL_MAN_DIR', 'Manual page destination, relative to INSTALL_PREFIX.'],
['CC', 'C compiler; set by the system.sh check.'],
['CXX', 'C++ compiler.'],
['AR', 'Archiver; set by the system.sh check.'],
['PKGCONF', 'pkg-config compatible tool; set by the system.sh check.'],
['CFLAGS', 'C compiler flags.'],
['CXXFLAGS', 'C++ compiler flags.'],
['LDFLAGS', 'Linker flags.'],
['CC_OBJS', 'Object files produced by the last cc rule.'],
['CXX_OBJS', 'Object files produced by the last cxx rule.'],
['HOST_CC_OBJS', 'Object files produced by the last host-cc rule.'],
['HOST_CXX_OBJS', 'Object files produced by the last host-cxx rule.'],
['HOST_CC', 'Host C compiler for build tools (cross builds).'],
['HOST_CXX', 'Host C++ compiler for build tools (cross builds).'],
['HOST_AR', 'Host archiver for build tools (cross builds).'],
['HOST_CFLAGS', 'Host C flags for build tools (cross builds).'],
['HOST_CXXFLAGS', 'Host C++ flags for build tools (cross builds).'],
['HOST_LDFLAGS', 'Host linker flags for build tools (cross builds).'],
['SYSTEM_NAME', 'Detected/declared target OS name (lowercase).'],
['SYSTEM_ARCH', 'Detected/declared target architecture.'],
['SYSTEM_ARCH_ALT', 'Alternative architecture name.'],
['SYSTEM_BITNESS', 'Target bitness (32 or 64).'],
['SYSTEM_ENDIAN', 'Target endianness (little or big).'],
['SYSTEM_LITTLE_ENDIAN', '1 when the target is little-endian.'],
['SYSTEM_BIGENDIAN', '1 when the target is big-endian.'],
['SYSTEM_CROSS', '1 in a cross build.'],
['SYSTEM_TARGET', 'Cross build target id.'],
['SYSTEM_TOOLCHAIN', 'Absolute path of the toolchain descriptor.'],
['SYSTEM_RUNNER', 'Command prefix used to run target binaries.'],
['RUNNER', 'Command prefix used to run target binaries.'],
['CFLAGS_TARGET', 'Extra target C flags from the toolchain descriptor.'],
['LDFLAGS_TARGET', 'Extra target linker flags from the toolchain descriptor.'],
['META_NAME', 'Project name from meta { name { ... } }.'],
['META_ARTIFACT', 'Artifact name from meta.'],
['META_VERSION', 'Project version from meta.'],
['META_VERSION_MAJOR', 'Major version component from meta.'],
['META_VERSION_MINOR', 'Minor version component from meta.'],
['META_VERSION_PATCH', 'Patch version component from meta.'],
['META_DESCRIPTION', 'Project description from meta.'],
['PTHREAD_LFLAG', 'pthread compiler/linker flag; set by test_pthread.sh.'],
['PTHREAD_HAS_SPINLOCK', '1 when pthread spinlocks are available.'],
['HAVE_QSORT_R', '1 when qsort_r() is available; set by test_qsort_r.sh.'],
['CHANGELOG_VERSION', 'Latest changelog version.'],
['CHANGELOG_VERSION_MAJOR', 'Latest changelog major version.'],
['CHANGELOG_VERSION_MINOR', 'Latest changelog minor version.'],
['CHANGELOG_VERSION_PATCH', 'Latest changelog patch version.'],
['CHANGELOG_VERSION_FLAVOR', 'Latest changelog version flavor, e.g. `dev`.'],
['BUILD_TYPE', 'Conventional build type (Release, Debug, ...), set via -DBUILD_TYPE=... or the environment.'],
['SYSTEM_BITNESS_32', '1 when the target is 32-bit.'],
['SYSTEM_BITNESS_64', '1 when the target is 64-bit.'],
['SYSTEM_LINUX', '1 when the target system is Linux.'],
['SYSTEM_DARWIN', '1 when the target system is macOS.'],
['SYSTEM_FREEBSD', '1 when the target system is FreeBSD.'],
['SYSTEM_OPENBSD', '1 when the target system is OpenBSD.'],
['SYSTEM_NETBSD', '1 when the target system is NetBSD.'],
['SYSTEM_WINDOWS', '1 when the target system is Windows.'],
['SYSTEM_ANDROID', '1 when the target system is Android.'],
['JDK_HOME', 'JDK home directory; set by find_jdk.sh.'],
['JNI_CFLAGS', 'JNI compiler flags; set by find_jdk.sh.'],
['JNI_LDFLAGS', 'JNI linker flags; set by find_jdk.sh.'],
['JAVA_EXEC', 'java executable; set by find_jdk.sh.'],
['JAVAC_EXEC', 'javac executable; set by find_jdk.sh.'],
['JAR_EXEC', 'jar executable; set by find_jdk.sh.'],
];
// Standard check scripts from the Autark repository. Known ones are offered
// even when they are not vendored into the project yet.
export const CHECK_SCRIPTS = [
['system.sh', 'Detects OS, CPU, bitness and endianness; sets CC, AR, PKGCONF and SYSTEM_*.'],
['test_header.sh', 'test_header.sh { HEADER DEFINE_VAR } — sets DEFINE_VAR if the header compiles.'],
['test_symbol.sh', 'test_symbol.sh { SYMBOL HEADER DEFINE_VAR } — sets DEFINE_VAR if the symbol exists.'],
['test_blocks.sh', 'test_blocks.sh { DEFINE_VAR } — checks Clang/Apple blocks support.'],
['test_pthread.sh', 'Checks pthread flags; sets PTHREAD_LFLAG and PTHREAD_HAS_SPINLOCK.'],
['test_qsort_r.sh', 'Checks qsort_r() availability; sets HAVE_QSORT_R=1.'],
['changelog_gnu.sh', 'changelog_gnu.sh { CHANGELOG } — parses a GNU changelog into CHANGELOG_VERSION*.'],
['changelog_md.sh', 'changelog_md.sh { CHANGELOG.md } — parses a Markdown changelog into CHANGELOG_VERSION*.'],
['fetch_resource.sh', 'fetch_resource.sh { URL TARGET_DIR [VAR] [NSTRIP_DIRS] } — fetches an archive, directory or git repo.'],
['find_jdk.sh', 'Locates a JDK; sets JDK_HOME, JNI_CFLAGS, JNI_LDFLAGS, JAVA_EXEC, JAVAC_EXEC and JAR_EXEC.'],
];
// Check scripts whose first argument is a project file path.
export const PATH_CHECK_SCRIPTS = new Set(['changelog_gnu.sh', 'changelog_md.sh']);
// Check scripts that store a result variable whose name is passed as an
// argument: script name -> index of that argument in the script's value list.
export const CHECK_OUTPUT_ARGS = {
'test_header.sh': 1, // test_header.sh { HEADER DEFINE_VAR }
'test_symbol.sh': 2, // test_symbol.sh { SYMBOL HEADER DEFINE_VAR }
'test_blocks.sh': 0, // test_blocks.sh { DEFINE_VAR }
'fetch_resource.sh': 2, // fetch_resource.sh { URL TARGET_DIR [TARGET_DIR_VAR] [NSTRIP_DIRS] }
};