Skip to content

Commit

Permalink
[infra] Improve srcmap support for Go projects (#3355, #2714).
Browse files Browse the repository at this point in the history
  • Loading branch information
Dor1s committed Apr 16, 2020
1 parent 5ed2a56 commit d69555c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 65 deletions.
12 changes: 9 additions & 3 deletions infra/base-images/base-builder/srcmap
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ function jq_inplace() {
F=$(tempfile) && cat $1 | jq "$2" > $F && mv $F $1
}

PATHS_TO_SCAN="$SRC"

if [[ $FUZZING_LANGUAGE == "go" ]]; then
PATHS_TO_SCAN="$PATHS_TO_SCAN $GOPATH"
fi

# Git
for DOT_GIT_DIR in $(find $SRC -name ".git" -type d); do
for DOT_GIT_DIR in $(find $PATHS_TO_SCAN -name ".git" -type d); do
GIT_DIR=$(dirname $DOT_GIT_DIR)
cd $GIT_DIR
GIT_URL=$(git config --get remote.origin.url)
Expand All @@ -35,7 +41,7 @@ for DOT_GIT_DIR in $(find $SRC -name ".git" -type d); do
done

# Subversion
for DOT_SVN_DIR in $(find $SRC -name ".svn" -type d); do
for DOT_SVN_DIR in $(find $PATHS_TO_SCAN -name ".svn" -type d); do
SVN_DIR=$(dirname $DOT_SVN_DIR)
cd $SVN_DIR
SVN_URL=$(svn info | grep "^URL:" | sed 's/URL: //g')
Expand All @@ -44,7 +50,7 @@ for DOT_SVN_DIR in $(find $SRC -name ".svn" -type d); do
done

# Mercurial
for DOT_HG_DIR in $(find $SRC -name ".hg" -type d); do
for DOT_HG_DIR in $(find $PATHS_TO_SCAN -name ".hg" -type d); do
HG_DIR=$(dirname $DOT_HG_DIR)
cd $HG_DIR
HG_URL=$(hg paths default)
Expand Down
29 changes: 2 additions & 27 deletions infra/gcb/build_and_run_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,8 @@ def get_build_steps(project_dir):
image = project_yaml['image']
report_date = datetime.datetime.now().strftime('%Y%m%d')

build_steps = [
{
'args': [
'clone',
'https://github.com/google/oss-fuzz.git',
],
'name': 'gcr.io/cloud-builders/git',
},
{
'name': 'gcr.io/cloud-builders/docker',
'args': [
'build',
'-t',
image,
'.',
],
'dir': 'oss-fuzz/projects/' + name,
},
{
'name': image,
'args': [
'bash', '-c',
'srcmap > /workspace/srcmap.json && cat /workspace/srcmap.json'
],
'env': ['OSSFUZZ_REVISION=$REVISION_ID'],
},
]
build_steps = build_lib.project_image_steps(name, image,
project_yaml['language'])

env = CONFIGURATION[:]
out = '/workspace/out/' + SANITIZER
Expand Down
33 changes: 33 additions & 0 deletions infra/gcb/build_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,36 @@ def gsutil_rm_rf_step(url):
],
}
return step


def project_image_steps(name, image, language):
"""Returns GCB steps to build OSS-Fuzz project image."""
steps = [{
'args': [
'clone',
'https://github.com/google/oss-fuzz.git',
],
'name': 'gcr.io/cloud-builders/git',
}, {
'name': 'gcr.io/cloud-builders/docker',
'args': [
'build',
'-t',
image,
'.',
],
'dir': 'oss-fuzz/projects/' + name,
}, {
'name':
image,
'args': [
'bash', '-c',
'srcmap > /workspace/srcmap.json && cat /workspace/srcmap.json'
],
'env': [
'OSSFUZZ_REVISION=$REVISION_ID',
'FUZZING_LANGUAGE=%s' % language,
],
}]

return steps
45 changes: 10 additions & 35 deletions infra/gcb/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,41 +113,16 @@ def get_build_steps(project_dir):

ts = datetime.datetime.now().strftime('%Y%m%d%H%M')

build_steps = [
{
'args': [
'clone',
'https://github.com/google/oss-fuzz.git',
],
'name': 'gcr.io/cloud-builders/git',
},
{
'name': 'gcr.io/cloud-builders/docker',
'args': [
'build',
'-t',
image,
'.',
],
'dir': 'oss-fuzz/projects/' + name,
},
{
'name': image,
'args': [
'bash', '-c',
'srcmap > /workspace/srcmap.json && cat /workspace/srcmap.json'
],
'env': ['OSSFUZZ_REVISION=$REVISION_ID'],
},
{
'name': 'gcr.io/oss-fuzz-base/msan-builder',
'args': [
'bash',
'-c',
'cp -r /msan /workspace',
],
},
]
build_steps = build_lib.project_image_steps(name, image,
project_yaml['language'])
build_steps.append({
'name': 'gcr.io/oss-fuzz-base/msan-builder',
'args': [
'bash',
'-c',
'cp -r /msan /workspace',
],
})

for fuzzing_engine in project_yaml['fuzzing_engines']:
for sanitizer in get_sanitizers(project_yaml):
Expand Down

0 comments on commit d69555c

Please sign in to comment.