Nikita Lutsenko 10 жил өмнө
commit
a19b5739c5

+ 71 - 0
.clang-format

@@ -0,0 +1,71 @@
+# Copyright (c) 2015-present, Parse, LLC.
+# All rights reserved.
+#
+# This source code is licensed under the BSD-style license found in the
+# LICENSE file in the root directory of this source tree. An additional grant
+# of patent rights can be found in the PATENTS file in the same directory.
+
+---
+Language:        Cpp
+BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: true
+AlignEscapedNewlinesLeft: true
+AlignOperands:   true
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: false
+AlwaysBreakTemplateDeclarations: false
+AlwaysBreakBeforeMultilineStrings: false
+BreakBeforeBinaryOperators: None
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: true
+BinPackParameters: true
+BinPackArguments: true
+ColumnLimit:     0
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 4
+DerivePointerAlignment: true
+ExperimentalAutoDetectBinPacking: true
+IndentCaseLabels: true
+IndentWrappedFunctionNames: true
+IndentFunctionDeclarationAfterType: true
+MaxEmptyLinesToKeep: 1
+KeepEmptyLinesAtTheStartOfBlocks: true
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakString: 1000
+PenaltyBreakFirstLessLess: 140
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 120
+PointerAlignment: Right
+SpacesBeforeTrailingComments: 1
+Cpp11BracedListStyle: true
+Standard:        Cpp11
+IndentWidth:     4
+TabWidth:        4
+UseTab:          Never
+BreakBeforeBraces: Attach
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpacesInAngles:  false
+SpaceInEmptyParentheses: false
+SpacesInCStyleCastParentheses: false
+SpaceAfterCStyleCast: false
+SpacesInContainerLiterals: true
+SpaceBeforeAssignmentOperators: true
+ContinuationIndentWidth: 4
+CommentPragmas:  '^ IWYU pragma:'
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+SpaceBeforeParens: ControlStatements
+DisableFormat:   false
+...

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.DS_Store

+ 21 - 0
Configurations/Common.xcconfig

@@ -0,0 +1,21 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+#include "Warnings.xcconfig"
+
+// Language Settings
+CLANG_ENABLE_OBJC_ARC = YES
+GCC_C_LANGUAGE_STANDARD = gnu11
+CLANG_CXX_LANGUAGE_STANDARD = gnu++14
+CLANG_CXX_LIBRARY = libstdc++
+
+// Search Paths
+PARSE_DIR = $(PROJECT_DIR)
+VENDOR_DIR = $(PARSE_DIR)/Vendor
+ALWAYS_SEARCH_USER_PATHS = NO

+ 11 - 0
Configurations/Platform/OSX.xcconfig

@@ -0,0 +1,11 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+SDKROOT = macosx
+MACOSX_DEPLOYMENT_TARGET = 10.9

+ 21 - 0
Configurations/Platform/iOS.xcconfig

@@ -0,0 +1,21 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+SDKROOT = iphoneos
+IPHONEOS_DEPLOYMENT_TARGET = 7.0
+
+GCC_THUMB_SUPPORT = NO
+
+ARCHS = $(ARCHS_STANDARD) armv7s
+DSTROOT = /tmp/$(PRODUCT_NAME).dst
+
+CODE_SIGN_IDENTITY =
+CODE_SIGNING_REQUIRED = NO
+
+TARGETED_DEVICE_FAMILY = 1,2

+ 11 - 0
Configurations/Platform/tvOS.xcconfig

@@ -0,0 +1,11 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+SDKROOT = appletvos
+TVOS_DEPLOYMENT_TARGET = 9.0

+ 14 - 0
Configurations/Platform/watchOS.xcconfig

@@ -0,0 +1,14 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+SDKROOT = watchos
+WATCHOS_DEPLOYMENT_TARGET = 2.0
+
+CODE_SIGN_IDENTITY =
+CODE_SIGNING_REQUIRED = NO

+ 14 - 0
Configurations/Product/Application.xcconfig

@@ -0,0 +1,14 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+LD_RUNPATH_SEARCH_PATHS = @executable_path/Frameworks
+
+ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
+ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage
+CLANG_ENABLE_MODULES = YES

+ 19 - 0
Configurations/Product/Framework.xcconfig

@@ -0,0 +1,19 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+ENABLE_NS_ASSERTIONS = NO
+MTL_ENABLE_DEBUG_INFO = NO
+
+DYLIB_COMPATIBILITY_VERSION = 1
+DYLIB_CURRENT_VERSION = 1
+
+SKIP_INSTALL = YES
+
+CLANG_MODULES_AUTOLINK = NO
+CLANG_ENABLE_MODULES = YES

+ 15 - 0
Configurations/Product/UnitTest.xcconfig

@@ -0,0 +1,15 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+OTHER_LDFLAGS = $(inherited) -ObjC -framework XCTest
+BUNDLE_LOADER = $(TEST_HOST)
+
+LD_RUNPATH_SEARCH_PATHS = $(inherited) @loader_path/Frameworks @executable_path/Frameworks
+USER_HEADER_SEARCH_PATHS = $(value) $(PARSE_DIR)/Tests/**
+CLANG_ENABLE_MODULES = YES

+ 22 - 0
Configurations/Project/Debug.xcconfig

@@ -0,0 +1,22 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+#include "../Common.xcconfig"
+
+GCC_OPTIMIZATION_LEVEL = 0
+SWIFT_OPTIMIZATION_LEVEL = -Onone
+
+GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1
+ONLY_ACTIVE_ARCH = YES
+
+ENABLE_TESTABILITY = YES
+
+SANITIZE_FLAGS = -fsanitize-undefined-trap-on-error -fsanitize=undefined-trap
+OTHER_CFLAGS = $(value) $(SANITIZE_FLAGS)
+OTHER_LDFLAGS = $(value) $(SANITIZE_FLAGS)

+ 18 - 0
Configurations/Project/Release.xcconfig

@@ -0,0 +1,18 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+#include "../Common.xcconfig"
+
+GCC_OPTIMIZATION_LEVEL = s
+SWIFT_OPTIMIZATION_LEVEL = -O
+
+VALIDATE_PRODUCT = YES
+
+DEPLOYMENT_POSTPROCESSING = YES
+STRIP_STYLE = debugging

+ 43 - 0
Configurations/Warnings.xcconfig

@@ -0,0 +1,43 @@
+//
+// Copyright (c) 2015-present, Parse, LLC.
+// All rights reserved.
+//
+// This source code is licensed under the BSD-style license found in the
+// LICENSE file in the root directory of this source tree. An additional grant
+// of patent rights can be found in the PATENTS file in the same directory.
+//
+
+ENABLE_STRICT_OBJC_MSGSEND = YES
+
+GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
+GCC_WARN_ABOUT_MISSING_NEWLINE = YES
+GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES
+GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
+GCC_WARN_MISSING_PARENTHESES = YES
+GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
+GCC_WARN_UNKNOWN_PRAGMAS = YES
+GCC_WARN_UNUSED_FUNCTION = YES
+GCC_WARN_UNUSED_LABEL = YES
+GCC_WARN_UNUSED_VALUE = YES
+GCC_WARN_UNUSED_VARIABLE = YES
+GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES
+GCC_WARN_UNDECLARED_SELECTOR = YES
+GCC_WARN_64_TO_32_BIT_CONVERSION = YES
+GCC_WARN_UNINITIALIZED_AUTOS = YES
+
+CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES
+CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
+CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES
+CLANG_WARN_CONSTANT_CONVERSION = YES
+CLANG_WARN_DOCUMENTATION_COMMENTS = YES
+CLANG_WARN_EMPTY_BODY = YES
+CLANG_WARN_ENUM_CONVERSION = YES
+CLANG_WARN_UNREACHABLE_CODE = YES
+CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
+CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES
+CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES
+
+// Errors
+GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR
+CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR
+CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR

+ 2 - 0
README.md

@@ -0,0 +1,2 @@
+# xctoolchain
+Common configuration files and scripts that are used to build our SDKs with Xcode.

+ 168 - 0
Scripts/xctask/build_framework_task.rb

@@ -0,0 +1,168 @@
+#!/usr/bin/env ruby
+#
+# Copyright (c) 2015-present, Parse, LLC.
+# All rights reserved.
+#
+# This source code is licensed under the BSD-style license found in the
+# LICENSE file in the root directory of this source tree. An additional grant
+# of patent rights can be found in the PATENTS file in the same directory.
+#
+
+require 'naturally'
+require_relative 'build_task'
+
+module XCTask
+  # This class defines all possible framework types for BuildFrameworkTask.
+  class FrameworkType
+    IOS = 'ios'
+    OSX = 'osx'
+    WATCHOS = 'watchos'
+
+    def self.verify(type)
+      if type.nil? || (type != IOS && type != OSX && type != WATCHOS)
+        fail "Unknown framework type. Available types: 'ios', 'osx', 'watchos'."
+      end
+    end
+  end
+
+  # This class adds ability to easily configure a building of iOS/OSX framework and execute the build process.
+  class BuildFrameworkTask
+    attr_accessor :directory
+    attr_accessor :build_directory
+    attr_accessor :framework_type
+    attr_accessor :framework_name
+
+    attr_accessor :workspace
+    attr_accessor :project
+    attr_accessor :scheme
+    attr_accessor :configuration
+
+    def initialize
+      @directory = '.'
+      @build_directory = './build'
+      yield self if block_given?
+    end
+
+    def execute
+      verify
+      prepare_build
+      build
+    end
+
+    private
+
+    def verify
+      FrameworkType.verify(@framework_type)
+    end
+
+    def prepare_build
+      Dir.chdir(@directory) unless @directory.nil?
+    end
+
+    def build
+      case @framework_type
+      when FrameworkType::IOS
+        build_ios_framework
+      when FrameworkType::OSX
+        build_osx_framework
+      when FrameworkType::WATCHOS
+        build_watchos_framework
+      end
+    end
+
+    def build_ios_framework
+      framework_paths = []
+      framework_paths << build_framework('iphoneos')
+      framework_paths << build_framework('iphonesimulator')
+      final_path = final_framework_path
+
+      system("rm -rf #{final_path} && cp -R #{framework_paths[0]} #{final_path}")
+
+      binary_name = File.basename(@framework_name, '.framework')
+      system("rm -rf #{final_path}/#{binary_name}")
+
+      lipo_command = 'lipo -create'
+      framework_paths.each do |path|
+        lipo_command += " #{path}/#{binary_name}"
+      end
+      lipo_command += " -o #{final_path}/#{binary_name}"
+
+      result = system(lipo_command)
+      unless result
+        puts 'Failed to lipo iOS framework.'
+        exit(1)
+      end
+      result
+    end
+
+    def build_watchos_framework
+      framework_paths = []
+      framework_paths << build_framework('watchos')
+      framework_paths << build_framework('watchsimulator')
+      final_path = final_framework_path
+
+      system("rm -rf #{final_path} && cp -R #{framework_paths[0]} #{final_path}")
+
+      binary_name = File.basename(@framework_name, '.framework')
+      system("rm -rf #{final_path}/#{binary_name}")
+
+      lipo_command = 'lipo -create'
+      framework_paths.each do |path|
+        lipo_command += " #{path}/#{binary_name}"
+      end
+      lipo_command += " -o #{final_path}/#{binary_name}"
+
+      result = system(lipo_command)
+      unless result
+        puts 'Failed to lipo watchOS framework.'
+        exit(1)
+      end
+      result
+    end
+
+    def build_osx_framework
+      build_path = build_framework('macosx')
+      final_path = final_framework_path
+      system("rm -rf #{final_path} && cp -R #{build_path} #{final_path}")
+    end
+
+    def build_framework(sdk)
+      configuration_directory = configuration_build_directory(sdk)
+      build_task = BuildTask.new do |t|
+        t.directory = @directory
+        t.project = @project
+        t.workspace = @workspace
+
+        t.scheme = @scheme
+        t.sdk = latest_sdk(sdk)
+        t.configuration = @configuration
+
+        t.actions = [BuildAction::CLEAN, BuildAction::BUILD]
+        t.formatter = BuildFormatter::XCPRETTY
+
+        t.additional_options = { 'CONFIGURATION_BUILD_DIR' => "'#{configuration_directory}'" }
+      end
+
+      result = build_task.execute
+      unless result
+        puts "Failed to build framework for #{sdk}."
+        exit(1)
+      end
+
+      "#{configuration_directory}/#{@framework_name}"
+    end
+
+    def latest_sdk(platform)
+      sdks = Naturally.sort(`xcodebuild -showsdks`.scan(/-sdk (.*)$/)).reverse.flatten
+      sdks.select { |s| s =~ /#{platform}/ }[0]
+    end
+
+    def configuration_build_directory(sdk)
+      "#{@build_directory}/#{@configuration}-#{@framework_type}-#{sdk}"
+    end
+
+    def final_framework_path
+      "#{@build_directory}/#{@framework_name}"
+    end
+  end
+end

+ 132 - 0
Scripts/xctask/build_task.rb

@@ -0,0 +1,132 @@
+#!/usr/bin/env ruby
+#
+# Copyright (c) 2015-present, Parse, LLC.
+# All rights reserved.
+#
+# This source code is licensed under the BSD-style license found in the
+# LICENSE file in the root directory of this source tree. An additional grant
+# of patent rights can be found in the PATENTS file in the same directory.
+#
+
+module XCTask
+  # This class defines all possible build formatters for BuildTask.
+  class BuildFormatter
+    XCODEBUILD = 'xcodebuild'
+    XCPRETTY = 'xcpretty'
+    XCTOOL = 'xctool'
+
+    def self.verify(formatter)
+      if formatter &&
+         formatter != XCPRETTY &&
+         formatter != XCODEBUILD &&
+         formatter != XCTOOL
+        fail "Unknown formatter used. Available formatters: 'xcodebuild', 'xcpretty', 'xctool'."
+      end
+    end
+  end
+
+  # This class defines all possible build actions for BuildTask.
+  class BuildAction
+    BUILD = 'build'
+    CLEAN = 'clean'
+    TEST = 'test'
+
+    def self.verify(action)
+      if action.nil? ||
+         (action != BUILD &&
+         action != CLEAN &&
+         action != TEST)
+        fail "Unknown build action used. Available actions: 'build', 'clean', 'test'."
+      end
+    end
+  end
+
+  # This class adds ability to easily configure a xcodebuild task and execute it.
+  class BuildTask
+    attr_accessor :directory
+    attr_accessor :workspace
+    attr_accessor :project
+
+    attr_accessor :scheme
+    attr_accessor :sdk
+    attr_accessor :configuration
+    attr_accessor :destinations
+
+    attr_accessor :additional_options
+    attr_accessor :actions
+    attr_accessor :formatter
+
+    attr_accessor :reports_enabled
+
+    def initialize
+      @directory = '.'
+      @destinations = []
+      @additional_options = {}
+
+      yield self if block_given?
+    end
+
+    def execute
+      verify
+      prepare_build
+      build
+    end
+
+    private
+
+    def verify
+      BuildFormatter.verify(@formatter)
+      @actions.each do |action|
+        BuildAction.verify(action)
+      end
+    end
+
+    def prepare_build
+      Dir.chdir(@directory) unless @directory.nil?
+    end
+
+    def build
+      system(build_command_string(@formatter))
+    end
+
+    def build_command_string(formatter)
+      command_string = nil
+
+      case formatter
+      when BuildFormatter::XCODEBUILD
+        command_string = 'xcodebuild ' + build_options_string
+      when BuildFormatter::XCPRETTY
+        command_string = build_command_string('xcodebuild') + ' | xcpretty -c'
+        if @actions.include? BuildAction::TEST
+          command_string += " --report junit --output build/reports/#{@sdk}.xml"
+        end
+        command_string += ' ; exit ${PIPESTATUS[0]}'
+      when BuildFormatter::XCTOOL
+        command_string = 'xctool ' + build_options_string
+      else
+        command_string = build_command_string(BuildFormatter::XCODEBUILD)
+      end
+
+      command_string
+    end
+
+    def build_options_string
+      opts = []
+      opts << "-workspace #{@workspace}" if @workspace
+      opts << "-project #{@project}" if @project
+      opts << "-scheme #{@scheme}" if @scheme
+      opts << "-sdk #{@sdk}" if @sdk
+      opts << "-configuration #{@configuration}" if @configuration
+      @destinations.each do |d|
+        opts << "-destination #{d}"
+      end
+      opts << @actions.compact.join(' ') if @actions
+
+      @additional_options.each do |key, value|
+        opts << "#{key}=#{value}"
+      end
+
+      opts.compact.join(' ')
+    end
+  end
+end