14b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org#!/usr/bin/env python
24b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
34b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org# Copyright (c) 2012 Google Inc. All rights reserved.
44b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org# Use of this source code is governed by a BSD-style license that can be
54b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org# found in the LICENSE file.
64b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
74b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org"""
84b240ee841e2a615efe774042b455cb40d918334thakis@chromium.orgVerifies that a postbuild copying a dependend framework into an app bundle is
94b240ee841e2a615efe774042b455cb40d918334thakis@chromium.orgrerun if the resources in the framework change.
104b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org"""
114b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
124b240ee841e2a615efe774042b455cb40d918334thakis@chromium.orgimport TestGyp
134b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
144b240ee841e2a615efe774042b455cb40d918334thakis@chromium.orgimport os.path
154b240ee841e2a615efe774042b455cb40d918334thakis@chromium.orgimport sys
164b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
174b240ee841e2a615efe774042b455cb40d918334thakis@chromium.orgif sys.platform == 'darwin':
184b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  # TODO(thakis): Make this pass with the make generator, http://crbug.com/95529
19ecae04c143848a2a0247af1af0180fe0a19b1a77thakis@chromium.org  test = TestGyp.TestGyp(formats=['ninja', 'xcode'])
204b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
214b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  CHDIR = 'postbuild-copy-bundle'
224b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.run_gyp('test.gyp', chdir=CHDIR)
234b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
244b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  app_bundle_dir = test.built_file_path('Test app.app', chdir=CHDIR)
254b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  bundled_framework_dir = os.path.join(
264b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org      app_bundle_dir, 'Contents', 'My Framework.framework', 'Resources')
274b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  final_plist_path = os.path.join(bundled_framework_dir, 'Info.plist')
284b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  final_resource_path = os.path.join(bundled_framework_dir, 'resource_file.sb')
2959faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  final_copies_path = os.path.join(
3059faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org      app_bundle_dir, 'Contents', 'My Framework.framework', 'Versions', 'A',
3159faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org      'Libraries', 'copied.txt')
324b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
334b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  # Check that the dependency was built and copied into the app bundle:
344b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.build('test.gyp', 'test_app', chdir=CHDIR)
354b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.must_exist(final_resource_path)
364b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.must_match(final_resource_path,
374b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org                  'This is included in the framework bundle.\n')
384b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
394b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.must_exist(final_plist_path)
404b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.must_contain(final_plist_path, '''\
414b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org\t<key>RandomKey</key>
424b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org\t<string>RandomValue</string>''')
434b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
444b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  # Touch the dependency's bundle resource, and check that the modification
454b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  # makes it all the way into the app bundle:
464b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.sleep()
474b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.write('postbuild-copy-bundle/resource_file.sb', 'New text\n')
484b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.build('test.gyp', 'test_app', chdir=CHDIR)
494b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
504b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.must_exist(final_resource_path)
514b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.must_match(final_resource_path, 'New text\n')
524b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
534b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  # Check the same for the plist file.
544b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.sleep()
554b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  contents = test.read('postbuild-copy-bundle/Framework-Info.plist')
564b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  contents = contents.replace('RandomValue', 'NewRandomValue')
574b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.write('postbuild-copy-bundle/Framework-Info.plist', contents)
584b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.build('test.gyp', 'test_app', chdir=CHDIR)
594b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
604b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.must_exist(final_plist_path)
614b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.must_contain(final_plist_path, '''\
624b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org\t<key>RandomKey</key>
634b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org\t<string>NewRandomValue</string>''')
644b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org
6559faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  # Check the same for the copies section, test for http://crbug.com/157077
6659faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  test.sleep()
6759faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  contents = test.read('postbuild-copy-bundle/copied.txt')
6859faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  contents = contents.replace('old', 'new')
6959faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  test.write('postbuild-copy-bundle/copied.txt', contents)
7059faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  test.build('test.gyp', 'test_app', chdir=CHDIR)
7159faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org
7259faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  test.must_exist(final_copies_path)
7359faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org  test.must_contain(final_copies_path, 'new copied file')
7459faf13dc34ddce4d2572465e5cee4337a34470bthakis@chromium.org
754b240ee841e2a615efe774042b455cb40d918334thakis@chromium.org  test.pass_test()
76