Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6bd02ca

Browse files
committed
Merge pull requestfacebookarchive#98 from facebook/fpotter/fix-implicit-dependencies
Make xctool play nice with Find Implicit Dependencies
2 parentse89f454 +4f59b2b commit6bd02ca

File tree

7 files changed

+196
-64
lines changed

7 files changed

+196
-64
lines changed

‎xctool/xctool-tests/BuildTestsActionTests.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ - (void)testBuildTestsAction
141141
assertThatInt(tool.exitStatus,equalToInt(0));
142142

143143
NSString *projectPath = TEST_DATA@"TestProject-Library/TestProject-Library.xcodeproj";
144+
145+
[verify(mockSchemeGenerator)setParallelizeBuildables:YES];
146+
[verify(mockSchemeGenerator)setBuildImplicitDependencies:YES];
147+
[verify(mockSchemeGenerator)addProjectPathToWorkspace:projectPath];
144148
[verify(mockSchemeGenerator)addBuildableWithID:kTestProjectTestProjectLibraryTargetID
145149
inProject:projectPath];
146150
[verify(mockSchemeGenerator)addBuildableWithID:kTestProjectTestProjectLibraryTestTargetID
@@ -197,6 +201,9 @@ - (void)testBuildTestsActionWillBuildEverythingMarkedAsBuildForTest
197201
assertThatInt(tool.exitStatus,equalToInt(0));
198202

199203
NSString *projectPath = TEST_DATA@"TestWorkspace-Library/TestProject-Library/TestProject-Library.xcodeproj";
204+
[verify(mockSchemeGenerator)setParallelizeBuildables:NO];
205+
[verify(mockSchemeGenerator)setBuildImplicitDependencies:YES];
206+
[verify(mockSchemeGenerator)addProjectPathToWorkspace:projectPath];
200207
[verify(mockSchemeGenerator)addBuildableWithID:kTestWorkspaceTestProjectLibraryTargetID
201208
inProject:projectPath];
202209
[verify(mockSchemeGenerator)addBuildableWithID:kTestWorkspaceTestProjectOtherLibTargetID
@@ -262,6 +269,9 @@ - (void)testBuildTestsCanBuildASingleTarget
262269
assertThatInt(tool.exitStatus,equalToInt(0));
263270

264271
NSString *projectPath = TEST_DATA@"TestWorkspace-Library/TestProject-Library/TestProject-Library.xcodeproj";
272+
[verify(mockSchemeGenerator)setParallelizeBuildables:NO];
273+
[verify(mockSchemeGenerator)setBuildImplicitDependencies:YES];
274+
[verify(mockSchemeGenerator)addProjectPathToWorkspace:projectPath];
265275
[verify(mockSchemeGenerator)addBuildableWithID:kTestWorkspaceTestProjectLibraryTargetID
266276
inProject:projectPath];
267277
[verify(mockSchemeGenerator)addBuildableWithID:kTestWorkspaceTestProjectOtherLibTargetID
@@ -324,6 +334,9 @@ - (void)testSkipDependencies
324334
assertThatInt(tool.exitStatus,equalToInt(0));
325335

326336
NSString *projectPath = TEST_DATA@"TestWorkspace-Library/TestProject-Library/TestProject-Library.xcodeproj";
337+
[verify(mockSchemeGenerator)setParallelizeBuildables:NO];
338+
[verify(mockSchemeGenerator)setBuildImplicitDependencies:YES];
339+
[verify(mockSchemeGenerator)addProjectPathToWorkspace:projectPath];
327340
[verify(mockSchemeGenerator)addBuildableWithID:kTestWorkspaceTestProjectLibraryTestsTargetID
328341
inProject:projectPath];
329342
[verifyCount(mockSchemeGenerator,times(1))addBuildableWithID:(id)anything()inProject:(id)anything()];

‎xctool/xctool-tests/XcodeSubjectInfoTests.m

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ - (void)testTestableIncludesInfoForMacroExpansion
253253
}]));
254254
}
255255

256-
- (void)testCanGetBuildConfigurationForRunAction
256+
- (XcodeSubjectInfo *)xcodeSubjectInfoPopulatedWithProject:(NSString *)projectscheme:(NSString *)scheme
257257
{
258+
__block XcodeSubjectInfo *subjectInfo =nil;
259+
258260
[[FakeTaskManagersharedManager]runBlockWithFakeTasks:^{
259261
[[FakeTaskManagersharedManager]addLaunchHandlerBlocks:@[
260262
// Make sure -showBuildSettings returns some data
@@ -268,19 +270,40 @@ - (void)testCanGetBuildConfigurationForRunAction
268270
@"-scheme",@"TestProject-Library",
269271
]];
270272

271-
XcodeSubjectInfo *subjectInfo = [[[XcodeSubjectInfoalloc]init]autorelease];
273+
subjectInfo = [[XcodeSubjectInfoalloc]init];
272274
[subjectInfosetSubjectProject:[optionsproject]];
273275
[subjectInfosetSubjectScheme:[optionsscheme]];
274276
[subjectInfosetSubjectXcodeBuildArguments:[optionsxcodeBuildArgumentsForSubject]];
275277
[subjectInfosetReporters:@[]];
276278

277-
// The project has a different configuration set for each scheme action.
278-
assertThat([subjectInfoconfigurationNameForAction:@"TestAction"],equalTo(@"TestConfig"));
279-
assertThat([subjectInfoconfigurationNameForAction:@"LaunchAction"],equalTo(@"LaunchConfig"));
280-
assertThat([subjectInfoconfigurationNameForAction:@"AnalyzeAction"],equalTo(@"AnalyzeConfig"));
281-
assertThat([subjectInfoconfigurationNameForAction:@"ProfileAction"],equalTo(@"ProfileConfig"));
282-
assertThat([subjectInfoconfigurationNameForAction:@"ArchiveAction"],equalTo(@"ArchiveConfig"));
279+
[subjectInfoperformSelector:@selector(populate)];
283280
}];
281+
282+
return [subjectInfoautorelease];
283+
}
284+
285+
- (void)testCanGetBuildConfigurationForRunAction
286+
{
287+
XcodeSubjectInfo *subjectInfo =
288+
[selfxcodeSubjectInfoPopulatedWithProject:TEST_DATA@"TestProject-Library-WithDifferentConfigurations/TestProject-Library.xcodeproj"
289+
scheme:@"TestProject-Library"];
290+
291+
// The project has a different configuration set for each scheme action.
292+
assertThat([subjectInfoconfigurationNameForAction:@"TestAction"],equalTo(@"TestConfig"));
293+
assertThat([subjectInfoconfigurationNameForAction:@"LaunchAction"],equalTo(@"LaunchConfig"));
294+
assertThat([subjectInfoconfigurationNameForAction:@"AnalyzeAction"],equalTo(@"AnalyzeConfig"));
295+
assertThat([subjectInfoconfigurationNameForAction:@"ProfileAction"],equalTo(@"ProfileConfig"));
296+
assertThat([subjectInfoconfigurationNameForAction:@"ArchiveAction"],equalTo(@"ArchiveConfig"));
297+
}
298+
299+
- (void)testBuildActionPropertiesShouldPopulateFromScheme
300+
{
301+
XcodeSubjectInfo *subjectInfo =
302+
[selfxcodeSubjectInfoPopulatedWithProject:TEST_DATA@"TestProject-Library-WithDifferentConfigurations/TestProject-Library.xcodeproj"
303+
scheme:@"TestProject-Library"];
304+
305+
assertThatBool(subjectInfo.parallelizeBuildables,equalToBool(YES));
306+
assertThatBool(subjectInfo.buildImplicitDependencies,equalToBool(YES));
284307
}
285308

286309
@end

‎xctool/xctool/BuildTestsAction.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ + (BOOL)buildTestables:(NSArray *)testables
9292
xcodeSubjectInfo:(XcodeSubjectInfo *)xcodeSubjectInfo
9393
{
9494
SchemeGenerator *schemeGenerator = [SchemeGeneratorschemeGenerator];
95+
schemeGenerator.parallelizeBuildables = xcodeSubjectInfo.parallelizeBuildables;
96+
schemeGenerator.buildImplicitDependencies = xcodeSubjectInfo.buildImplicitDependencies;
97+
98+
// For Xcode's Find Implicit Dependencies to work, we must add every project
99+
// in the subject's workspace to the generated workspace.
100+
if (options.workspace) {
101+
NSArray *projectPaths = [XcodeSubjectInfoprojectPathsInWorkspace:options.workspace];
102+
for (NSString *projectPath in projectPaths) {
103+
[schemeGeneratoraddProjectPathToWorkspace:projectPath];
104+
}
105+
}elseif (options.project) {
106+
[schemeGeneratoraddProjectPathToWorkspace:options.project];
107+
}else {
108+
NSAssert(NO,@"Should have a workspace or a project.");
109+
}
110+
95111
for (NSDictionary *buildable in testables) {
96112
[schemeGeneratoraddBuildableWithID:buildable[@"targetID"]inProject:buildable[@"projectPath"]];
97113
}

‎xctool/xctool/SchemeGenerator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
*/
2222
@interfaceSchemeGenerator :NSObject
2323

24+
@property (nonatomic,assign)BOOL parallelizeBuildables;
25+
@property (nonatomic,assign)BOOL buildImplicitDependencies;
26+
2427
+ (SchemeGenerator *)schemeGenerator;
2528

2629
- (void)addBuildableWithID:(NSString *)identifier
2730
inProject:(NSString *)projectPath;
2831

32+
- (void)addProjectPathToWorkspace:(NSString *)projectPath;
33+
2934
/// Write the workspace into this directory.
3035
- (BOOL)writeWorkspaceNamed:(NSString *)name
3136
to:(NSString *)destination;

‎xctool/xctool/SchemeGenerator.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ - (void)addBuildableWithID:(NSString *)identifier
5050
{
5151
NSString *absPath = [[[NSURLfileURLWithPath:projectPath]URLByStandardizingPath]path];
5252
[_buildablesaddObject:@{@"id":identifier,@"project":absPath}];
53+
}
54+
55+
- (void)addProjectPathToWorkspace:(NSString *)projectPath
56+
{
57+
NSString *absPath = [[[NSURLfileURLWithPath:projectPath]URLByStandardizingPath]path];
5358
[_projectPathsaddObject:absPath];
5459
}
5560

@@ -179,8 +184,10 @@ - (NSXMLDocument *)_schemeDocument
179184
children:@[[NSXMLNodeelementWithName:@"PreActions"],
180185
[NSXMLNodeelementWithName:@"PostActions"],
181186
buildActionEntries]
182-
attributes:@[[NSXMLNodeattributeWithName:@"parallelizeBuildables"stringValue:@"NO"],
183-
[NSXMLNodeattributeWithName:@"buildImplicitDependencies"stringValue:@"NO"]]];
187+
attributes:@[[NSXMLNodeattributeWithName:@"parallelizeBuildables"
188+
stringValue:_parallelizeBuildables ?@"YES" :@"NO"],
189+
[NSXMLNodeattributeWithName:@"buildImplicitDependencies"
190+
stringValue:_buildImplicitDependencies ?@"YES" :@"NO"]]];
184191

185192
NSXMLElement *root =
186193
[NSXMLNode

‎xctool/xctool/XcodeSubjectInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
@property (nonatomic,retain)NSArray *testables;
4141
// Everything in the scheme marked as Build for Test
4242
@property (nonatomic,retain)NSArray *buildablesForTest;
43+
@property (nonatomic,assign)BOOL parallelizeBuildables;
44+
@property (nonatomic,assign)BOOL buildImplicitDependencies;
4345

4446
// buildables for Running or Testing
4547
@property (nonatomic,retain)NSArray *buildables;

‎xctool/xctool/XcodeSubjectInfo.m

Lines changed: 120 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,105 @@ - (NSDictionary *)buildSettingsForFirstBuildable
771771
return settings;
772772
}
773773

774+
- (NSString *)matchingSchemePathForWorkspace
775+
{
776+
NSString *matchingSchemePath =nil;
777+
778+
NSArray *schemePaths = [XcodeSubjectInfoschemePathsInWorkspace:self.subjectWorkspace];
779+
for (NSString *schemePath in schemePaths) {
780+
if ([schemePathhasSuffix:[NSStringstringWithFormat:@"/%@.xcscheme",self.subjectScheme]]) {
781+
matchingSchemePath = schemePath;
782+
}
783+
}
784+
785+
return matchingSchemePath;
786+
}
787+
788+
- (NSString *)matchingSchemePathForProject
789+
{
790+
NSString *matchingSchemePath =nil;
791+
792+
NSArray *schemePaths = [XcodeSubjectInfoschemePathsInContainer:self.subjectProject];
793+
for (NSString *schemePath in schemePaths) {
794+
if ([schemePathhasSuffix:[NSStringstringWithFormat:@"/%@.xcscheme",self.subjectScheme]]) {
795+
matchingSchemePath = schemePath;
796+
}
797+
}
798+
799+
return matchingSchemePath;
800+
}
801+
802+
- (void)populateBuildablesAndTestablesForWorkspaceWithSchemePath:(NSString *)schemePath
803+
{
804+
NSArray *testables = [[selfclass]testablesInSchemePath:schemePath
805+
basePath:BasePathFromSchemePath(schemePath)];
806+
NSArray *buildables = [[selfclass]buildablesInSchemePath:schemePath
807+
basePath:BasePathFromSchemePath(schemePath)];
808+
809+
810+
// It's possible that the scheme references projects that aren't part of the workspace. When
811+
// Xcode encounters these, it just skips them so we'll do the same.
812+
NSSet *projectPathsInWorkspace = [NSSetsetWithArray:[XcodeSubjectInfoprojectPathsInWorkspace:self.subjectWorkspace]];
813+
BOOL (^workspaceContainsProject)(id) = ^(id item) {
814+
return [projectPathsInWorkspacecontainsObject:[itemobjectForKey:@"projectPath"]];
815+
};
816+
817+
self.testables = [testablesobjectsAtIndexes:
818+
[testablesindexesOfObjectsPassingTest:
819+
^BOOL(id obj,NSUInteger idx,BOOL *stop) {
820+
returnworkspaceContainsProject(obj);
821+
}]];
822+
823+
self.buildables = [buildablesobjectsAtIndexes:
824+
[buildablesindexesOfObjectsPassingTest:
825+
^BOOL(id obj,NSUInteger idx,BOOL *stop) {
826+
returnworkspaceContainsProject(obj);
827+
}]];
828+
829+
self.buildablesForTest = [buildablesobjectsAtIndexes:
830+
[buildablesindexesOfObjectsPassingTest:
831+
^BOOL(id obj,NSUInteger idx,BOOL *stop) {
832+
return (workspaceContainsProject(obj) &&
833+
[[objobjectForKey:@"forTesting"]boolValue]);
834+
}]];
835+
}
836+
837+
- (void)populateBuildablesAndTestablesForProjectWithSchemePath:(NSString *)schemePath
838+
{
839+
self.testables = [[selfclass]testablesInSchemePath:schemePath
840+
basePath:BasePathFromSchemePath(schemePath)];
841+
842+
NSArray *buildables = [[selfclass]buildablesInSchemePath:schemePath
843+
basePath:BasePathFromSchemePath(schemePath)];
844+
self.buildablesForTest = [buildablesobjectsAtIndexes:
845+
[buildablesindexesOfObjectsPassingTest:
846+
^BOOL(id obj,NSUInteger idx,BOOL *stop) {
847+
return [[objobjectForKey:@"forTesting"]boolValue];
848+
}]];
849+
}
850+
851+
- (void)populateBuildActionPropertiesWithSchemePath:(NSString *)schemePath
852+
{
853+
NSError *error =nil;
854+
NSXMLDocument *doc = [[[NSXMLDocumentalloc]initWithContentsOfURL:[NSURLfileURLWithPath:schemePath]
855+
options:0
856+
error:&error]autorelease];
857+
if (error !=nil) {
858+
NSLog(@"Error in parsing:%@:%@", schemePath, error);
859+
abort();
860+
}
861+
862+
NSArray *buildActionNodes = [docnodesForXPath:@"//BuildAction"error:&error];
863+
NSAssert(error ==nil,@"Failed to get BuildAction node:%@", [errorlocalizedFailureReason]);
864+
NSAssert([buildActionNodescount] ==1,@"Should have only one BuildAction node");
865+
NSXMLElement *buildActionNode = buildActionNodes[0];
866+
867+
self.parallelizeBuildables =
868+
[[[buildActionNodeattributeForName:@"parallelizeBuildables"]stringValue]isEqualToString:@"YES"];
869+
self.buildImplicitDependencies =
870+
[[[buildActionNodeattributeForName:@"buildImplicitDependencies"]stringValue]isEqualToString:@"YES"];
871+
}
872+
774873
- (void)populate
775874
{
776875
if (_didPopulate) {
@@ -798,64 +897,19 @@ - (void)populate
798897
NSString *matchingSchemePath =nil;
799898

800899
if (self.subjectWorkspace) {
801-
NSArray *schemePaths = [XcodeSubjectInfoschemePathsInWorkspace:self.subjectWorkspace];
802-
for (NSString *schemePath in schemePaths) {
803-
if ([schemePathhasSuffix:[NSStringstringWithFormat:@"/%@.xcscheme",self.subjectScheme]]) {
804-
matchingSchemePath = schemePath;
805-
}
806-
}
807-
808-
NSArray *testables = [[selfclass]testablesInSchemePath:matchingSchemePath
809-
basePath:BasePathFromSchemePath(matchingSchemePath)];
810-
NSArray *buildables = [[selfclass]buildablesInSchemePath:matchingSchemePath
811-
basePath:BasePathFromSchemePath(matchingSchemePath)];
812-
813-
814-
// It's possible that the scheme references projects that aren't part of the workspace. When
815-
// Xcode encounters these, it just skips them so we'll do the same.
816-
NSSet *projectPathsInWorkspace = [NSSetsetWithArray:[XcodeSubjectInfoprojectPathsInWorkspace:self.subjectWorkspace]];
817-
BOOL (^workspaceContainsProject)(id) = ^(id item) {
818-
return [projectPathsInWorkspacecontainsObject:[itemobjectForKey:@"projectPath"]];
819-
};
820-
821-
self.testables = [testablesobjectsAtIndexes:
822-
[testablesindexesOfObjectsPassingTest:
823-
^BOOL(id obj,NSUInteger idx,BOOL *stop) {
824-
returnworkspaceContainsProject(obj);
825-
}]];
826-
827-
self.buildables = [buildablesobjectsAtIndexes:
828-
[buildablesindexesOfObjectsPassingTest:
829-
^BOOL(id obj,NSUInteger idx,BOOL *stop) {
830-
returnworkspaceContainsProject(obj);
831-
}]];
832-
833-
self.buildablesForTest = [buildablesobjectsAtIndexes:
834-
[buildablesindexesOfObjectsPassingTest:
835-
^BOOL(id obj,NSUInteger idx,BOOL *stop) {
836-
return (workspaceContainsProject(obj) &&
837-
[[objobjectForKey:@"forTesting"]boolValue]);
838-
}]];
900+
matchingSchemePath = [selfmatchingSchemePathForWorkspace];
839901
}else {
840-
NSArray *schemePaths = [XcodeSubjectInfoschemePathsInContainer:self.subjectProject];
841-
for (NSString *schemePath in schemePaths) {
842-
if ([schemePathhasSuffix:[NSStringstringWithFormat:@"/%@.xcscheme",self.subjectScheme]]) {
843-
matchingSchemePath = schemePath;
844-
}
845-
}
846-
847-
self.testables = [[selfclass]testablesInSchemePath:matchingSchemePath
848-
basePath:BasePathFromSchemePath(matchingSchemePath)];
902+
matchingSchemePath = [selfmatchingSchemePathForProject];
903+
}
849904

850-
NSArray *buildables = [[selfclass]buildablesInSchemePath:matchingSchemePath
851-
basePath:BasePathFromSchemePath(matchingSchemePath)];
852-
self.buildablesForTest = [buildablesobjectsAtIndexes:
853-
[buildablesindexesOfObjectsPassingTest:
854-
^BOOL(id obj,NSUInteger idx,BOOL *stop) {
855-
return [[objobjectForKey:@"forTesting"]boolValue];
856-
}]];
905+
if (self.subjectWorkspace) {
906+
[selfpopulateBuildablesAndTestablesForWorkspaceWithSchemePath:matchingSchemePath];
907+
}else {
908+
[selfpopulateBuildablesAndTestablesForProjectWithSchemePath:matchingSchemePath];
857909
}
858910

911+
[selfpopulateBuildActionPropertiesWithSchemePath:matchingSchemePath];
912+
859913
_configurationNameByAction =
860914
[BuildConfigurationsByActionForSchemePath(matchingSchemePath)retain];
861915

@@ -909,6 +963,18 @@ - (NSArray *)buildables
909963
return _buildables;
910964
}
911965

966+
- (BOOL)parallelizeBuildables
967+
{
968+
[selfpopulate];
969+
return _parallelizeBuildables;
970+
}
971+
972+
- (BOOL)buildImplicitDependencies
973+
{
974+
[selfpopulate];
975+
return _buildImplicitDependencies;
976+
}
977+
912978
- (NSArray *)testablesAndBuildablesForTest
913979
{
914980
[selfpopulate];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp