Debian Codegraph @

XCode/PBXHeadersBuildPhase.m

raw
1 /*
2 Copyright (C) 2018, 2019, 2020, 2021 Free Software Foundation, Inc.
3
4 Written by: Gregory John Casamento <[email protected]>
5 Date: 2022
6
7 This file is part of the GNUstep XCode Library
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free
21 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110 USA.
23 */
24
25 #import <Foundation/Foundation.h>
26 #import "PBXCommon.h"
27 #import "PBXHeadersBuildPhase.h"
28 #import "PBXFileReference.h"
29 #import "PBXBuildFile.h"
30 #import "GSXCBuildContext.h"
31 #import "GSXCCommon.h"
32
33 @implementation PBXHeadersBuildPhase
34 - (BOOL) build
35 {
36 xcputs("=== Executing Headers Build Phase");
37 NSString *productType = [[GSXCBuildContext sharedBuildContext] objectForKey: @"PRODUCT_TYPE"];
38 if([productType isEqualToString: BUNDLE_TYPE] ||
39 [productType isEqualToString: TOOL_TYPE] ||
40 [productType isEqualToString: APPLICATION_TYPE])
41 {
42 xcputs([[NSString stringWithFormat: @"\t* %s%sWARN%s: No need to process headers for product type %@",BOLD, YELLOW, RESET, productType] cString]);
43 return YES;
44 }
45
46 xcputs([[NSString stringWithFormat: @"\t* Copying headers to derived sources folder..."] cString]);
47 NSFileManager *defaultManager = [NSFileManager defaultManager];
48 id file = nil;
49 BOOL result = YES;
50 GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
51 NSError *error = nil;
52
53 NSArray *synchronizedFiles = [_target synchronizedHeaders];
54 NSArray *files = [_files arrayByAddingObjectsFromArray: synchronizedFiles];
55
56 NSEnumerator *en = [files objectEnumerator];
57 NSString *derivedSourceHeaderDir = [context objectForKey: @"DERIVED_SOURCE_HEADER_DIR"];
58 while((file = [en nextObject]) != nil && result)
59 {
60 NSString *path = [[file fileRef] path];
61 NSString *srcFile = [[file fileRef] buildPath];
62 NSString *dstFile = [derivedSourceHeaderDir stringByAppendingPathComponent: [path lastPathComponent]];
63 BOOL copyResult = [defaultManager copyItemAtPath: srcFile
64 toPath: dstFile
65 error: &error];
66 xcputs([[NSString stringWithFormat: @"\tCopy %s%@%s -> %s%@%s", YELLOW, srcFile, RESET, GREEN, dstFile, RESET] cString]);
67 if(!copyResult)
68 {
69 xcputs([[NSString stringWithFormat: @"\t* Already exists"] cString]);
70 }
71 }
72
73 // Only copy into the framework header folder, if it's a framework...
74 if([productType isEqualToString: FRAMEWORK_TYPE])
75 {
76 xcputs([[NSString stringWithFormat: @"\t* Copying headers to framework header folder..."] cString]);
77 en = [_files objectEnumerator];
78 NSString *headerDir = [context objectForKey: @"HEADER_DIR"];
79 while((file = [en nextObject]) != nil && result)
80 {
81 NSString *path = [[file fileRef] path];
82 NSString *srcFile = [[file fileRef] buildPath];
83 NSString *dstFile = [headerDir stringByAppendingPathComponent: [path lastPathComponent]];
84 BOOL copyResult = [defaultManager copyItemAtPath: srcFile
85 toPath: dstFile
86 error: &error];
87 xcputs([[NSString stringWithFormat: @"\tCopy %s%@%s -> %s%@%s", YELLOW, srcFile, RESET, GREEN, dstFile, RESET] cString]);
88 if(!copyResult)
89 {
90 xcputs([[NSString stringWithFormat: @"\t* Already exists"] cString]);
91 }
92 }
93 }
94
95 xcputs([[NSString stringWithFormat: @"=== Completed Headers Build Phase"] cString]);
96
97 return result;
98 }
99
100 - (BOOL) generate
101 {
102 xcputs("=== Executing Headers Build Phase (Generate)");
103 NSString *productType = [[GSXCBuildContext sharedBuildContext] objectForKey: @"PRODUCT_TYPE"];
104 if([productType isEqualToString: BUNDLE_TYPE] ||
105 [productType isEqualToString: TOOL_TYPE] ||
106 [productType isEqualToString: APPLICATION_TYPE])
107 {
108 xcputs([[NSString stringWithFormat: @"\t* %s%sWARN%s: No need to process headers for product type %@",BOLD, YELLOW, RESET, productType] cString]);
109 return YES;
110 }
111
112 BOOL result = YES;
113 GSXCBuildContext *context = [GSXCBuildContext sharedBuildContext];
114
115 // NSString *derivedSourceHeaderDir = [context objectForKey: @"DERIVED_SOURCE_HEADER_DIR"];
116 [context setObject: _files forKey: @"DERIVED_HEADERS"];
117 xcputs([[NSString stringWithFormat: @"\tAdding entry for derived header files"] cString]);
118
119 // Only copy into the framework header folder, if it's a framework...
120 if([productType isEqualToString: FRAMEWORK_TYPE])
121 {
122 // NSString *headerDir = [context objectForKey: @"HEADER_DIR"];
123 [context setObject: _files forKey: @"HEADERS"];
124 xcputs([[NSString stringWithFormat: @"\tAdding entry for derived header"] cString]);
125 }
126
127 xcputs([[NSString stringWithFormat: @"=== Completed Headers Build Phase (Generate)"] cString]);
128
129 return result;
130 }
131
132 - (BOOL) link
133 {
134 return YES;
135 }
136
137 @end