blob: 060c711506b6e68bd77e9981fa2d65045663eb89 [file] [log] [blame]
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Shared utilities for the build recipe module."""
# This lists the products we want to isolate as outputs for future steps.
def py_to_gn(val):
"""Convert val to a string that can be used as GN args."""
if isinstance(val, bool):
return 'true' if val else 'false'
elif '%s' % val == val:
# TODO(dogben): Handle quoting "$\
return '"%s"' % val
elif isinstance(val, (list, tuple)):
return '[%s]' % (','.join(py_to_gn(x) for x in val))
elif isinstance(val, dict):
gn = ' '.join(
'%s=%s' % (k, py_to_gn(v)) for (k, v) in sorted(val.items()))
return gn
else: # pragma: nocover
raise Exception('Converting %s to gn is not implemented.' % type(val))
def copy_listed_files(api, src, dst, product_list):
"""Copy listed files src to dst."""
name='copy build products',
program='''import errno
import glob
import os
import shutil
import sys
src = sys.argv[1]
dst = sys.argv[2]
build_products = %s
except OSError as e:
if e.errno != errno.EEXIST:
for pattern in build_products:
path = os.path.join(src, pattern)
for f in glob.glob(path):
dst_path = os.path.join(dst, os.path.relpath(f, src))
if not os.path.isdir(os.path.dirname(dst_path)):
print('Copying build product %%s to %%s' %% (f, dst_path))
shutil.move(f, dst_path)
''' % str(product_list),
args=[src, dst],