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 that a postbuild copying a dependend framework into an app bundle is
9rerun if the resources in the framework change.
10"""
11
12import TestGyp
13
14import os.path
15import sys
16
17if sys.platform == 'darwin':
18  # TODO(thakis): Make this pass with the make generator, http://crbug.com/95529
19  test = TestGyp.TestGyp(formats=['ninja', 'xcode'])
20
21  CHDIR = 'postbuild-copy-bundle'
22  test.run_gyp('test.gyp', chdir=CHDIR)
23
24  app_bundle_dir = test.built_file_path('Test app.app', chdir=CHDIR)
25  bundled_framework_dir = os.path.join(
26      app_bundle_dir, 'Contents', 'My Framework.framework', 'Resources')
27  final_plist_path = os.path.join(bundled_framework_dir, 'Info.plist')
28  final_resource_path = os.path.join(bundled_framework_dir, 'resource_file.sb')
29  final_copies_path = os.path.join(
30      app_bundle_dir, 'Contents', 'My Framework.framework', 'Versions', 'A',
31      'Libraries', 'copied.txt')
32
33  # Check that the dependency was built and copied into the app bundle:
34  test.build('test.gyp', 'test_app', chdir=CHDIR)
35  test.must_exist(final_resource_path)
36  test.must_match(final_resource_path,
37                  'This is included in the framework bundle.\n')
38
39  test.must_exist(final_plist_path)
40  test.must_contain(final_plist_path, '''\
41\t<key>RandomKey</key>
42\t<string>RandomValue</string>''')
43
44  # Touch the dependency's bundle resource, and check that the modification
45  # makes it all the way into the app bundle:
46  test.sleep()
47  test.write('postbuild-copy-bundle/resource_file.sb', 'New text\n')
48  test.build('test.gyp', 'test_app', chdir=CHDIR)
49
50  test.must_exist(final_resource_path)
51  test.must_match(final_resource_path, 'New text\n')
52
53  # Check the same for the plist file.
54  test.sleep()
55  contents = test.read('postbuild-copy-bundle/Framework-Info.plist')
56  contents = contents.replace('RandomValue', 'NewRandomValue')
57  test.write('postbuild-copy-bundle/Framework-Info.plist', contents)
58  test.build('test.gyp', 'test_app', chdir=CHDIR)
59
60  test.must_exist(final_plist_path)
61  test.must_contain(final_plist_path, '''\
62\t<key>RandomKey</key>
63\t<string>NewRandomValue</string>''')
64
65  # Check the same for the copies section, test for http://crbug.com/157077
66  test.sleep()
67  contents = test.read('postbuild-copy-bundle/copied.txt')
68  contents = contents.replace('old', 'new')
69  test.write('postbuild-copy-bundle/copied.txt', contents)
70  test.build('test.gyp', 'test_app', chdir=CHDIR)
71
72  test.must_exist(final_copies_path)
73  test.must_contain(final_copies_path, 'new copied file')
74
75  test.pass_test()
76