1#!/bin/bash 2# 3# Copyright (C) 2023 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Helper script to run cargo_embargo generate on all external Rust crates and generate an HTML 18# report of the results, including any errors, warnings or changes to Android.bp files. 19# 20# Should be run from under external/rust/crates. 21 22set -e 23 24report="cargo_embargo_report.html" 25 26cat > $report <<END 27<html> 28<head> 29<title>cargo_embargo crate report</title> 30<style type="text/css"> 31td { vertical-align: top; } 32.success { color: green; } 33.skipped { color: yellow; } 34.warning { color: orange; } 35.error { color: red; } 36</style> 37</head> 38<body> 39<h1>cargo_embargo crate report</h1> 40<h2>Using existing cargo_embargo.json</h2> 41<table> 42<tr><th>Crate name</th><th>Generate</th><th>Details</th><th style="width: 25%;">Files</th></tr> 43END 44 45success_count=0 46different_count=0 47total_count=0 48for config in */cargo_embargo.json; do 49 ((total_count+=1)) 50 crate=$(dirname $config) 51 echo "Trying $crate..." 52 echo "<tr><td><code>$crate</code></td>" >> $report 53 if (cd $crate && cargo_embargo generate cargo_embargo.json) 2> cargo_embargo.err; then 54 (cd $crate && git diff Android.bp > Android.bp.diff) 55 if grep "WARNING" cargo_embargo.err; then 56 echo '<td class="error">Warning</td>' >> $report 57 echo '<td><details><summary>' >> $report 58 grep -m 1 "WARNING" cargo_embargo.err >> $report 59 echo '</summary>' >> $report 60 sed 's/$/<br\/>/g' < cargo_embargo.err >> $report 61 echo '</details></td>' >> $report 62 else 63 # Compare the checked-in Android.bp to the generated one. 64 (cd $crate && git show HEAD:Android.bp > Android.bp.orig) 65 if diff $crate/Android.bp.orig $crate/Android.bp > /dev/null; then 66 echo '<td class="success">Success</td>' >> $report 67 ((success_count+=1)) 68 else 69 echo '<td class="warning">Different</td>' >> $report 70 ((different_count+=1)) 71 fi 72 73 echo '<td>' >> $report 74 if [[ -s "cargo_embargo.err" ]]; then 75 echo '<details>' >> $report 76 sed 's/$/<br\/>/g' < cargo_embargo.err >> $report 77 echo '</details>' >> $report 78 fi 79 echo '</td>' >> $report 80 fi 81 else 82 echo '<td class="error">Error</td>' >> $report 83 echo '<td><details open>' >> $report 84 sed 's/$/<br\/>/g' < cargo_embargo.err >> $report 85 echo '</details></td>' >> $report 86 fi 87 88 rm cargo_embargo.err 89 rm -rf "$crate/cargo.metadata" "$crate/cargo.out" "$crate/target.tmp" "$crate/Cargo.lock" "$crate/Android.bp.orig" "$crate/Android.bp.embargo" "$crate/Android.bp.embargo_nobuild" 90 (cd $crate && git checkout Android.bp) 91 92 echo '<td>' >> $report 93 if [[ -s "$crate/Android.bp.diff" ]]; then 94 echo '<details><summary>Android.bp.diff</summary><pre>' >> $report 95 cat "$crate/Android.bp.diff" >> $report 96 echo '</pre></details>' >> $report 97 rm "$crate/Android.bp.diff" 98 fi 99 echo '</td></tr>' >> $report 100done 101 102echo '</table>' >> $report 103echo "<p>$success_count success, $different_count different, $total_count total.</p>" >> $report 104echo '</body>' >> $report 105echo '</html>' >> $report 106 107echo "Open file://$PWD/$report for details" 108