Skip to content

Commit 9710fdf

Browse files
DellaBittaa-maurice
authored andcommitted
Cmake gtest build support for iOS.
- Added a new test_mac_ios_simulator build script. This builds in its own subdirectory separate from test_mac_ios.sh. - Simulator target builds for the x86 arch. - Added new objective c test runner to execute tests on iOS. - Cmake builds hte runner as an unsigned .app file and can be deployed on iphone simulators. - Updated cc_test_on_ios cmake functions to leverage the test runner as an execution HOST. These targets now build xctest files which are embedded in the test runner .app file. - Removed the cctest execution at the end of the ios build scripts, which is incongruent with test execution flow on ios simulators. Note that the tests still can't be executed as the Info.plist files are not be injected with the proper key values. PiperOrigin-RevId: 294685221
1 parent c0f6fb0 commit 9710fdf

12 files changed

+380
-71
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2020 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "UIKit/UIKit.h"
18+
19+
@interface FIRAppDelegate : UIResponder <UIApplicationDelegate>
20+
21+
@property(strong, nonatomic) UIWindow *window;
22+
23+
@end
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2020 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "FIRAppDelegate.h"
18+
19+
@implementation FIRAppDelegate
20+
21+
- (BOOL)application:(UIApplication *)application
22+
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
23+
// Override point for customization after application launch.
24+
return YES;
25+
}
26+
27+
- (void)applicationWillResignActive:(UIApplication *)application {
28+
// Sent when the application is about to move from active to inactive state. This can occur for
29+
// certain types of temporary interruptions (such as an incoming phone call or SMS message) or
30+
// when the user quits the application and it begins the transition to the background state. Use
31+
// this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates.
32+
// Games should use this method to pause the game.
33+
}
34+
35+
- (void)applicationDidEnterBackground:(UIApplication *)application {
36+
// Use this method to release shared resources, save user data, invalidate timers, and store
37+
// enough application state information to restore your application to its current state in case
38+
// it is terminated later. If your application supports background execution, this method is
39+
// called instead of applicationWillTerminate: when the user quits.
40+
}
41+
42+
- (void)applicationWillEnterForeground:(UIApplication *)application {
43+
// Called as part of the transition from the background to the inactive state; here you can undo
44+
// many of the changes made on entering the background.
45+
}
46+
47+
- (void)applicationDidBecomeActive:(UIApplication *)application {
48+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If
49+
// the application was previously in the background, optionally refresh the user interface.
50+
}
51+
52+
- (void)applicationWillTerminate:(UIApplication *)application {
53+
// Called when the application is about to terminate. Save data if appropriate. See also
54+
// applicationDidEnterBackground:.
55+
}
56+
57+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2020 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "UIKit/UIKit.h"
18+
19+
@interface FIRViewController : UIViewController
20+
21+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "FIRViewController.h"
18+
19+
@interface FIRViewController ()
20+
21+
@end
22+
23+
@implementation FIRViewController
24+
25+
- (void)viewDidLoad {
26+
[super viewDidLoad];
27+
// Do any additional setup after loading the view, typically from a nib.
28+
}
29+
30+
- (void)didReceiveMemoryWarning {
31+
[super didReceiveMemoryWarning];
32+
// Dispose of any resources that can be recreated.
33+
}
34+
35+
@end

app/src/tests/runner/ios/Info.plist

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>${PRODUCT_NAME}</string>
9+
<key>CFBundleExecutable</key>
10+
<string>${EXECUTABLE_NAME}</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>${PRODUCT_NAME}</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSignature</key>
22+
<string>????</string>
23+
<key>CFBundleVersion</key>
24+
<string>1.0</string>
25+
<key>LSRequiresIPhoneOS</key>
26+
<true/>
27+
<key>UILaunchStoryboardName</key>
28+
<string>LaunchScreen</string>
29+
<key>UIMainStoryboardFile</key>
30+
<string>Main</string>
31+
<key>UIRequiredDeviceCapabilities</key>
32+
<array>
33+
<string>armv7</string>
34+
</array>
35+
<key>UISupportedInterfaceOrientations</key>
36+
<array>
37+
<string>UIInterfaceOrientationPortrait</string>
38+
<string>UIInterfaceOrientationLandscapeLeft</string>
39+
<string>UIInterfaceOrientationLandscapeRight</string>
40+
</array>
41+
<key>UISupportedInterfaceOrientations~ipad</key>
42+
<array>
43+
<string>UIInterfaceOrientationPortrait</string>
44+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
45+
<string>UIInterfaceOrientationLandscapeLeft</string>
46+
<string>UIInterfaceOrientationLandscapeRight</string>
47+
</array>
48+
</dict>
49+
</plist>

app/src/tests/runner/ios/main.m

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2020 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "UIKit/UIKit.h"
18+
#include "FIRAppDelegate.h"
19+
20+
int main(int argc, char* argv[]) {
21+
@autoreleasepool {
22+
return UIApplicationMain(argc, argv, nil, NSStringFromClass([FIRAppDelegate class]));
23+
}
24+
}

cmake/FindASANDylib.cmake

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2020 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
if(APPLE AND CXX_CLANG)
16+
# Sanitizers in Clang are supported by a specific runtime and Clang
17+
# automatically links against the right runtime. When building staticly
18+
# linked binaries, the resulting binary will contain the runtime. Dynamically
19+
# linked binaries will link against the dynamic version of the library.
20+
#
21+
# xctest bundles are necessarily dynamicly linked, but linked in such a way
22+
# that the sanitizer runtime is assumed to be on the @rpath. This finds the
23+
# clang runtimes so that they can be supplied as needed.
24+
get_filename_component(compiler_bin_dir ${CMAKE_CXX_COMPILER} DIRECTORY)
25+
get_filename_component(compiler_dir ${compiler_bin_dir} DIRECTORY)
26+
27+
if(WITH_ASAN)
28+
file(
29+
GLOB_RECURSE CLANG_ASAN_DYLIB
30+
${compiler_dir}/libclang_rt.asan_osx_dynamic.dylib
31+
)
32+
endif()
33+
34+
if(WITH_TSAN)
35+
file(
36+
GLOB_RECURSE CLANG_TSAN_DYLIB
37+
${compiler_dir}/libclang_rt.tsan_osx_dynamic.dylib
38+
)
39+
endif()
40+
endif(APPLE AND CXX_CLANG)

0 commit comments

Comments
 (0)