Skip to content

Commit

Permalink
Add option to import extra modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mac-cain13 committed Dec 12, 2016
1 parent 63b3a97 commit 9d2fe72
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target 'ResourceApp'
target 'ResourceAppTests'

pod 'R.swift.Library', :path => './R.swift.Library'
pod 'SWRevealViewController'

post_install do |installer|
installer.pods_project.targets.each do |target|
Expand Down
5 changes: 4 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
PODS:
- R.swift.Library (3.0.2)
- SWRevealViewController (2.3.0)

DEPENDENCIES:
- R.swift.Library (from `./R.swift.Library`)
- SWRevealViewController

EXTERNAL SOURCES:
R.swift.Library:
:path: ./R.swift.Library

SPEC CHECKSUMS:
R.swift.Library: fbdec16c9802ad104fc1ba53415dc190e6ec5c73
SWRevealViewController: 6d3fd97f70112fd7cef9de14df4260eacce4c63a

PODFILE CHECKSUM: 7cd35a355bad243c7a21d1bbcec5bf669a3e93b7
PODFILE CHECKSUM: 01a9adda3d0351316eaba0604673348a62d0ea9d

COCOAPODS: 1.1.1
7 changes: 4 additions & 3 deletions R.swift/SwiftTypes/CodeGenerators/ImportPrinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import Foundation
struct ImportPrinter: SwiftCodeConverible {
let swiftCode: String

init(structs: [Struct?], excludedModules: Set<Module>) {
let usedModules = structs
init(modules: Set<Module>, extractFrom structs: [Struct?], exclude excludedModules: Set<Module>) {
let extractedModules = structs
.flatMap { $0 }
.flatMap(getUsedTypes)
.map { $0.type.module }

swiftCode = Set(usedModules)
swiftCode = modules
.union(extractedModules)
.subtracting(excludedModules)
.filter { $0.isCustom }
.sortBy { $0.description }
Expand Down
16 changes: 16 additions & 0 deletions R.swift/input.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ private let edgeOption = Option(
helpDescription: "Enable stable features that will be in the next major release."
)

private let importOption = Option(
trigger: .long("import"),
numberOfParameters: 1,
helpDescription: "Add extra modules as import in the generated file, comma seperated."
)

private let accessLevelOption = Option(
trigger: .long("accessLevel"),
numberOfParameters: 1,
Expand Down Expand Up @@ -108,6 +114,7 @@ private let sdkRootOption = Option(
private let AllOptions = [
versionOption,
edgeOption,
importOption,
accessLevelOption,
rswiftIgnoreOption,
xcodeprojOption,
Expand All @@ -126,6 +133,7 @@ struct CallInformation {

let edge: Bool
let accessLevel: AccessLevel
let imports: Set<Module>

let xcodeprojURL: URL
let targetName: String
Expand Down Expand Up @@ -187,6 +195,14 @@ struct CallInformation {
}
accessLevel = parsedAccessLevel

imports = Set(
try getFirstArgumentForOption(importOption, "")
.components(separatedBy: ",")
.map { $0.trimmingCharacters(in: CharacterSet.whitespaces) }
.filter { !$0.isEmpty }
.map(Module.custom)
)

let xcodeprojPath = try getFirstArgumentForOption(xcodeprojOption, environment["PROJECT_FILE_PATH"])
xcodeprojURL = URL(fileURLWithPath: xcodeprojPath)

Expand Down
6 changes: 5 additions & 1 deletion R.swift/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ do {

let codeConvertibles: [SwiftCodeConverible?] = [
HeaderPrinter(),
ImportPrinter(structs: [externalStruct, internalStruct], excludedModules: [Module.custom(name: callInformation.productModuleName)]),
ImportPrinter(
modules: callInformation.imports,
extractFrom: [externalStruct, internalStruct],
exclude: [Module.custom(name: callInformation.productModuleName)]
),
externalStruct,
internalStruct
]
Expand Down
2 changes: 1 addition & 1 deletion ResourceApp/ResourceApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"$SRCROOT/rswift\" \"$SRCROOT\" > \"$SRCROOT/rswift.log\"";
shellScript = "\"$SRCROOT/rswift\" \"--import\" \"SWRevealViewController\" \"$SRCROOT\" > \"$SRCROOT/rswift.log\"";
};
DEF559A61CA487D6009B8C51 /* R.swift */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
38 changes: 33 additions & 5 deletions ResourceApp/ResourceApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A320" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="49e-Tb-3d3">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="49e-Tb-3d3">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
Expand All @@ -23,17 +26,21 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="First View" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="KQZ-1w-vlD">
<rect key="frame" x="109" y="313" width="157.5" height="41.5"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="36"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Loaded by FirstViewController" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="A5M-7J-77L">
<rect key="frame" x="90.5" y="362.5" width="194.5" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="[email protected]" translatesAutoresizingMaskIntoConstraints="NO" id="ZJc-88-QRk"/>
<imageView userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="[email protected]" translatesAutoresizingMaskIntoConstraints="NO" id="ZJc-88-QRk">
<rect key="frame" x="123.5" y="52" width="128" height="128"/>
</imageView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -54,6 +61,24 @@
</objects>
<point key="canvasLocation" x="750" y="-320"/>
</scene>
<!--Reveal View Controller-->
<scene sceneID="d0u-kX-nCz">
<objects>
<viewController storyboardIdentifier="swRevealViewController" id="uQ3-nU-KEn" customClass="SWRevealViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="f16-cV-z5y"/>
<viewControllerLayoutGuide type="bottom" id="soX-IP-S1A"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="cRv-1n-fml">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="OSL-5X-vl5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1586" y="-321"/>
</scene>
<!--Second-->
<scene sceneID="wg7-f3-ORb">
<objects>
Expand All @@ -67,12 +92,14 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Second View" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="zEq-FU-wV5">
<rect key="frame" x="83" y="313" width="209.5" height="41.5"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="36"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Loaded by SecondViewController" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NDk-cv-Gan">
<rect key="frame" x="80" y="362.5" width="215" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -122,6 +149,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8B6-zH-yBB">
<rect key="frame" x="161.5" y="318.5" width="52" height="30"/>
<state key="normal" title="Unwind"/>
<connections>
<segue destination="gh1-ro-RFV" kind="unwind" identifier="unwindSegue" unwindAction="unwindSomethingSomthing:" id="UNt-3N-uEw"/>
Expand Down Expand Up @@ -171,15 +199,15 @@
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Lre-Cj-0QS" id="sq1-mW-7Wa">
<frame key="frameInset" width="375" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="fullCell" id="L8j-6T-BZ6">
<rect key="frame" x="0.0" y="72" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="L8j-6T-BZ6" id="Vn1-wc-sJz">
<frame key="frameInset" width="375" height="43"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
Expand Down

0 comments on commit 9d2fe72

Please sign in to comment.