idb/FBControlCore/Utility/FBControlCoreGlobalConfigur...

110 строки
2.7 KiB
Mathematica
Исходник Обычный вид История

/*
* Copyright (c) Facebook, Inc. and its affiliates.
2015-09-09 00:41:39 +03:00
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
2015-09-09 00:41:39 +03:00
*/
#import "FBControlCoreGlobalConfiguration.h"
2015-09-09 00:41:39 +03:00
#import <Foundation/Foundation.h>
#import "FBControlCoreLogger.h"
2015-09-09 00:41:39 +03:00
NSString *const FBControlCoreStderrLogging = @"FBCONTROLCORE_LOGGING";
NSString *const FBControlCoreDebugLogging = @"FBCONTROLCORE_DEBUG_LOGGING";
NSString *const ConfirmShimsAreSignedEnv = @"FBCONTROLCORE_CONFIRM_SIGNED_SHIMS";
2015-12-15 21:57:20 +03:00
static id<FBControlCoreLogger> logger;
2016-01-26 20:30:32 +03:00
@implementation FBControlCoreGlobalConfiguration
2015-09-09 00:41:39 +03:00
2015-12-23 15:57:46 +03:00
+ (NSTimeInterval)fastTimeout
{
return 10;
}
+ (NSTimeInterval)regularTimeout
{
return 30;
}
+ (NSTimeInterval)slowTimeout
{
return 120;
}
+ (id<FBControlCoreLogger>)defaultLogger
{
2016-01-26 20:30:32 +03:00
if (logger) {
return logger;
}
logger = [self createDefaultLogger];
2015-12-29 17:32:53 +03:00
return logger;
}
+ (void)setDefaultLogger:(id<FBControlCoreLogger>)defaultLogger
{
if (logger) {
[defaultLogger.debug logFormat:@"Overriding the Default Logger with %@", defaultLogger];
}
logger = defaultLogger;
}
+ (BOOL)confirmCodesignaturesAreValid
{
return NSProcessInfo.processInfo.environment[ConfirmShimsAreSignedEnv].boolValue;
}
+ (NSString *)description
{
return [NSString stringWithFormat:@"Default Logger %@", logger];
}
- (NSString *)description
{
return [FBControlCoreGlobalConfiguration description];
}
+ (NSDictionary<NSString *, NSString *> *)safeSubprocessEnvironment
{
NSDictionary<NSString *, NSString *> *env = NSProcessInfo.processInfo.environment;
NSMutableDictionary<NSString *, NSString *> *modified = NSMutableDictionary.dictionary;
for (NSString *key in env) {
if ([key containsString:@"TERMCAP"]) {
continue;
}
modified[key] = env[key];
}
return [modified copy];
}
2016-01-26 20:30:32 +03:00
#pragma mark Private
+ (id<FBControlCoreLogger>)createDefaultLogger
2016-01-26 20:30:32 +03:00
{
return [FBControlCoreLogger systemLoggerWritingToStderr:self.stderrLoggingEnabledByDefault withDebugLogging:self.debugLoggingEnabledByDefault];
2016-01-26 20:30:32 +03:00
}
+ (BOOL)stderrLoggingEnabledByDefault
2016-01-26 20:30:32 +03:00
{
return [NSProcessInfo.processInfo.environment[FBControlCoreStderrLogging] boolValue];
}
+ (BOOL)debugLoggingEnabledByDefault
{
return [NSProcessInfo.processInfo.environment[FBControlCoreDebugLogging] boolValue];
2016-01-26 20:30:32 +03:00
}
+ (nullable id)readValueForKey:(NSString *)key fromPlistAtPath:(NSString *)plistPath
{
NSCAssert([NSFileManager.defaultManager fileExistsAtPath:plistPath], @"plist does not exist at path '%@'", plistPath);
NSDictionary *infoPlist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSCAssert(infoPlist, @"Could not read plist at '%@'", plistPath);
id value = infoPlist[key];
NSCAssert(value, @"'%@' does not exist in plist '%@'", key, infoPlist.allKeys);
return value;
}
@end