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"""
8Verify that relinking a solib doesn't relink a dependent executable if the
9solib's public API hasn't changed.
10"""
11
12import os
13import sys
14import TestCommon
15import TestGyp
16
17# NOTE(fischman): This test will not work with other generators because the
18# API-hash-based-mtime-preservation optimization is only implemented in
19# ninja.py.  It could be extended to the make.py generator as well pretty
20# easily, probably.
21# (also, it tests ninja-specific out paths, which would have to be generalized
22# if this was extended to other generators).
23test = TestGyp.TestGyp(formats=['ninja'])
24
25test.run_gyp('solibs_avoid_relinking.gyp')
26
27# Build the executable, grab its timestamp, touch the solib's source, rebuild
28# executable, ensure timestamp hasn't changed.
29test.build('solibs_avoid_relinking.gyp', 'b')
30test.built_file_must_exist('b' + TestCommon.exe_suffix)
31pre_stat = os.stat(test.built_file_path('b' + TestCommon.exe_suffix))
32os.utime(os.path.join(test.workdir, 'solib.cc'),
33         (pre_stat.st_atime, pre_stat.st_mtime + 100))
34test.sleep()
35test.build('solibs_avoid_relinking.gyp', 'b')
36post_stat = os.stat(test.built_file_path('b' + TestCommon.exe_suffix))
37
38if pre_stat.st_mtime != post_stat.st_mtime:
39  test.fail_test()
40else:
41  test.pass_test()
42