Debian Codegraph @

XCode/GSXCBuildContext.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 */ #import "GSXCBuildContext.h"
24
25 id _sharedBuildContext = nil;
26
27 @implementation GSXCBuildContext
28
29 + (id) sharedBuildContext
30 {
31 if(_sharedBuildContext == nil)
32 {
33 _sharedBuildContext = [[GSXCBuildContext alloc] init];
34 }
35 return _sharedBuildContext;
36 }
37
38 - (id) init
39 {
40 if((self = [super init]) != nil)
41 {
42 stack = [[NSMutableArray alloc] initWithCapacity: 10];
43 contextDictionary = [[NSMutableDictionary alloc] init];
44 config = [[NSDictionary alloc] initWithContentsOfFile: @"buildtool.plist"];
45 NSDebugLog(@"%@",config);
46 }
47 return self;
48 }
49
50 - (void) dealloc
51 {
52 RELEASE(stack);
53 RELEASE(contextDictionary);
54 RELEASE(config);
55
56 [super dealloc];
57 }
58
59 - (NSDictionary *) config
60 {
61 return config;
62 }
63
64 - (NSDictionary *) configForTargetName: (NSString *)name
65 {
66 NSDictionary *targetDict = [config objectForKey: name];
67 NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary: config];
68
69 if (targetDict != nil)
70 {
71 [result addEntriesFromDictionary: targetDict]; // override existing entries.
72 }
73
74 return result;
75 }
76
77 - (NSMutableDictionary *) currentContext
78 {
79 return currentContext;
80 }
81
82 - (NSMutableDictionary *) contextDictionaryForName: (NSString *)name
83 {
84 currentContext = [contextDictionary objectForKey: name];
85 if(currentContext == nil)
86 {
87 currentContext = [NSMutableDictionary dictionary];
88 [contextDictionary setObject: currentContext forKey: name];
89 [contextDictionary setObject: name forKey: @"TARGET_NAME"];
90 [stack addObject: currentContext];
91 }
92 return currentContext;
93 }
94
95 - (NSMutableDictionary *) popCurrentContext
96 {
97 NSMutableDictionary *popped = [stack lastObject];
98 [stack removeLastObject];
99 currentContext = [stack lastObject];
100 return popped;
101 }
102
103 - (void) setObject: (id)object forKey: (id)key
104 {
105 [currentContext setObject: object forKey: key];
106 }
107
108 - (id) objectForKey: (id)key
109 {
110 return [currentContext objectForKey: key];
111 }
112
113 - (void) addEntriesFromDictionary: (NSDictionary *)dict;
114 {
115 [currentContext addEntriesFromDictionary: dict];
116 }
117
118 - (NSString *) description
119 {
120 return [NSString stringWithFormat: @"%@ -- contextDictionary = %@, \n currentContext = %@, \n stack = %@ \n\n",
121 [super description], contextDictionary, currentContext, stack];
122 }
123 @end