sublime-cpp/sublime/compete_CPP.sublime-build
PeterChrz 40c23f9c6b
Sublime Text + clang C++ setup with portable installer
Build systems, Makefile, and a setup script that reproduces this
environment on another machine.

- CP.sublime-build: incremental make-based build, clang++, flags shared
  with clangd via compile_flags.txt
- compete_CPP.sublime-build: competitive-programming workflow, runs
  against inputf.in and diffs the result against expectedf.out
- Makefile: builds every .cpp in the tree into a binary beside its source
- setup.sh: export/install/check, path-neutral payload, idempotent
- README: setup notes, the Sublime $-expansion trap, and the -MMD -MP
  header-dependency limitation to fix later

The .sublime-workspace is deliberately excluded: it holds Sublime's
global recent-file history and absolute paths. Only the pane layout is
portable, extracted to sublime/layout.json.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KCtkkFDkSGi868JWuinwcF
2026-09-07 10:46:56 -04:00

37 lines
2.3 KiB
Text

{
// Competitive-programming workflow: compile the focused .cpp, feed it
// inputf.in on stdin, capture stdout to outputf.out, and print the result.
//
// Both files live NEXT TO THE SOURCE (working_dir is the file's folder),
// not at the repo root. Use "Setup" below to create them.
//
// Sublime expands ${name} AND bare $name in shell_cmd. Every $ meant for
// bash is escaped \$ -- see https://www.sublimetext.com/docs/build_systems.html
"shell_cmd": "test -n \"${file}\" || { echo 'Click into a .cpp tab, then build.'; exit 1; }; clang++ \\$(cat compile_flags.txt 2>/dev/null) \"${file}\" -o \"${file_base_name}\" || exit 1; touch inputf.in; ./\"${file_base_name}\" < inputf.in > outputf.out; echo '--- inputf.in ---'; cat inputf.in; echo '--- outputf.out ---'; cat outputf.out",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path:${folder}}",
"selector": "source.c++",
"variants":
[
{
// Same as above, then check the answer against expectedf.out.
"name": "Run + check against expectedf.out",
"shell_cmd": "test -n \"${file}\" || { echo 'Click into a .cpp tab, then build.'; exit 1; }; clang++ \\$(cat compile_flags.txt 2>/dev/null) \"${file}\" -o \"${file_base_name}\" || exit 1; touch inputf.in; ./\"${file_base_name}\" < inputf.in > outputf.out; echo '--- outputf.out ---'; cat outputf.out; if [ -f expectedf.out ]; then echo '--- diff (expected vs actual) ---'; if diff -u expectedf.out outputf.out; then echo 'PASS'; else echo 'FAIL'; exit 1; fi; else echo '(no expectedf.out here - run Setup to make one)'; fi"
},
{
// No redirect: type the input straight into the build panel.
"name": "Run (type input live)",
"shell_cmd": "test -n \"${file}\" || { echo 'Click into a .cpp tab, then build.'; exit 1; }; clang++ \\$(cat compile_flags.txt 2>/dev/null) \"${file}\" -o \"${file_base_name}\" || exit 1; ./\"${file_base_name}\"",
"interactive": true
},
{
"name": "Setup: create inputf.in / expectedf.out here",
"shell_cmd": "touch inputf.in expectedf.out outputf.out; echo \"ready in \\$(pwd):\"; ls -l inputf.in expectedf.out outputf.out"
},
{
"name": "DIAGNOSTIC - show Sublime variables",
"shell_cmd": "echo \"file = [${file}]\"; echo \"file_path = [${file_path}]\"; echo \"base_name = [${file_base_name}]\"; echo \"cwd = \\$(pwd)\""
}
]
}