config.py
1 # This source file is part of the Swift.org open source project 2 # 3 # Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors 4 # Licensed under Apache License v2.0 with Runtime Library Exception 5 # 6 # See http://swift.org/LICENSE.txt for license information 7 # See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 8 # 9 10 import json 11 12 from .path import Path 13 14 class Configuration: 15 Debug = "debug" 16 Release = "release" 17 version = 1 18 19 command = None 20 current = None 21 project = None 22 script_path = None 23 build_script_path = None 24 source_root = None 25 target = None 26 system_root = None 27 toolchain = None 28 linker = None 29 build_directory = None 30 intermediate_directory = None 31 module_cache_directory = None 32 install_directory = None 33 prefix = None 34 swift_install = None 35 pkg_config = None 36 requires_pkg_config = False 37 clang = None 38 clangxx = None 39 swift = None 40 swiftc = None 41 ar = None 42 swift_sdk = None 43 bootstrap_directory = None 44 verbose = False 45 extra_c_flags = None 46 extra_swift_flags = None 47 extra_ld_flags = None 48 build_mode = None 49 config_path = None # don't save this; else it would be recursive 50 variables = {} 51 def __init__(self): 52 pass 53 54 def _encode_path(self, path): 55 if path is not None: 56 return path.absolute() 57 else: 58 return None 59 60 def write(self, path): 61 info = { 62 'version' : self.version, 63 'command' : self.command, 64 'project' : self.project, 65 'script_path' : self._encode_path(self.script_path), 66 'build_script_path' : self._encode_path(self.build_script_path), 67 'source_root' : self._encode_path(self.source_root), 68 'target' : self.target.triple, 69 'system_root' : self._encode_path(self.system_root), 70 'toolchain' : self._encode_path(self.toolchain), 71 'linker' : self.linker, 72 'build_directory' : self._encode_path(self.build_directory), 73 'intermediate_directory' : self._encode_path(self.intermediate_directory), 74 'module_cache_directory' : self._encode_path(self.module_cache_directory), 75 'install_directory' : self._encode_path(self.install_directory), 76 'prefix' : self.prefix, 77 'swift_install' : self.swift_install, 78 'pkg_config' : self.pkg_config, 79 'requires_pkg_config' : self.requires_pkg_config, 80 'clang' : self.clang, 81 'clangxx' : self.clangxx, 82 'swift' : self.swift, 83 'swiftc' : self.swiftc, 84 'ar' : self.ar, 85 'swift_sdk' : self.swift_sdk, 86 'bootstrap_directory' : self._encode_path(self.bootstrap_directory), 87 'verbose' : self.verbose, 88 'extra_c_flags' : self.extra_c_flags, 89 'extra_swift_flags' : self.extra_swift_flags, 90 'extra_ld_flags' : self.extra_ld_flags, 91 'build_mode' : self.build_mode, 92 'variables' : self.variables, 93 } 94 with open(path, 'w+') as outfile: 95 json.dump(info, outfile) 96