Lines Matching +full:ninja +full:- +full:bin
1 #!/bin/bash
3 set -eu
11 # http://www.apache.org/licenses/LICENSE-2.0
19 # Tool to evaluate the transitive closure of the ninja dependency graph of the
28 Evaluate the transitive closure of files and ninja targets that one or more
33 -(no)order_deps Whether to include order-only dependencies. (Default false)
34 -(no)implicit Whether to include implicit dependencies. (Default true)
35 -(no)explicit Whether to include regular / explicit deps. (Default true)
37 -nofollow Unanchored regular expression. Matching paths and targets
41 e.g. -nofollow='*.so' not -nofollow='.so$'
42 -nofollow='*.so|*.dex' or -nofollow='*.so' -nofollow='.dex'
44 -container Unanchored regular expression. Matching file extensions get
45 treated as 'container' files for -nofollow option.
51 -(no)quiet Suppresses progress output to stderr and interactive
52 alias -(no)q prompts. By default, when stderr is a tty, progress gets
57 -sep=<delim> Use 'delim' as output field separator between notice
61 -csv Shorthand for -sep=','
62 -directories=<f> Output directory names of dependencies to 'f'.
63 alias -d User '/dev/stdout' to send directories to stdout. Defaults
65 -notices=<file> Output license and notice file paths to 'file'.
66 alias -n Use '/dev/stdout' to send notices to stdout. Defaults to no
68 -projects=<file> Output git project names to 'file'. Use '/dev/stdout' to
69 alias -p send projects to stdout. Defaults to no project output.
70 -targets=<fils> Output target dependencies to 'file'. Use '/dev/stdout' to
71 alias -t send targets to stdout.
80 to setup the build environment, choose a target platform, and build the ninja
84 function die() { echo -e "${*}" >&2; exit 2; }
88 # output target is a ninja target that the input target depends on
91 (tr '\n' '\0' | xargs -0 -r "${ninja_bin}" -f "${ninja_file}" -t query) \
92 | awk -v include_order="${include_order_deps}" \
93 -v include_implicit="${include_implicit_deps}" \
94 -v include_explicit="${include_deps}" \
95 -v containers="${container_types}" \
153 if [ -d "${d}/.git/" ]; then
159 done | sort -u
163 if [ -z "${ANDROID_BUILD_TOP}" ]; then
167 if [ -z "${TARGET_PRODUCT}" ]; then
171 readonly ninja_file="${ANDROID_BUILD_TOP}/out/combined-${TARGET_PRODUCT}.ninja"
172 if [ ! -f "${ninja_file}" ]; then
176 readonly ninja_bin="${ANDROID_BUILD_TOP}/prebuilts/build-tools/linux-x86/bin/ninja"
177 if [ ! -x "${ninja_bin}" ]; then
178 die "${me}: Cannot find ninja executable expected at ${ninja_bin}"
182 # parse the command-line
184 declare -a targets # one or more targets to evaluate
203 use_stdin=false # whether to read targets from stdin i.e. target -
205 while [ $# -gt 0 ]; do
206 case "${1:-}" in
207 -)
210 -*)
211 flag=$(expr "${1}" : '^-*\(.*\)$')
212 case "${flag:-}" in
287 targets+=("${1:-}")
294 # fail fast if command-line arguments are invalid
296 if [ ! -v targets[0] ] && ! ${use_stdin}; then
300 if [ -z "${projects_out}" ] \
301 && [ -z "${directories_out}" ] \
302 && [ -z "${targets_out}" ] \
303 && [ -z "${notices_out}" ]
308 if [ -z "${container_types}" ]; then
313 if [ -t 2 ] && ! ${quiet}; then
320 if ${showProgress} && [ -t 0 ]; then
327 readonly tmpFiles=$(mktemp -d "${TMPDIR}.tdeps.XXXXXXXXX")
328 if [ -z "${tmpFiles}" ]; then
333 # isnotice in {0,1} with 1 when ninja target 'target' is a license or notice.
351 # extend deps by appending targets from command-line
365 sort -u < "${newDeps}" > "${allDeps}"
374 while [ $(wc -l < "${newDeps}") -gt 0 ]; do
376 echo "depth ${depth} has "$(wc -l < "${newDeps}")" targets" >&2
381 sh -c "${filter}" < "${newDeps}" | cut -d\ -f3- | getDeps
382 set -e
384 ) | sort -u > "${allDeps}"
387 diff "${oldDeps}" "${allDeps}" --old-line-format='' --new-line-format='%L' \
388 --unchanged-line-format='' > "${newDeps}"
389 set -e
395 filter="egrep -v '^[01] 0 (${nofollow})$'"
402 # found all deps -- clean up last iteration of old and new
403 rm -f "${oldDeps}"
404 rm -f "${newDeps}"
407 echo $(wc -l < "${allDeps}")" targets" >&2
410 if [ -n "${targets_out}" ]; then
411 cut -d\ -f3- "${allDeps}" | sort -u > "${targets_out}"
414 if [ -n "${directories_out}" ] \
415 || [ -n "${projects_out}" ] \
416 || [ -n "${notices_out}" ]
420 cut -d\ -f3- "${allDeps}" | tr '\n' '\0' | xargs -0 dirname
421 ) | sort -u > "${allDirs}"
423 echo $(wc -l < "${allDirs}")" directories" >&2
434 if [ -n "${projects_out}" ] \
435 || [ -n "${notices_out}" ]
439 egrep -v '^out[/]' "${allDirs}" | getProjects > "${allProj}"
440 set -e
442 echo $(wc -l < "${allProj}")" projects" >&2
458 egrep '^1' "${allDeps}" | cut -d\ -f3- | egrep -v '^out/' > "${allNotice}"
459 set -e
462 if [ -f "${proj}/${f}" ]; then
468 echo $(cat "${allNotice}" | sort -u | wc -l)" notice targets" >&2
473 sort -u "${allNotice}" | tr '\n' '\0' | xargs -0 -r md5sum 2>/dev/null
474 set -e
478 echo $(cut -d\ -f2- "${hashedNotice}" | sort -u | wc -l)" notice files" >&2
479 echo $(cut -d\ -f1 "${hashedNotice}" | sort -u | wc -l)" distinct notices" >&2
486 echo -n "$(date '+%F %-k:%M:%S') Delete ${tmpFiles} ? [n] " >&2
488 case "${answer}" in [yY]*) rm -fr "${tmpFiles}";; esac
490 rm -fr "${tmpFiles}"