Skip to content

Commit

Permalink
Merge branch 'provide-input-paths-to-script'
Browse files Browse the repository at this point in the history
* provide-input-paths-to-script:
  Provide inputPaths to extra script build phase
  • Loading branch information
norio-nomura committed Nov 11, 2015
2 parents a63f188 + ed1ee0a commit 6caa71d
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 3 deletions.
10 changes: 10 additions & 0 deletions ExtraBuildPhase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

/* Begin PBXFileReference section */
6C233E1C1BEF24AB00D7C9D2 /* PBXTarget.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXTarget.h; sourceTree = "<group>"; };
6C777D4A1BF2306600DA25D8 /* PBXSourcesBuildPhase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXSourcesBuildPhase.h; sourceTree = "<group>"; };
6C777D4B1BF230C000DA25D8 /* PBXBuildPhase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXBuildPhase.h; sourceTree = "<group>"; };
6C777D4C1BF2318100DA25D8 /* PBXBuildFile.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXBuildFile.h; sourceTree = "<group>"; };
6C777D541BF2349100DA25D8 /* PBXFileReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXFileReference.h; sourceTree = "<group>"; };
6C777D551BF2366400DA25D8 /* PBXReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXReference.h; sourceTree = "<group>"; };
6CEA7CA51BEDD37300E0CE79 /* ExtraBuildPhase.xcplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExtraBuildPhase.xcplugin; sourceTree = BUILT_PRODUCTS_DIR; };
6CEA7CA81BEDD37300E0CE79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6CEA7CAE1BEDD4B800E0CE79 /* ExtraBuildPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtraBuildPhase.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -56,7 +61,12 @@
6CEA7CA81BEDD37300E0CE79 /* Info.plist */,
6CEA7CAE1BEDD4B800E0CE79 /* ExtraBuildPhase.h */,
6CEA7CAF1BEDD4B800E0CE79 /* ExtraBuildPhase.m */,
6C777D4C1BF2318100DA25D8 /* PBXBuildFile.h */,
6C777D4B1BF230C000DA25D8 /* PBXBuildPhase.h */,
6C777D541BF2349100DA25D8 /* PBXFileReference.h */,
6C777D551BF2366400DA25D8 /* PBXReference.h */,
6CF50AB91BEF148700604C02 /* PBXShellScriptBuildPhase.h */,
6C777D4A1BF2306600DA25D8 /* PBXSourcesBuildPhase.h */,
6C233E1C1BEF24AB00D7C9D2 /* PBXTarget.h */,
);
path = ExtraBuildPhase;
Expand Down
22 changes: 20 additions & 2 deletions ExtraBuildPhase/ExtraBuildPhase.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ @implementation ExtraBuildPhase(SwizzlingTargetMethods)
typedef id<PBXShellScriptBuildPhase> BuildPhase;

/// replacement for -[PBXTarget buildPhases];
- (NSArray*)_ExtraBuildPhase_buildPhases
- (NSArray<id<PBXBuildPhase>>*)_ExtraBuildPhase_buildPhases
{
// call original method
NSArray *result = [self _ExtraBuildPhase_buildPhases];
NSArray<id<PBXBuildPhase>> *result = [self _ExtraBuildPhase_buildPhases];

if (_ExtraBuildPhase_in_createDependencyGraphSnapshot) {
NSString *identifier = [[NSBundle bundleForClass:[ExtraBuildPhase class]]bundleIdentifier];
Expand All @@ -61,6 +61,24 @@ - (NSArray*)_ExtraBuildPhase_buildPhases
[buildPhase setShowEnvVarsInLog:showEnvVarsInLog];
[buildPhase setShellPath:@"/bin/sh"];
[buildPhase setShellScript:shellScript];

Class SourcesBuildPhaseClass = objc_getClass("PBXSourcesBuildPhase");
NSMutableArray<NSString *> *inputPaths = [[NSMutableArray<NSString *> alloc]init];
for (id<PBXBuildPhase> buildPhase in result) {
if ([buildPhase isKindOfClass:SourcesBuildPhaseClass]) {
for (id<PBXBuildFile> buildFile in [buildPhase buildFiles]) {
NSString *path = [[buildFile fileReference]projectRelativePath];
if (path) {
[inputPaths addObject:[@"$(SRCROOT)/" stringByAppendingString:path]];
}
}
}
}

if ([inputPaths count]) {
[buildPhase setInputPaths:inputPaths];
}

NSMutableArray *newResult = [result mutableCopy];
[newResult addObject:buildPhase];
return newResult;
Expand Down
40 changes: 40 additions & 0 deletions ExtraBuildPhase/PBXBuildFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// PBXBuildFile.h
// ExtraBuildPhase
//
// Created by 野村 憲男 on 11/10/15.
//
// Copyright (c) 2015 Norio Nomura
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#ifndef PBXBuildFile_h
#define PBXBuildFile_h

#import "PBXFileReference.h"

@protocol PBXBuildFile <NSObject>

- (id<PBXFileReference>)fileReference;

@end


#endif /* PBXBuildFile_h */
39 changes: 39 additions & 0 deletions ExtraBuildPhase/PBXBuildPhase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// PBXBuildPhase.h
// ExtraBuildPhase
//
// Created by 野村 憲男 on 11/10/15.
//
// Copyright (c) 2015 Norio Nomura
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#ifndef PBXBuildPhase_h
#define PBXBuildPhase_h

#import "PBXBuildFile.h"

@protocol PBXBuildPhase <NSObject>

- (NSArray<id<PBXBuildFile>> *)buildFiles;

@end

#endif /* PBXBuildPhase_h */
36 changes: 36 additions & 0 deletions ExtraBuildPhase/PBXFileReference.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// PBXFileReference.h
// ExtraBuildPhase
//
// Created by 野村 憲男 on 11/10/15.
//
// Copyright (c) 2015 Norio Nomura
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#ifndef PBXFileReference_h
#define PBXFileReference_h

#import "PBXReference.h"

@protocol PBXFileReference <PBXReference>
@end

#endif /* PBXFileReference_h */
37 changes: 37 additions & 0 deletions ExtraBuildPhase/PBXReference.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// PBXReference.h
// ExtraBuildPhase
//
// Created by 野村 憲男 on 11/10/15.
//
// Copyright (c) 2015 Norio Nomura
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#ifndef PBXReference_h
#define PBXReference_h

@protocol PBXReference <NSObject>

- (NSString*)projectRelativePath;

@end

#endif /* PBXReference_h */
4 changes: 3 additions & 1 deletion ExtraBuildPhase/PBXShellScriptBuildPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#ifndef PBXShellScriptBuildPhase_h
#define PBXShellScriptBuildPhase_h

@protocol PBXShellScriptBuildPhase <NSObject>
#import "PBXBuildPhase.h"

@protocol PBXShellScriptBuildPhase <PBXBuildPhase>

- (id)initWithName:(NSString*)name;
- (void)setShowEnvVarsInLog:(BOOL)arg1;
Expand Down
36 changes: 36 additions & 0 deletions ExtraBuildPhase/PBXSourcesBuildPhase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// PBXSourcesBuildPhase.h
// ExtraBuildPhase
//
// Created by 野村 憲男 on 11/10/15.
//
// Copyright (c) 2015 Norio Nomura
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#ifndef PBXSourcesBuildPhase_h
#define PBXSourcesBuildPhase_h

#import "PBXBuildPhase.h"

@protocol PBXSourcesBuildPhase <PBXBuildPhase>
@end

#endif /* PBXSourcesBuildPhase_h */

0 comments on commit 6caa71d

Please sign in to comment.