Skip to content

Commit c7edd98

Browse files
committed
MVP for bazel support
Allows small strings to be consumed by bazel directly
1 parent a458e2e commit c7edd98

28 files changed

+621
-10
lines changed

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build --macos_minimum_os=13.0
2+
build --host_macos_minimum_os=13.0
3+
build --apple_platform_type=macos

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
compress # Ignore executable that gets compiled
2+
3+
bazel-*

BUILD.bazel

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
objc_library(
2+
name = "SSTSmallStrings",
3+
srcs = [
4+
"Source/SSTSmallStrings.m",
5+
],
6+
hdrs = [
7+
"Source/SSTSmallStrings.h",
8+
],
9+
sdk_dylibs = [
10+
"compression",
11+
],
12+
visibility = ["//visibility:public"],
13+
)
14+
15+
cc_binary(
16+
name = "compress",
17+
visibility = ["//visibility:public"],
18+
deps = [
19+
":compress_lib",
20+
],
21+
)
22+
23+
objc_library(
24+
name = "compress_lib",
25+
srcs = [
26+
"compress.m",
27+
],
28+
sdk_dylibs = [
29+
"compression",
30+
],
31+
)
32+
33+
cc_binary(
34+
name = "localize",
35+
data = [
36+
":compress",
37+
],
38+
visibility = ["//visibility:public"],
39+
deps = [
40+
":localize_lib",
41+
],
42+
)
43+
44+
objc_library(
45+
name = "localize_lib",
46+
srcs = [
47+
"localize.m",
48+
],
49+
)

Example/Localization/BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("//:localize.bzl", "localize")
2+
3+
localize(
4+
name = "localize_test",
5+
srcs = [
6+
"en.lproj/Localizable.strings",
7+
"es.lproj/Localizable.strings",
8+
],
9+
target_name = "example_Source_app_Sources",
10+
visibility = [
11+
"//Example/Source:__pkg__",
12+
],
13+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"string1" = "en_value1";
2+
"string2" = "en_value2";
3+
"string3" = "en_value3";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"string1" = "es_value1";
2+
"string2" = "es_value2";
3+
"string3" = "es_value3";

Example/Source/App.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <Foundation/Foundation.h>
2+
3+
@interface App : NSObject
4+
5+
+ (NSString *)fetchLocalizationValueForKey:(NSString *)key;
6+
7+
@end

Example/Source/App.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import "Example/Source/App.h"
2+
#import "Source/SSTSmallStrings.h"
3+
4+
@implementation App
5+
6+
+ (NSString *)fetchLocalizationValueForKey:(NSString *)key {
7+
return SSTStringForKeyWithBundleAndSubdirectoryAndTargetName(key, [NSBundle bundleForClass:[self class]], nil, @"example_Source_app_Sources");
8+
}
9+
10+
@end

Example/Source/AppDelegate.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import <UIKit/UIKit.h>
2+
3+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
4+
5+
@property (strong, nonatomic) UIWindow *window;
6+
7+
@end

Example/Source/AppDelegate.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import "Example/Source/AppDelegate.h"
2+
#import "Source/SSTSmallStrings.h"
3+
4+
@implementation AppDelegate
5+
6+
- (BOOL)application:(UIApplication *)application
7+
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
8+
return YES;
9+
}
10+
11+
@end

Example/Source/AppTest.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import "Example/Source/App.h"
2+
#import <XCTest/XCTest.h>
3+
4+
@interface AppTest : XCTestCase
5+
@end
6+
7+
@implementation AppTest
8+
9+
- (void)testLocalization {
10+
XCTAssertTrue([@"en_value1" isEqual:[App fetchLocalizationValueForKey:@"string1"]]);
11+
XCTAssertTrue([@"does_not_exist" isEqual:[App fetchLocalizationValueForKey:@"does_not_exist"]]);
12+
}
13+
14+
@end

Example/Source/BUILD

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
load(
2+
"@build_bazel_rules_apple//apple:ios.bzl",
3+
"ios_application",
4+
"ios_unit_test",
5+
)
6+
7+
objc_library(
8+
name = "Sources",
9+
srcs = [
10+
"App.m",
11+
"AppDelegate.m",
12+
"main.m",
13+
],
14+
hdrs = [
15+
"App.h",
16+
"AppDelegate.h",
17+
],
18+
data = [
19+
"//Example/Localization:localize_test",
20+
],
21+
deps = [
22+
"//:SSTSmallStrings",
23+
],
24+
)
25+
26+
objc_library(
27+
name = "app_test_lib",
28+
testonly = True,
29+
srcs = [
30+
"AppTest.m",
31+
],
32+
deps = [
33+
":Sources",
34+
],
35+
)
36+
37+
ios_unit_test(
38+
name = "app_test",
39+
minimum_os_version = "16.0",
40+
deps = [
41+
":app_test_lib",
42+
],
43+
)
44+
45+
ios_application(
46+
name = "LocalizationExampleApp",
47+
bundle_id = "com.example.localization-example",
48+
families = [
49+
"iphone",
50+
],
51+
infoplists = [":Info.plist"],
52+
minimum_os_version = "16.0",
53+
deps = [":Sources"],
54+
)

Example/Source/Info.plist

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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>CFBundleVersion</key>
8+
<string>10000000</string>
9+
<key>CFBundleShortVersionString</key>
10+
<string>1.0.0</string>
11+
<key>CFBundleExecutable</key>
12+
<string>$(EXECUTABLE_NAME)</string>
13+
<key>CFBundleIdentifier</key>
14+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
15+
<key>CFBundleInfoDictionaryVersion</key>
16+
<string>6.0</string>
17+
<key>CFBundleName</key>
18+
<string>$(PRODUCT_NAME)</string>
19+
<key>CFBundlePackageType</key>
20+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
21+
<key>LSRequiresIPhoneOS</key>
22+
<true/>
23+
<key>UIRequiredDeviceCapabilities</key>
24+
<array>
25+
<string>armv7</string>
26+
</array>
27+
<key>UISupportedInterfaceOrientations</key>
28+
<array>
29+
<string>UIInterfaceOrientationPortrait</string>
30+
<string>UIInterfaceOrientationLandscapeLeft</string>
31+
<string>UIInterfaceOrientationLandscapeRight</string>
32+
</array>
33+
</dict>
34+
</plist>

Example/Source/Module/BUILD

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
load(
2+
"@build_bazel_rules_apple//apple:ios.bzl",
3+
"ios_unit_test",
4+
)
5+
6+
objc_library(
7+
name = "module",
8+
srcs = ["Module.m"],
9+
hdrs = ["Module.h"],
10+
data = [
11+
"//Example/Source/Module/Localization:localizations",
12+
],
13+
deps = [
14+
"//:SSTSmallStrings",
15+
],
16+
)
17+
18+
objc_library(
19+
name = "module_test_lib",
20+
testonly = True,
21+
srcs = ["ModuleTest.m"],
22+
deps = [
23+
":module",
24+
],
25+
)
26+
27+
ios_unit_test(
28+
name = "module_test",
29+
minimum_os_version = "16.0",
30+
deps = [
31+
":module_test_lib",
32+
],
33+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
load("//:localize.bzl", "localize")
2+
3+
localize(
4+
name = "localize_module_test",
5+
srcs = [
6+
"en.lproj/Localizable.strings",
7+
"es.lproj/Localizable.strings",
8+
],
9+
target_name = "example_Source_Module_module",
10+
visibility = [
11+
"//Example/Source/Module:__pkg__",
12+
],
13+
)
14+
15+
filegroup(
16+
name = "localizations",
17+
srcs = [
18+
"en.lproj/Localizable.stringsdict",
19+
"es.lproj/Localizable.stringsdict",
20+
":localize_module_test",
21+
],
22+
visibility = [
23+
"//Example/Source/Module:__pkg__",
24+
],
25+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"string1" = "en_module_value1";
2+
"string2" = "en_module_value2";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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>string1_stringdict</key>
6+
<dict>
7+
<key>NSStringLocalizedFormatKey</key>
8+
<string>string1_stringdict_en %#@formattedValue@</string>
9+
<key>formattedValue</key>
10+
<dict>
11+
<key>NSStringFormatSpecTypeKey</key>
12+
<string>NSStringPluralRuleType</string>
13+
<key>NSStringFormatValueTypeKey</key>
14+
<string>zd</string>
15+
<key>one</key>
16+
<string>%1$zd thing</string>
17+
<key>other</key>
18+
<string>%1$zd things</string>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"string1" = "es_module_value1";
2+
"string2" = "es_module_value2";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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>string1_stringdict</key>
6+
<dict>
7+
<key>NSStringLocalizedFormatKey</key>
8+
<string>string1_stringdict_es %#@formattedValue@</string>
9+
<key>formattedValue</key>
10+
<dict>
11+
<key>NSStringFormatSpecTypeKey</key>
12+
<string>NSStringPluralRuleType</string>
13+
<key>NSStringFormatValueTypeKey</key>
14+
<string>zd</string>
15+
<key>one</key>
16+
<string>%1$zd thing</string>
17+
<key>other</key>
18+
<string>%1$zd things</string>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>

Example/Source/Module/Module.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <Foundation/Foundation.h>
2+
3+
@interface Module : NSObject
4+
5+
+ (NSString *)fetchLocalizationValueForKey:(NSString *)key;
6+
7+
@end

Example/Source/Module/Module.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import "Example/Source/Module/Module.h"
2+
#import "Source/SSTSmallStrings.h"
3+
4+
@implementation Module
5+
6+
+ (NSString *)fetchLocalizationValueForKey:(NSString *)key {
7+
return SSTStringForKeyWithBundleAndSubdirectoryAndTargetName(key, [NSBundle bundleForClass:[self class]], nil, @"example_Source_Module_module");
8+
}
9+
10+
@end

Example/Source/Module/ModuleTest.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import <XCTest/XCTest.h>
2+
#import "Example/Source/Module/Module.h"
3+
4+
@interface ModuleTest : XCTestCase
5+
@end
6+
7+
@implementation ModuleTest
8+
9+
- (void)testLocalization {
10+
XCTAssertTrue([@"en_module_value1" isEqual:[Module fetchLocalizationValueForKey:@"string1"]]);
11+
XCTAssertTrue([@"does_not_exist" isEqual:[Module fetchLocalizationValueForKey:@"does_not_exist"]]);
12+
}
13+
14+
@end

Example/Source/main.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import <UIKit/UIKit.h>
2+
3+
#import "Example/Source/AppDelegate.h"
4+
5+
int main(int argc, char *argv[]) {
6+
@autoreleasepool {
7+
return UIApplicationMain(argc, argv, nil,
8+
NSStringFromClass([AppDelegate class]));
9+
}
10+
}

Source/SSTSmallStrings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#import <Foundation/Foundation.h>
22

33
NSString *SSTStringForKey(NSString *key);
4+
NSString *SSTStringForKeyWithBundle(NSString *key, NSBundle *bundle);
5+
NSString *SSTStringForKeyWithBundleAndSubdirectory(NSString *key, NSBundle *bundle, NSString *subdirectory);
6+
NSString *SSTStringForKeyWithBundleAndSubdirectoryAndTargetName(NSString *key, NSBundle *bundle, NSString *subdirectory, NSString *targetName);

0 commit comments

Comments
 (0)