File: ninja_symlink_outputs.sh

package info (click to toggle)
android-platform-build-kati 10.0.0%2Br32%2Bgit20220314.09dfa26c4e59-7.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,628 kB
  • sloc: cpp: 10,340; sh: 1,087; python: 85; makefile: 46
file content (76 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#
# Copyright 2020 Google Inc. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

mk="$@"

cat <<EOF >Makefile
dangling_symlink:
	ln -sf nil dangling_symlink
dangling_symlink: .KATI_SYMLINK_OUTPUTS := dangling_symlink

file:
	touch file

resolved_symlink: file
	ln -sf file resolved_symlink
resolved_symlink: .KATI_SYMLINK_OUTPUTS := resolved_symlink

incorrectly_declared_symlink:
	ln -sf nil incorrectly_declared_symlink
incorrectly_declared_symlink: .KATI_SYMLINK_OUTPUTS := something_else

foo bar: file
	ln -sf file foo && cp foo bar
foo: .KATI_SYMLINK_OUTPUTS := foo
bar: .KATI_SYMLINK_OUTPUTS := bar
EOF

all="dangling_symlink resolved_symlink foo bar"
if echo "${mk}" | grep kati > /dev/null; then
  mk="${mk} --use_ninja_symlink_outputs"
fi
${mk} -j1 $all

if [ -e ninja.sh ]; then
  ./ninja.sh -j1 $all

  if ! grep -A1 "build dangling_symlink:" build.ninja | grep -q "symlink_outputs = dangling_symlink"; then
    echo "symlink_outputs not present for dangling_symlink in build.ninja"
  fi
  if ! grep -A1 "build resolved_symlink:" build.ninja | grep -q "symlink_outputs = resolved_symlink"; then
    echo "symlink_outputs not present for resolved_symlink in build.ninja"
  fi
  if grep -A1 "build file:" build.ninja | grep -q "symlink_outputs ="; then
    echo "unexpected symlink_outputs present for file in build.ninja"
  fi

  # Even though this was a multi-output Make rule, Kati generates individual build
  # statements for each of the outputs, therefore the symlink_outputs list is a singleton.
  if ! grep -A1 "build foo: rule" build.ninja | grep -q "symlink_outputs = foo"; then
    echo "symlink_outputs not present for foo in build.ninja"
  fi
  if ! grep -A1 "build bar: rule" build.ninja | grep -q "symlink_outputs = bar"; then
    echo "symlink_outputs not present for bar in build.ninja"
  fi

  ${mk} -j1 "incorrectly_declared_symlink" 2> kati.err
  # The actual error message contains the line number in the Makefile.
  if ! grep "Makefile:" kati.err | grep "undeclared symlink output: something_else"; then
    echo "did not get undeclared symlink out error message"
  fi
fi