diff --git a/.gitignore b/.gitignore index 2faf68e..81a3fe3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +bazel-* +.kokoro-ios-runner + # Xcode # # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore diff --git a/.kokoro b/.kokoro new file mode 100755 index 0000000..3ad57df --- /dev/null +++ b/.kokoro @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Copyright 2017-present The Material Foundation Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Fail on any error. +set -e + +# Display commands to stderr. +set -x + +KOKORO_RUNNER_VERSION="v3.*" + +fix_bazel_imports() { + if [ -z "$KOKORO_BUILD_NUMBER" ]; then + tests_dir_prefix="" + else + tests_dir_prefix="github/repo/" + fi + + rewrite_source() { + find "${stashed_dir}${tests_dir_prefix}Tests" -type f -name '*.h' -exec sed -i '' -E "$1" {} + || true + find "${stashed_dir}${tests_dir_prefix}Tests" -type f -name '*.m' -exec sed -i '' -E "$1" {} + || true + } + + # CocoaPods requires that public headers of dependent pods be implemented using framework import + # notation, while bazel requires that dependency headers be imported with quoted notation. + stashed_dir="" + rewrite_source "s/import /import \"\1.h\"/" + stashed_dir="$(pwd)/" + reset_imports() { + # Undoes our source changes from above. + rewrite_source "s/import \"MDF(.+).h\"/import /" + rewrite_source "s/import \"(.+)\+MaterialRTL\.h\"/import /" + } + trap reset_imports EXIT +} + +if [ ! -d .kokoro-ios-runner ]; then + git clone https://github.com/material-foundation/kokoro-ios-runner.git .kokoro-ios-runner +fi + +pushd .kokoro-ios-runner +git fetch > /dev/null +TAG=$(git tag --sort=v:refname -l "$KOKORO_RUNNER_VERSION" | tail -n1) +git checkout "$TAG" > /dev/null +popd + +fix_bazel_imports + +./.kokoro-ios-runner/bazel.sh test //:UnitTests 8.1.0 + +echo "Success!" diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..4a680a5 --- /dev/null +++ b/BUILD @@ -0,0 +1,54 @@ +# Copyright 2017-present The Material Foundation Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@bazel_ios_warnings//:strict_warnings_objc_library.bzl", "strict_warnings_objc_library") +load("@build_bazel_rules_apple//apple:swift.bzl", "swift_library") +load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") + +licenses(["notice"]) # Apache 2.0 + +exports_files(["LICENSE"]) + +strict_warnings_objc_library( + name = "MDFInternationalization", + srcs = glob([ + "Sources/*.m", + ]), + hdrs = glob([ + "Sources/*.h", + ]), + defines = ["IS_BAZEL_BUILD"], + enable_modules = 1, + includes = ["Sources"], + visibility = ["//visibility:public"], +) + +objc_library( + name = "UnitTestsLib", + srcs = glob([ + "Tests/*.m", + ]), + deps = [":MDFInternationalization"], + visibility = ["//visibility:private"], +) + +ios_unit_test( + name = "UnitTests", + deps = [ + ":UnitTestsLib", + ], + minimum_os_version = "8.0", + timeout = "short", + visibility = ["//visibility:private"], +) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ed156c..c1abc25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 1.0.3 + +* [Add compile time flag for import style (#34)](https://github.com/material-foundation/material-internationalization-ios/88af44b587cb03408a827b97aa82234f6a7abc23) (ianegordon) +* [Add C++ guards so the compiler does not mangle symbol names. (#31)](https://github.com/material-foundation/material-internationalization-ios/5060976bcf45947d1176f8e060d13d4447b60a10) (Adrian Secord) +* [Remove framework-style headers from the umbrella header. (#30)](https://github.com/material-foundation/material-internationalization-ios/fef1a31313a4a8aa0234cce416e1615c7054cf9d) (featherless) +* [Add support for bazel and kokoro. (#27)](https://github.com/material-foundation/material-internationalization-ios/42a9bdf739a8de112fbcf8d395640f3477306fae) (featherless) +* [Silence NSNumber to BOOL conversion analyzer warning (#28)](https://github.com/material-foundation/material-internationalization-ios/5630a566396477ce6df5fd48b885aefdf40826d6) (ianegordon) +* [[RTL] Comment corrections and clarifications. (#26)](https://github.com/material-foundation/material-internationalization-ios/b6d5bfb53cac16de15c75d6571da5e15cdea4884) (Will Larche) + # 1.0.2 * [Update Project and Scheme to latest recommended settings](https://github.com/material-foundation/material-internationalization-ios/8a0317501403463fab8c1d541eddf0f649df2fc6) (Ian Gordon) diff --git a/MDFInternationalization.podspec b/MDFInternationalization.podspec index 2bfa04a..7501d05 100644 --- a/MDFInternationalization.podspec +++ b/MDFInternationalization.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "MDFInternationalization" - s.version = "1.0.2" + s.version = "1.0.3" s.authors = "The Material Foundation Authors" s.summary = "Internationalization tools." s.homepage = "https://github.com/material-foundation/material-internationalization-ios" diff --git a/Sources/Info.plist b/Sources/Info.plist index 9645e5d..e2ecf82 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.2 + 1.0.3 CFBundleSignature ???? CFBundleVersion diff --git a/Sources/MDFInternationalization.h b/Sources/MDFInternationalization.h index 2446234..12adde8 100644 --- a/Sources/MDFInternationalization.h +++ b/Sources/MDFInternationalization.h @@ -16,9 +16,16 @@ #import +// TODO(#33): Always use import <> once Bazel supports it. +#ifdef IS_BAZEL_BUILD +#import "MDFRTL.h" +#import "UIImage+MaterialRTL.h" +#import "UIView+MaterialRTL.h" +#else #import #import #import +#endif // IS_BAZEL_BUILD //! Project version number for MDFInternationalization. FOUNDATION_EXPORT double MDFInternationalizationVersionNumber; diff --git a/Sources/MDFRTL.h b/Sources/MDFRTL.h index 568fa5b..595dc94 100644 --- a/Sources/MDFRTL.h +++ b/Sources/MDFRTL.h @@ -23,7 +23,7 @@ @param layoutDirection The layout direction to consider when computing the autoresizing mask. @return The leading margin part of an autoresizing mask. */ -UIViewAutoresizing MDFLeadingMarginAutoresizingMaskForLayoutDirection( +FOUNDATION_EXPORT UIViewAutoresizing MDFLeadingMarginAutoresizingMaskForLayoutDirection( UIUserInterfaceLayoutDirection layoutDirection); /** @@ -33,7 +33,7 @@ UIViewAutoresizing MDFLeadingMarginAutoresizingMaskForLayoutDirection( @param layoutDirection The layout direction to consider to compute the autoresizing mask. @return The trailing margin part of an autoresizing mask. */ -UIViewAutoresizing MDFTrailingMarginAutoresizingMaskForLayoutDirection( +FOUNDATION_EXPORT UIViewAutoresizing MDFTrailingMarginAutoresizingMaskForLayoutDirection( UIUserInterfaceLayoutDirection layoutDirection); /** @@ -75,7 +75,7 @@ UIViewAutoresizing MDFTrailingMarginAutoresizingMaskForLayoutDirection( @param containerWidth The superview's bounds's width. @return The frame mirrored around the vertical axis. */ -CGRect MDFRectFlippedHorizontally(CGRect frame, CGFloat containerWidth); +FOUNDATION_EXPORT CGRect MDFRectFlippedHorizontally(CGRect frame, CGFloat containerWidth); /** @@ -84,7 +84,7 @@ CGRect MDFRectFlippedHorizontally(CGRect frame, CGFloat containerWidth); @param insets The insets we are intending to flip horizontally. @return Insets with the right and left values exchanged. */ -UIEdgeInsets MDFInsetsFlippedHorizontally(UIEdgeInsets insets); +FOUNDATION_EXPORT UIEdgeInsets MDFInsetsFlippedHorizontally(UIEdgeInsets insets); /** Creates a UIEdgeInsets instance from the parameters while obeying layoutDirection. @@ -98,8 +98,8 @@ UIEdgeInsets MDFInsetsFlippedHorizontally(UIEdgeInsets insets); @param trailing The trailing inset. @return Insets in terms of left/right, already internationalized based on the layout direction. */ -UIEdgeInsets MDFInsetsMakeWithLayoutDirection(CGFloat top, - CGFloat leading, - CGFloat bottom, - CGFloat trailing, - UIUserInterfaceLayoutDirection layoutDirection); +FOUNDATION_EXPORT UIEdgeInsets MDFInsetsMakeWithLayoutDirection(CGFloat top, + CGFloat leading, + CGFloat bottom, + CGFloat trailing, + UIUserInterfaceLayoutDirection layoutDirection); diff --git a/Sources/UIView+MaterialRTL.h b/Sources/UIView+MaterialRTL.h index 8e21957..fbf1155 100644 --- a/Sources/UIView+MaterialRTL.h +++ b/Sources/UIView+MaterialRTL.h @@ -60,7 +60,8 @@ /** Returns the layout direction implied by the provided semantic content attribute relative to the application-wide layout direction (as returned by - UIApplication.sharedApplication.userInterfaceLayoutDirection). + UIApplication.sharedApplication.userInterfaceLayoutDirection). However, if it's being called from + an iOS 8 extension, it will return left-to-right every time. @param semanticContentAttribute The semantic content attribute. @return The layout direction. diff --git a/Sources/UIView+MaterialRTL.m b/Sources/UIView+MaterialRTL.m index ca0394a..95126f7 100644 --- a/Sources/UIView+MaterialRTL.m +++ b/Sources/UIView+MaterialRTL.m @@ -105,8 +105,7 @@ + (UIUserInterfaceLayoutDirection)mdf_userInterfaceLayoutDirectionForSemanticCon #endif // MDF_BASE_SDK_EQUAL_OR_ABOVE(9_0) { // If we are running in the context of an app, we query [UIApplication sharedApplication]. - // Otherwise use a default of Left-to-Right, as UIKit in iOS 8 and below doesn't support native - // RTL layout. + // Otherwise use a default of Left-to-Right. UIUserInterfaceLayoutDirection applicationLayoutDirection = UIUserInterfaceLayoutDirectionLeftToRight; NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; @@ -151,7 +150,7 @@ @implementation UIView (MaterialRTLPrivate) - (UISemanticContentAttribute)mdf_associatedSemanticContentAttribute { NSNumber *semanticContentAttributeNumber = objc_getAssociatedObject(self, @selector(mdf_semanticContentAttribute)); - if (semanticContentAttributeNumber) { + if (semanticContentAttributeNumber != nil) { return [semanticContentAttributeNumber integerValue]; } return UISemanticContentAttributeUnspecified; diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000..69c79a3 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,25 @@ +# Copyright 2017-present The Material Foundation Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +git_repository( + name = "build_bazel_rules_apple", + remote = "https://github.com/bazelbuild/rules_apple.git", + commit = "7ea0557", +) + +git_repository( + name = "bazel_ios_warnings", + remote = "https://github.com/material-foundation/bazel_ios_warnings.git", + tag = "v1.0.1", +)