File size: 3,912 Bytes
0e239c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Build actual candidate Istio and grpc-xds sources offline; no source shims."""
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import time

H = Path(__file__).resolve().parent
R = Path('/tmp/crossrepo-ab04-runtime')
A = Path('/artifacts')
I = Path('/testbed/istio/istio')
G = Path('/testbed/grpc/grpc-java')
receipt = A / 'ab04-runtime-build-receipt.json'
sha = lambda p: hashlib.sha256(p.read_bytes()).hexdigest()
if receipt.exists():
    print(receipt.read_text())
    raise SystemExit(0)
R.mkdir(parents=True, exist_ok=True)
A.mkdir(parents=True, exist_ok=True)
target = I / 'pilot/pkg/networking/core/crossrepo_ab04_routes_test.go'
assert not target.exists(), 'refuse to overwrite a candidate file'
shutil.copyfile(H / 'ab04_routes_test.go', target)
env = os.environ.copy()
env.update(GOPROXY='off', GOSUMDB='off', GOFLAGS='-p=2', GOMAXPROCS='2')
commands = []
def run(cmd, cwd, label):
    before = time.time()
    p = subprocess.run(cmd, cwd=cwd, env=env, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=1800)
    path = A / ('ab04-build-' + label + '.log')
    path.write_text(p.stdout)
    print(p.stdout, flush=True)
    commands.append({'cmd':cmd,'cwd':str(cwd),'returncode':p.returncode,'seconds':time.time()-before,'log_sha256':sha(path)})
    if p.returncode:
        (A/'ab04-runtime-build-failure.json').write_text(json.dumps(commands,indent=2)+'\n')
        raise SystemExit(p.returncode)

run(['go','test','-c','-o',str(R/'istio.test'),'./pilot/pkg/networking/core'],I,'istio')
run(['./gradlew','--offline','--no-daemon','--no-build-cache','--max-workers=2','-PskipAndroid=true','-PskipCodegen=true','-I',str(H/'ab04.init.gradle'),':grpc-xds:ab04Classpath'],G,'grpc')
classpath = (R/'classpath.txt').read_text().strip()
assert classpath and str(G/'xds/build/classes/java/main') in classpath
(R/'consumer').mkdir(exist_ok=True)
run(['javac','-cp',classpath,'-d',str(R/'consumer'),str(H/'AB04Consumer.java')],G,'consumer')

def output(cmd, cwd=None):
    return subprocess.check_output(cmd,cwd=cwd,stderr=subprocess.STDOUT).decode()

source_files = {str(p.relative_to(G)):sha(p) for p in sorted((G/'xds/src/main/java').rglob('*.java'))}
class_files = {str(p.relative_to(G)):sha(p) for p in sorted((G/'xds/build/classes/java/main').rglob('*.class'))}
assert source_files and class_files
data = {
    'network':'none','commands':commands,
    'go_version':output(['go','version']).strip(),
    'java_version':output(['java','-version']).strip(),
    'istio_head':output(['git','rev-parse','HEAD'],I).strip(),
    'grpc_head':output(['git','rev-parse','HEAD'],G).strip(),
    'istio_worktree_diff_sha256':hashlib.sha256(subprocess.check_output(['git','diff','--binary','HEAD'],cwd=I)).hexdigest(),
    'grpc_worktree_diff_sha256':hashlib.sha256(subprocess.check_output(['git','diff','--binary','HEAD'],cwd=G)).hexdigest(),
    'harness_sha256':{p.name:sha(p) for p in sorted(H.iterdir()) if p.is_file()},
    'istio_test_binary_sha256':sha(R/'istio.test'),
    'consumer_class_sha256':sha(R/'consumer/io/grpc/xds/AB04Consumer.class'),
    'classpath_sha256':sha(R/'classpath.txt'),
    'grpc_xds_source_files':source_files,
    'grpc_xds_compiled_class_files':class_files,
    'production_compilation':'Gradle grpc-xds compileJava forced out of up-to-date mode; cache disabled. Go test binary builds from current candidate sources.',
    'old_test_exclusion':'No original test patch is applied. Java harness is independently compiled against rebuilt production classes; original test-suite source is not compiled.',
}
shutil.copyfile(R/'classpath.txt',A/'ab04-classpath.txt')
receipt.write_text(json.dumps(data,indent=2)+'\n')
print(json.dumps({'receipt_sha256':sha(receipt),'grpc_source_count':len(source_files),'grpc_class_count':len(class_files),'istio_binary_sha256':data['istio_test_binary_sha256']}))