Skip to content

Instantly share code, notes, and snippets.

@mikeseese
Last active August 30, 2021 20:25
Show Gist options
  • Save mikeseese/eaac28cc52a0778ab0d23f1ab5caad64 to your computer and use it in GitHub Desktop.
Save mikeseese/eaac28cc52a0778ab0d23f1ab5caad64 to your computer and use it in GitHub Desktop.
A modified version of colormake.pl to work with Unreal's build scripts (i.e. RunUAT and RunUBT)
#!/usr/bin/perl
#
# colormake.pl 0.9.20140504
#
# Copyright: (C) 1999, 2012-2014, Bjarni R. Einarsson <bre@klaki.net>
# http://bre.klaki.net/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Some useful color codes, see end of file for more.
#
$col_black = "\033[30m";
$col_red = "\033[31m";
$col_green = "\033[32m";
$col_yellow = "\033[33m";
$col_blue = "\033[34m";
$col_magenta = "\033[35m";
$col_cyan = "\033[36m";
$col_ltgray = "\033[37m";
$col_drkgray = "\033[1;30m";
$col_norm = "\033[00m";
$col_background = "\033[07m";
$col_brighten = "\033[01m";
$col_underline = "\033[04m";
$col_blink = "\033[05m";
# Customize colors here...
#
$col_default = $col_ltgray;
$col_gcc = $col_magenta . $col_brighten;
$col_make = $col_cyan;
$col_ue = $col_gcc;
$col_filename = $col_blue;
$col_linenum = $col_cyan;
$col_trace = $col_yellow;
$col_warning = $col_yellow;
$col_comment = $col_drkgray;
$tag_error = "";
$col_error = $tag_error . $col_red . $col_brighten;
$col_success = $col_green . $col_brighten;
$error_highlight = $col_brighten;
$col_build_config = $col_cyan;
$SIG{INT} = \END;
# read in config files: system first, then user
for $file ("/usr/share/colormake/colormake.rc", "$ENV{HOME}/.colormakerc")
{
unless (!-f $file or do $file)
{
warn "couldn't parse $file: $@" if $@;
}
}
# Get size of terminal
#
$lines = shift @ARGV || 0;
$cols = shift @ARGV || 0;
$cols -= 19;
$in = 'unknown';
$| = 1; # auto flush
$skip = 0;
while (<>)
{
$orgline = $thisline = $_;
# Remove multiple spaces
$thisline =~ s/ \+/ /g;
# skip lines
$skip--;
if ($skip < 0)
{
$skip = 0;
}
# Truncate lines.
# I suppose this is bad, but it's better than what less does!
if ($cols >= 0)
{
$thisline =~ s/^(.{$cols}).....*(.{15})$/$1 .. $2/;
}
# remove the "Dist/HostProject/Plugins/<Plugin>" that is created in the BuildPlugin command
$thisline =~ s|Dist[/\\]HostProject[/\\]Plugins[/\\][a-zA-Z\_\-]+[/\\]||g;
# make[1]: Entering directory `/blah/blah/blah'
if ($thisline =~ s/^((p|g)?make\[)/$col_make$1/x)
{
$in = 'make';
}
elsif ($thisline =~ s/^(\s*(libtool:\s*)?((compile|link):\s*)?(([[:ascii:]]+-)?g?(cc|\+\+)|(g|c)\+\+|clang|CC|CXX).*)$/$col_gcc$1$col_norm/)
{
$in = 'gcc';
if ($thisline =~ /\W-MF\W/)
{
$skip = 2;
}
}
elsif ($thisline =~ s/^\#/$col_comment#$1/x)
{
$in = 'comment';
}
elsif ($thisline =~ s/(\[[0-9]+\/[0-9]+\] .*\.(rc2|h|cpp|cc|c|so|a|lib|dylib|target))/$col_ue$1$col_norm/)
{
$in = 'ue'; # unreal engine
}
elsif (!$skip && $thisline =~ /^(\s*\(|\[|a(r|wk)|c(p|d|h(mod|own))|do(ne)?|e(cho|lse)|f(ind|or)|i(f|nstall)|mv|perl|r(anlib|m(dir)?)|s(e(d|t)|trip)|tar)\s+/)
{
$in = $1;
}
elsif ($thisline =~ s/([0-9]+ error(s)? generated\.)/$col_error$1$col_norm/)
{
$in = 'unknown';
}
elsif ($thisline =~ s/(Total time in (Local|Parallel) executor: [0-9]+(\.[0-9]+)? seconds|BUILD SUCCESSFUL)/$col_success$1$col_norm/)
{
$in = 'unknown';
}
elsif ($thisline =~ s/(BUILD SUCCESSFUL)/$col_success$1$col_norm/)
{
$in = 'unknown';
}
elsif ($thisline =~ s/^(Running: .*UnrealBuildTool.exe\"? )(.*)( -Project.*)/$1$col_build_config$2$col_norm$3/)
{
# this colors the build configuration (i.e. UE4Editor Mac Development)
$in = 'unknown';
}
elsif (($in eq 'gcc' || $in eq 'ue')
&& $thisline !~ /^mv\W/
)
{
# Do interesting things if make is compiling something.
if (($thisline !~ /[,:]$/) && ($thisline !~ /warning/) && ($thisline !~ /note:/))
{
# error?
if ($cols >= 0)
{
# Retruncate line, because we are about to insert "Error:".
my $c = $cols - length($tag_error);
$thisline = $orgline;
$thisline =~ s/^(.{$c}).....*(.{15})$/$1 .. $2/;
}
$thisline =~ s/(\d+:\s+)/$1$col_default$col_error/;
$thisline = $error_highlight . $thisline . $col_norm;
}
elsif (thisline =~ /note:/)
{
# note/info
$thisline =~ s|(note:\s+)(.*)$|$1$col_comment$2|;
}
else
{
# warning
$thisline =~ s|(warning:\s+)(.*)$|$1$col_warning$2|;
}
# In file included from main.cpp:38:
# main.cpp: In function int main(...)':
$thisline =~ s/(In f(unction|ile))/$col_trace$1/x;
# /blah/blah/blah.cpp:123:
$thisline =~ s|(\s)([A-Z])(:\\)|$1-DRIVE$2|g; # temporarily remove the D:\ for -DRIVED since to not confuse line numbers, for windows
$thisline =~ s|^([^:]+)|$col_filename$1$col_default|;
$thisline =~ s|:(\d+)([:,])|:$col_linenum$1$col_default$2|;
$thisline =~ s|(\s)(-DRIVE)([A-Z])|$1$3:\\|g; # remove temporary place holders
}
if ($thisline !~ /^\s+/)
{
print $col_norm, $col_default;
}
print $thisline;
}
END
{
print $col_norm;
}
# UNUSED:
#
#%colors = (
# 'black' => "\033[30m",
# 'red' => "\033[31m",
# 'green' => "\033[32m",
# 'yellow' => "\033[33m",
# 'blue' => "\033[34m",
# 'magenta' => "\033[35m",
# 'purple' => "\033[35m",
# 'cyan' => "\033[36m",
# 'white' => "\033[37m",
# 'darkgray' => "\033[30m");
@mikeseese
Copy link
Author

mikeseese commented Aug 30, 2021

This is a gist of a modified version of https://github.com/pagekite/Colormake @ v0.9.20140504 that adds in hooks for using Unreal Engine's build scripts for Bash environments (i.e. Mac/Linux). I made this to help identify warnings and errors in the build output when compiling C++ plugins that I compile and distribute on the Marketplace with the BuildPlugin command to RunUAT.sh.

This script works on Windows if you use MINGW (i.e. Git Bash).

A couple of key points:

  • Modify the colors in lines 43-54
  • Sample usage would be something like (this is running in the directory of the plugin itself, with this file in that directory):
/Users/Shared/Epic\ Games/UE_4.26/Engine/Build/BatchFiles/RunUAT.sh \
  BuildPlugin \
  -Plugin=$(pwd)/FileSDK.uplugin \
  -Package=$(pwd)/Dist \
  -TargetPlatforms=Mac \
  -Rocket \
  -VS2017 \
  | ./unreal-colormake.pl --short

The output generates something like this:

image

This isn't maintained or supported, but happy to update it with any suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment