diff --git a/genrules/BUILD b/genrules/BUILD index c5ca8dd..0492102 100644 --- a/genrules/BUILD +++ b/genrules/BUILD @@ -65,3 +65,62 @@ build_test( ":foo_TXT_4KB_1", ], ) + +# Remote Execution Environment Detection +# These genrules detect system resources where builds are running. + +genrule( + name = "get_cpu_info", + outs = ["cpu_info.txt"], + cmd = "(" + + "echo '=== CPU Info ===' && " + + "(grep -E 'processor|model name|cpu cores|physical id' /proc/cpuinfo || echo 'cpuinfo unavailable') && " + + "echo '' && " + + "echo '=== CPU Count ===' && " + + "(nproc || echo 'nproc unavailable')" + + ") 2>&1 | tee $@ >&2", + tags = ["no-cache"], +) + +genrule( + name = "get_memory_info", + outs = ["memory_info.txt"], + cmd = "(" + + "echo '=== Memory Info ===' && " + + "(grep -E 'MemTotal|MemAvailable' /proc/meminfo || echo 'meminfo unavailable') && " + + "echo '' && " + + "echo '=== Free Memory ===' && " + + "(free -h || echo 'free unavailable')" + + ") 2>&1 | tee $@ >&2", + tags = ["no-cache"], +) + +genrule( + name = "get_system_info", + outs = ["system_info.txt"], + cmd = "(" + + "echo '=== System Info ===' && " + + "echo '=== Hostname ===' && " + + "(hostname || echo 'unavailable') && " + + "echo '' && " + + "echo '=== Kernel ===' && " + + "(uname -a || echo 'unavailable') && " + + "echo '' && " + + "echo '=== Container/OS ===' && " + + "(cat /etc/os-release || echo 'unavailable') && " + + "echo '' && " + + "echo '=== Disk Space ===' && " + + "(df -h / || echo 'unavailable')" + + ") 2>&1 | tee $@ >&2", + tags = ["no-cache"], +) + +# Convenience target to get all info at once +filegroup( + name = "remote_exec_info", + srcs = [ + ":get_cpu_info", + ":get_memory_info", + ":get_system_info", + ], +)