1#!/bin/bash
2LOCAL_DIR="$( dirname "${BASH_SOURCE}" )"
3
4MAINLINE_FRAMEWORKS_AV_PATHS=(
5    media/extractors/
6    media/codec2/components/
7    media/libstagefright/codecs/amrnb
8    media/libstagefright/codecs/amrwb
9    media/libstagefright/codecs/amrwbenc
10    media/libstagefright/codecs/common
11    media/libstagefright/codecs/mp3dec
12    media/libstagefright/codecs/m4v_h263
13    media/libstagefright/flac/dec
14    media/libstagefright/mpeg2ts
15)
16
17MAINLINE_EXTERNAL_PROJECTS=(
18    external/aac
19    external/flac
20    external/libaac
21    external/libaom
22    external/libavc
23    external/libgav1
24    external/libgsm
25    external/libhevc
26    external/libmpeg2
27    external/libopus
28    external/libvpx
29    external/libxaac
30    external/sonivox
31    external/tremolo
32)
33
34DEV_BRANCH=qt-aml-media-dev
35RED=$(tput setaf 1)
36NORMAL=$(tput sgr0)
37WARNING_FULL="${RED}Please upload this change in ${DEV_BRANCH} unless it is restricted
38from mainline release until next dessert release. Low/moderate security bugs
39are restricted this way.${NORMAL}"
40WARNING_PARTIAL="${RED}It looks like your change has mainline and non-mainline changes;
41Consider separating them into two separate CLs -- one for mainline files,
42one for non-mainline files.${NORMAL}"
43PWD=`pwd`
44
45if git branch -vv | grep -q -P "^\*[^\[]+\[goog/qt-aml-media-dev"; then
46    # Change appears to be in mainline dev branch
47    exit 0
48fi
49
50for path in "${MAINLINE_EXTERNAL_PROJECTS[@]}"; do
51    if [[ $PWD =~ $path ]]; then
52        echo -e "${RED}The source of truth for '$path' is in ${DEV_BRANCH}.${NORMAL}"
53        echo -e ${WARNING_FULL}
54        exit 1
55    fi
56done
57
58if [[ ! $PWD =~ frameworks/av ]]; then
59    exit 0
60fi
61
62mainline_count=0
63total_count=0
64echo
65while read -r file ; do
66    (( total_count++ ))
67    for path in "${MAINLINE_FRAMEWORKS_AV_PATHS[@]}"; do
68        if [[ $file =~ ^$path ]]; then
69            echo -e "${RED}The source of truth for '$file' is in ${DEV_BRANCH}.${NORMAL}"
70            (( mainline_count++ ))
71            break
72        fi
73    done
74done < <(git show --name-only --pretty=format: $1 | grep -- "$2")
75
76if (( mainline_count != 0 )); then
77    if (( mainline_count == total_count )); then
78        echo -e ${WARNING_FULL}
79    else
80        echo -e ${WARNING_PARTIAL}
81    fi
82    exit 1
83fi
84exit 0
85