Skip to content

Commit

Permalink
[infra] Improve srcmap support for Go projects (#3355, #2714). (#3664)
Browse files Browse the repository at this point in the history
* [infra] Improve srcmap support for Go projects (#3355, #2714).

* address review feedback
  • Loading branch information
Dor1s authored Apr 17, 2020
1 parent 1dae0c2 commit 8ed2f7a
Show file tree
Hide file tree
Showing 4 changed files with 56 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 @@ -71,35 +71,10 @@ def get_build_steps(project_dir):
dockerfile_path = os.path.join(project_dir, 'Dockerfile')
name = project_yaml['name']
image = project_yaml['image']
language = project_yaml['language']
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, 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
47 changes: 12 additions & 35 deletions infra/gcb/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,45 +109,22 @@ def get_build_steps(project_dir):
dockerfile_path = os.path.join(project_dir, 'Dockerfile')
name = project_yaml['name']
image = project_yaml['image']
language = project_yaml['language']
run_tests = project_yaml['run_tests']

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, language)

# Copy over MSan instrumented libraries.
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 8ed2f7a

Please sign in to comment.