From ed1ee0a9dc15bf2540da9862c53fa4eae04110b8 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Wed, 11 Nov 2015 00:05:35 +0900 Subject: [PATCH] Provide inputPaths to extra script build phase --- ExtraBuildPhase.xcodeproj/project.pbxproj | 10 ++++++ ExtraBuildPhase/ExtraBuildPhase.m | 22 ++++++++++-- ExtraBuildPhase/PBXBuildFile.h | 40 ++++++++++++++++++++++ ExtraBuildPhase/PBXBuildPhase.h | 39 +++++++++++++++++++++ ExtraBuildPhase/PBXFileReference.h | 36 +++++++++++++++++++ ExtraBuildPhase/PBXReference.h | 37 ++++++++++++++++++++ ExtraBuildPhase/PBXShellScriptBuildPhase.h | 4 ++- ExtraBuildPhase/PBXSourcesBuildPhase.h | 36 +++++++++++++++++++ 8 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 ExtraBuildPhase/PBXBuildFile.h create mode 100644 ExtraBuildPhase/PBXBuildPhase.h create mode 100644 ExtraBuildPhase/PBXFileReference.h create mode 100644 ExtraBuildPhase/PBXReference.h create mode 100644 ExtraBuildPhase/PBXSourcesBuildPhase.h diff --git a/ExtraBuildPhase.xcodeproj/project.pbxproj b/ExtraBuildPhase.xcodeproj/project.pbxproj index 74e9f19..033c511 100644 --- a/ExtraBuildPhase.xcodeproj/project.pbxproj +++ b/ExtraBuildPhase.xcodeproj/project.pbxproj @@ -12,6 +12,11 @@ /* Begin PBXFileReference section */ 6C233E1C1BEF24AB00D7C9D2 /* PBXTarget.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXTarget.h; sourceTree = ""; }; + 6C777D4A1BF2306600DA25D8 /* PBXSourcesBuildPhase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXSourcesBuildPhase.h; sourceTree = ""; }; + 6C777D4B1BF230C000DA25D8 /* PBXBuildPhase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXBuildPhase.h; sourceTree = ""; }; + 6C777D4C1BF2318100DA25D8 /* PBXBuildFile.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXBuildFile.h; sourceTree = ""; }; + 6C777D541BF2349100DA25D8 /* PBXFileReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXFileReference.h; sourceTree = ""; }; + 6C777D551BF2366400DA25D8 /* PBXReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PBXReference.h; sourceTree = ""; }; 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 = ""; }; 6CEA7CAE1BEDD4B800E0CE79 /* ExtraBuildPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtraBuildPhase.h; sourceTree = ""; }; @@ -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; diff --git a/ExtraBuildPhase/ExtraBuildPhase.m b/ExtraBuildPhase/ExtraBuildPhase.m index 163ce1f..43c9c78 100644 --- a/ExtraBuildPhase/ExtraBuildPhase.m +++ b/ExtraBuildPhase/ExtraBuildPhase.m @@ -38,10 +38,10 @@ @implementation ExtraBuildPhase(SwizzlingTargetMethods) typedef id BuildPhase; /// replacement for -[PBXTarget buildPhases]; -- (NSArray*)_ExtraBuildPhase_buildPhases +- (NSArray>*)_ExtraBuildPhase_buildPhases { // call original method - NSArray *result = [self _ExtraBuildPhase_buildPhases]; + NSArray> *result = [self _ExtraBuildPhase_buildPhases]; if (_ExtraBuildPhase_in_createDependencyGraphSnapshot) { NSString *identifier = [[NSBundle bundleForClass:[ExtraBuildPhase class]]bundleIdentifier]; @@ -61,6 +61,24 @@ - (NSArray*)_ExtraBuildPhase_buildPhases [buildPhase setShowEnvVarsInLog:showEnvVarsInLog]; [buildPhase setShellPath:@"/bin/sh"]; [buildPhase setShellScript:shellScript]; + + Class SourcesBuildPhaseClass = objc_getClass("PBXSourcesBuildPhase"); + NSMutableArray *inputPaths = [[NSMutableArray alloc]init]; + for (id buildPhase in result) { + if ([buildPhase isKindOfClass:SourcesBuildPhaseClass]) { + for (id 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; diff --git a/ExtraBuildPhase/PBXBuildFile.h b/ExtraBuildPhase/PBXBuildFile.h new file mode 100644 index 0000000..84dbb3e --- /dev/null +++ b/ExtraBuildPhase/PBXBuildFile.h @@ -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 + +- (id)fileReference; + +@end + + +#endif /* PBXBuildFile_h */ diff --git a/ExtraBuildPhase/PBXBuildPhase.h b/ExtraBuildPhase/PBXBuildPhase.h new file mode 100644 index 0000000..5835108 --- /dev/null +++ b/ExtraBuildPhase/PBXBuildPhase.h @@ -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 + +- (NSArray> *)buildFiles; + +@end + +#endif /* PBXBuildPhase_h */ diff --git a/ExtraBuildPhase/PBXFileReference.h b/ExtraBuildPhase/PBXFileReference.h new file mode 100644 index 0000000..06460b9 --- /dev/null +++ b/ExtraBuildPhase/PBXFileReference.h @@ -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 +@end + +#endif /* PBXFileReference_h */ diff --git a/ExtraBuildPhase/PBXReference.h b/ExtraBuildPhase/PBXReference.h new file mode 100644 index 0000000..e04aa86 --- /dev/null +++ b/ExtraBuildPhase/PBXReference.h @@ -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 + +- (NSString*)projectRelativePath; + +@end + +#endif /* PBXReference_h */ diff --git a/ExtraBuildPhase/PBXShellScriptBuildPhase.h b/ExtraBuildPhase/PBXShellScriptBuildPhase.h index 0fd489b..c98d25b 100644 --- a/ExtraBuildPhase/PBXShellScriptBuildPhase.h +++ b/ExtraBuildPhase/PBXShellScriptBuildPhase.h @@ -28,7 +28,9 @@ #ifndef PBXShellScriptBuildPhase_h #define PBXShellScriptBuildPhase_h -@protocol PBXShellScriptBuildPhase +#import "PBXBuildPhase.h" + +@protocol PBXShellScriptBuildPhase - (id)initWithName:(NSString*)name; - (void)setShowEnvVarsInLog:(BOOL)arg1; diff --git a/ExtraBuildPhase/PBXSourcesBuildPhase.h b/ExtraBuildPhase/PBXSourcesBuildPhase.h new file mode 100644 index 0000000..e6f914c --- /dev/null +++ b/ExtraBuildPhase/PBXSourcesBuildPhase.h @@ -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 +@end + +#endif /* PBXSourcesBuildPhase_h */