1#!/usr/bin/env python 2 3# Copyright (c) 2012 Google Inc. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7""" 8Verifies build of a static_library with the standalone_static_library flag set. 9""" 10 11import os 12import subprocess 13import sys 14import TestGyp 15 16# standalone_static_library currently means two things: a specific output 17# location for the built target and non-thin archive files. 18test = TestGyp.TestGyp() 19 20# Verify that types other than static_library cause a failure. 21test.run_gyp('invalid.gyp', status=1, stderr=None) 22target_str = 'invalid.gyp:bad#target' 23err = ['gyp: Target %s has type executable but standalone_static_library flag ' 24 'is only valid for static_library type.' % target_str] 25test.must_contain_all_lines(test.stderr(), err) 26 27# Build a valid standalone_static_library. 28test.run_gyp('mylib.gyp') 29test.build('mylib.gyp', target='prog') 30 31# Verify that the static library is copied to the correct location. 32# We expect the library to be copied to $PRODUCT_DIR. 33standalone_static_library_dir = test.EXECUTABLE 34path_to_lib = os.path.split( 35 test.built_file_path('mylib', type=standalone_static_library_dir))[0] 36lib_name = test.built_file_basename('mylib', type=test.STATIC_LIB) 37path = os.path.join(path_to_lib, lib_name) 38test.must_exist(path) 39 40# Verify that the program runs properly. 41expect = 'hello from mylib.c\n' 42test.run_built_executable('prog', stdout=expect) 43 44# Verify that libmylib.a contains symbols. "ar -x" fails on a 'thin' archive. 45supports_thick = ('make', 'ninja', 'cmake') 46if test.format in supports_thick and sys.platform.startswith('linux'): 47 retcode = subprocess.call(['ar', '-x', path]) 48 assert retcode == 0 49 50test.pass_test() 51