SC::Tools are self contained single C++ source files that are (automatically) compiled on the fly and linked to Sane C++ to be immediately executed.
They leverage the growing shell, system and network programming capabilities of Sane C++ Libraries, by just including the SC.cpp unity build file, that has no third party dependencies (see Building (Contributor)).
Another way to look at them is just as small C++ scripts for which you don't need to setup or maintain a build system, as long as you only use Sane C++ Libraries.
Name is SC::Tools and not SC::Scripts because they're still just small programs.
If the system will be generalized even more, maybe acquiring more advanced capabilities from SC::Plugin and SC::Build or sandboxing capabilities, this naming will be re-evaluated and/or changed.
Reasons
SC::Tools has been created for the following reasons:
Enjoy the coolness of writing C++ scripts
Create development tools and automate shell operations in a real programming language
Allow C++ programmers to use regular C++ IDE / Debuggers when writing automation / shell scripts
Use Sane C++ Libraries for real tasks to improve them and fix bugs:
Example: Tools/SC-package.cpp uses SC::Process library to download some third party binary
Example: Tools/SC-package.cpp uses SC::Hashing library to check downloads MD5 hash
Example: Tools/SC-format.cpp uses SC::FileSystemIterator library to find all files to format in the repo
Create portable scripts that can be written once and run (or be debugged) on all platforms
Avoid introducing additional dependencies
Keep the percentage of C++ code in the repo as high as possible (as a consequence of the above)
Invoking built-in Tools
All built-in tools are invoked with the SC.sh or SC.bat bootstrap script that is located in the root of the repo.
Such script must be called with the name of the tool and some parameters.
For Example, invoking the Tools\SC-build.cpp tool with configure action:
./SC.sh build configure
or (on Windows)
SC.bat build compile
Note
SC::Tools are just regular programs being compiled on the fly when needed, so they require a working host compiler to be available in system path. This limitation could be removed if needed, as described in the Roadmap section.
Invoking custom tools
Tools can be automatically compiled and run by just passing its full path to the SC bootstrap.
Given the following custom tool at myToolDirectory/TestScript.cpp
SC-package downloads third party tools needed for Sane C++ development (example: clang-format).
Proper OS / Architecture combination is selected (Windows/Linux/Mac and Intel/ARM) and all downloaded files (packages) MD5 hash is checked for correctness. Packages are placed and extracted in _Build/_Packages and once extracted, they are symlinked in _Build/Tools.
Note
Directory naming has been chosen to avoid clashes when mounting the same working copy folder in multiple concurrent virtual machines with different Operating Systems / architectures.
This happens during regular development, where new code is frequently tested in parallel on macOS, Windows and Linux before even committing it and pushing it to the CI system.
Actions
install: Downloads requires tools (LLVM / 7zip)
Examples
./SC.sh package install
Packages
These are the packages that are currently downloaded and extracted / symlinked by SC-package.cpp:
LLVM 15: Downloads LLVM from the official github repository
7zip: 7zip executable (needed to decompress LLVM installer on Windows)
7zr.exe: 7Zip console executable (needed to decompress 7zip installer on Windows)
Tools.cpp is shared between all compiled tools by the Makefile inside the _Build/_Tools/_Intermediates directory.
This allows modifying and recompiling a script, or compiling different scripts spending negligible (often sub-second) time, to just compile/link script logic.
This is because all Sane C++ Libraries are compiled just once (the first time, in no more than a couple of seconds) inside Tools.cpp.
Roadmap
Generate ready made .vscode configurations to debug the programs easily
When and if SC::Build will be capable of launching build commands autonomously, get rid of the tool Tools\Build\ makefiles.
Investigate better way of expressing the dependencies chain between scripts
Investigate if Tools (scripts) can be sandboxed using os facilities
Do not require to have a C++ toolchain already installed on the system [*]
[*] Running the Sane C++ Tools scripts on a machine without a pre-installed compiler could be implemented by shipping a pre-compiled SC-package.cpp (that is already capable of downloading clang on all platforms) or by adding to the bootstrap script ability to download a suitable compiler (and sysroot).