blob: 45c1160e231df71df46fa07082c8b3d830d94c22 [file] [log] [blame]
#!/usr/bin/env python3.8
# Copyright 2020 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Update golden files for GN SDK for use in tests.
Executes against the testdata/ directory and copies the output to
the golden directory. Run this after making changes to generator code and
include the updated files in your commit.
import generate
import os
import shutil
import sys
import tempfile
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
GOLDEN_DIR = os.path.join(SCRIPT_DIR, 'golden')
TMP_DIR_NAME = tempfile.mkdtemp(prefix='tmp_gn_sdk_golden')
def main():
testdata = os.path.join(SCRIPT_DIR, 'testdata')
# Generator follows bash convention and returns a non-zero value on error.
if generate.run_generator(output=TMP_DIR_NAME,
print(' returned an error')
return 1
# Remove the existing files.
if os.path.exists(GOLDEN_DIR):
# Ignore bin and build, which are copied from base.
shutil.copytree(src=TMP_DIR_NAME, dst=GOLDEN_DIR,
ignore=shutil.ignore_patterns('bin', 'build'))
# Special case: copy build/test_targets.gni from outdir
golden_build = os.path.join(GOLDEN_DIR, 'build')
shutil.copy2(src=os.path.join(TMP_DIR_NAME, 'build', 'test_targets.gni'),
# Cleanup.
if os.path.exists(TMP_DIR_NAME):
return 0
if __name__ == '__main__':