From 46f9b83fe54b2c0b2a81c60de143ba0abcb75ec9 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sat, 16 Jun 2018 11:39:54 -0500 Subject: [PATCH] Add calcrom discord webhook to travis --- .travis.yml | 2 ++ .travis/calcrom/calcrom.pl | 37 +++++++++++++++++++++++++++++++++++++ .travis/calcrom/webhook.sh | 16 ++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100755 .travis/calcrom/calcrom.pl create mode 100755 .travis/calcrom/webhook.sh diff --git a/.travis.yml b/.travis.yml index fef1fc0eb..aad16906c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,3 +26,5 @@ matrix: script: - ./build_tools.sh - make -j2 compare +after_success: + - .travis/calcrom/webhook.sh pokeemerald diff --git a/.travis/calcrom/calcrom.pl b/.travis/calcrom/calcrom.pl new file mode 100755 index 000000000..8ee02036d --- /dev/null +++ b/.travis/calcrom/calcrom.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +(@ARGV == 1) + or die "ERROR: no map file specified.\n"; +open(my $file, $ARGV[0]) + or die "ERROR: could not open file '$ARGV[0]'.\n"; + +my $src = 0; +my $asm = 0; +while (my $line = <$file>) +{ + if ($line =~ /^ \.(\w+)\s+0x[0-9a-f]+\s+(0x[0-9a-f]+) (\w+)\/.+\.o/) + { + my $section = $1; + my $size = hex($2); + my $dir = $3; + + if ($section =~ /text/) + { + if ($dir eq 'src') + { + $src += $size; + } + elsif ($dir eq 'asm') + { + $asm += $size; + } + } + } +} + +my $total = $src + $asm; +my $srcPct = sprintf("%.4f", 100 * $src / $total); +my $asmPct = sprintf("%.4f", 100 * $asm / $total); +print "$total total bytes of code\n"; +print "$src bytes of code in src ($srcPct%)\n"; +print "$asm bytes of code in asm ($asmPct%)\n"; diff --git a/.travis/calcrom/webhook.sh b/.travis/calcrom/webhook.sh new file mode 100755 index 000000000..336a8103e --- /dev/null +++ b/.travis/calcrom/webhook.sh @@ -0,0 +1,16 @@ +#!/bin/bash -ex + +# Only run this script if it's the master branch build. +if [[ "$TRAVIS_BRANCH" != "master" || "$TRAVIS_PULL_REQUEST" != "false" ]]; then + exit 0 +fi + +build_name=$1 +map_file=$build_name.map +if [ ! -f $map_file ]; then + echo "$map_file does not exist!" + exit 1 +fi + +output=$(perl $(dirname "$0")/calcrom.pl $build_name.map | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g') +curl -d "{\"username\": \"OK\", \"avatar_url\": \"https://i.imgur.com/38BQHdd.png\", \"content\":\"\`\`\`$build_name progress:\\n$output\`\`\`\"}" -H "Content-Type: application/json" -X POST https://discordapp.com/api/webhooks/340931107060973570/$DISCORD_WEBHOOK_KEY