-
Notifications
You must be signed in to change notification settings - Fork 16
/
self_contained_repro.sh
executable file
·72 lines (62 loc) · 1.28 KB
/
self_contained_repro.sh
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
#!/bin/bash
set -eux
bazel version
rm -rf build
mkdir build && cd build
# Create external repository.
mkdir repo && pushd repo
cat > WORKSPACE <<EOF
workspace(name = "repo")
EOF
cat > BUILD <<EOF
py_library(
name = "repo_py",
deps = ["//repo"],
visibility = ["//visibility:public"],
)
EOF
# Simulate nested Python package with same name as parent.
mkdir repo && cd repo
cat > BUILD <<EOF
py_library(
name = "repo",
srcs = ["__init__.py"],
imports = [".."],
visibility = ["//:__pkg__"],
)
EOF
cat > __init__.py <<EOF
my_special_symbol = 1
EOF
popd
mkdir example && pushd example
cat > WORKSPACE <<EOF
workspace(name = "example")
local_repository(
name = "repo",
path = "../repo",
)
EOF
cat > BUILD <<EOF
py_binary(
name = "example_consuming_repo",
srcs = ["example_consuming_repo.py"],
deps = ["@repo//:repo_py"],
)
EOF
cat > print_paths.py <<EOF
EOF
cat > example_consuming_repo.py <<EOF
# print paths
import os, re, sys
def reformat(x):
source = os.path.dirname(os.path.realpath(__file__))
x = x.replace(source, "{source}")
x = re.sub(r"^/.*?\.runfiles", "{runfiles}", x)
return x
print("\n".join(reformat(x) for x in sys.path))
# try import
from repo import my_special_symbol
EOF
echo "---"
bazel run -s //:example_consuming_repo