Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: pylib/gyp/generator/ninja.py

Issue 1160773005: Support for Swift language and Clang modules for ninja generator. Base URL: https://chromium.googlesource.com/external/gyp@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pylib/gyp/mac_tool.py » ('j') | pylib/gyp/xcode_emulation.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 Google Inc. All rights reserved. 1 # Copyright (c) 2013 Google Inc. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import collections 5 import collections
6 import copy 6 import copy
7 import hashlib 7 import hashlib
8 import json 8 import json
9 import multiprocessing 9 import multiprocessing
10 import os.path 10 import os.path
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 # File representing the completion of actions/rules/copies, if any. 133 # File representing the completion of actions/rules/copies, if any.
134 self.actions_stamp = None 134 self.actions_stamp = None
135 # Path to the output of the link step, if any. 135 # Path to the output of the link step, if any.
136 self.binary = None 136 self.binary = None
137 # Path to the file representing the completion of building the bundle, 137 # Path to the file representing the completion of building the bundle,
138 # if any. 138 # if any.
139 self.bundle = None 139 self.bundle = None
140 # On Windows, incremental linking requires linking against all the .objs 140 # On Windows, incremental linking requires linking against all the .objs
141 # that compose a .lib (rather than the .lib itself). That list is stored 141 # that compose a .lib (rather than the .lib itself). That list is stored
142 # here. 142 # here.
143
144 # Path to the file representing completion of building module, if any.
145 self.module_stamp = None
146
143 self.component_objs = None 147 self.component_objs = None
144 # Windows only. The import .lib is the output of a build step, but 148 # Windows only. The import .lib is the output of a build step, but
145 # because dependents only link against the lib (not both the lib and the 149 # because dependents only link against the lib (not both the lib and the
146 # dll) we keep track of the import library here. 150 # dll) we keep track of the import library here.
147 self.import_lib = None 151 self.import_lib = None
148 152
149 def Linkable(self): 153 def Linkable(self):
150 """Return true if this is a target that can be linked against.""" 154 """Return true if this is a target that can be linked against."""
151 return self.type in ('static_library', 'shared_library') 155 return self.type in ('static_library', 'shared_library')
152 156
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 self.name = spec['target_name'] 373 self.name = spec['target_name']
370 self.toolset = spec['toolset'] 374 self.toolset = spec['toolset']
371 config = spec['configurations'][config_name] 375 config = spec['configurations'][config_name]
372 self.target = Target(spec['type']) 376 self.target = Target(spec['type'])
373 self.is_standalone_static_library = bool( 377 self.is_standalone_static_library = bool(
374 spec.get('standalone_static_library', 0)) 378 spec.get('standalone_static_library', 0))
375 # Track if this target contains any C++ files, to decide if gcc or g++ 379 # Track if this target contains any C++ files, to decide if gcc or g++
376 # should be used for linking. 380 # should be used for linking.
377 self.uses_cpp = False 381 self.uses_cpp = False
378 382
383 # Track if there are any swift sources
384 self.uses_swift = False
385
379 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec) 386 self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
380 self.xcode_settings = self.msvs_settings = None 387 self.xcode_settings = self.msvs_settings = None
381 if self.flavor == 'mac': 388 if self.flavor == 'mac':
382 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec) 389 self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
383 if self.flavor == 'win': 390 if self.flavor == 'win':
384 self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec, 391 self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec,
385 generator_flags) 392 generator_flags)
386 arch = self.msvs_settings.GetArch(config_name) 393 arch = self.msvs_settings.GetArch(config_name)
387 self.ninja.variable('arch', self.win_env[arch]) 394 self.ninja.variable('arch', self.win_env[arch])
388 self.ninja.variable('cc', '$cl_' + arch) 395 self.ninja.variable('cc', '$cl_' + arch)
(...skipping 12 matching lines...) Expand all
401 'w'))) 408 'w')))
402 for arch in self.archs) 409 for arch in self.archs)
403 410
404 # Compute predepends for all rules. 411 # Compute predepends for all rules.
405 # actions_depends is the dependencies this target depends on before running 412 # actions_depends is the dependencies this target depends on before running
406 # any of its action/rule/copy steps. 413 # any of its action/rule/copy steps.
407 # compile_depends is the dependencies this target depends on before running 414 # compile_depends is the dependencies this target depends on before running
408 # any of its compile steps. 415 # any of its compile steps.
409 actions_depends = [] 416 actions_depends = []
410 compile_depends = [] 417 compile_depends = []
418 module_depends = []
411 # TODO(evan): it is rather confusing which things are lists and which 419 # TODO(evan): it is rather confusing which things are lists and which
412 # are strings. Fix these. 420 # are strings. Fix these.
413 if 'dependencies' in spec: 421 if 'dependencies' in spec:
414 for dep in spec['dependencies']: 422 for dep in spec['dependencies']:
415 if dep in self.target_outputs: 423 if dep in self.target_outputs:
416 target = self.target_outputs[dep] 424 target = self.target_outputs[dep]
417 actions_depends.append(target.PreActionInput(self.flavor)) 425 actions_depends.append(target.PreActionInput(self.flavor))
418 compile_depends.append(target.PreCompileInput()) 426 compile_depends.append(target.PreCompileInput())
427 module_depends.append(target.module_stamp)
419 actions_depends = filter(None, actions_depends) 428 actions_depends = filter(None, actions_depends)
420 compile_depends = filter(None, compile_depends) 429 compile_depends = filter(None, compile_depends)
430 module_depends = filter(None, module_depends)
431 if (self.flavor == 'mac' and
432 self.xcode_settings.AreModulesEnabled(config_name)):
433 compile_depends += module_depends
434
421 actions_depends = self.WriteCollapsedDependencies('actions_depends', 435 actions_depends = self.WriteCollapsedDependencies('actions_depends',
422 actions_depends) 436 actions_depends)
423 compile_depends = self.WriteCollapsedDependencies('compile_depends', 437 compile_depends = self.WriteCollapsedDependencies('compile_depends',
424 compile_depends) 438 compile_depends)
425 self.target.preaction_stamp = actions_depends 439 self.target.preaction_stamp = actions_depends
426 self.target.precompile_stamp = compile_depends 440 self.target.precompile_stamp = compile_depends
427 441
428 # Write out actions, rules, and copies. These must happen before we 442 # Write out actions, rules, and copies. These must happen before we
429 # compile any sources, so compute a list of predependencies for sources 443 # compile any sources, so compute a list of predependencies for sources
430 # while we do it. 444 # while we do it.
431 extra_sources = [] 445 extra_sources = []
432 mac_bundle_depends = [] 446 mac_bundle_depends = []
433 self.target.actions_stamp = self.WriteActionsRulesCopies( 447 self.target.actions_stamp = self.WriteActionsRulesCopies(
434 spec, extra_sources, actions_depends, mac_bundle_depends) 448 spec, extra_sources, actions_depends, mac_bundle_depends)
435 449
436 # If we have actions/rules/copies, we depend directly on those, but 450 # If we have actions/rules/copies, we depend directly on those, but
437 # otherwise we depend on dependent target's actions/rules/copies etc. 451 # otherwise we depend on dependent target's actions/rules/copies etc.
438 # We never need to explicitly depend on previous target's link steps, 452 # We never need to explicitly depend on previous target's link steps,
439 # because no compile ever depends on them. 453 # because no compile ever depends on them.
440 compile_depends_stamp = (self.target.actions_stamp or compile_depends) 454 compile_depends_stamp = (self.target.actions_stamp or compile_depends)
441 455
456 if self.flavor == 'mac':
457 # Module should be written before compilaton, because Swift compiler
458 # use it
459 module_stamp = self.WriteModule(self.ninja, compile_depends_stamp,
460 config_name, spec)
461 if module_stamp:
462 compile_depends_stamp = module_stamp
463
442 # Write out the compilation steps, if any. 464 # Write out the compilation steps, if any.
443 link_deps = [] 465 link_deps = []
444 sources = extra_sources + spec.get('sources', []) 466 sources = extra_sources + spec.get('sources', [])
445 if sources: 467 if sources:
446 if self.flavor == 'mac' and len(self.archs) > 1: 468 if self.flavor == 'mac' and len(self.archs) > 1:
447 # Write subninja file containing compile and link commands scoped to 469 # Write subninja file containing compile and link commands scoped to
448 # a single arch if a fat binary is being built. 470 # a single arch if a fat binary is being built.
449 for arch in self.archs: 471 for arch in self.archs:
450 self.ninja.subninja(self._SubninjaNameForArch(arch)) 472 self.ninja.subninja(self._SubninjaNameForArch(arch))
451 473
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 [partial_info_plist, info_plist]) 870 [partial_info_plist, info_plist])
849 871
850 keys = self.xcode_settings.GetExtraPlistItems(self.config_name) 872 keys = self.xcode_settings.GetExtraPlistItems(self.config_name)
851 keys = QuoteShellArgument(json.dumps(keys), self.flavor) 873 keys = QuoteShellArgument(json.dumps(keys), self.flavor)
852 isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name) 874 isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name)
853 self.ninja.build(out, 'copy_infoplist', info_plist, 875 self.ninja.build(out, 'copy_infoplist', info_plist,
854 variables=[('env', env), ('keys', keys), 876 variables=[('env', env), ('keys', keys),
855 ('binary', isBinary)]) 877 ('binary', isBinary)])
856 bundle_depends.append(out) 878 bundle_depends.append(out)
857 879
880 def _AddSwiftModuleExt(self, module):
881 return module + '.swiftmodule'
882
883 def _GetSwiftModulePath(self, config_name, spec, arch=None):
884 module_path = self._AddSwiftModuleExt(
885 self.xcode_settings.GetProductModuleName(config_name))
886 if self._IsFramework(spec):
887 module_path = os.path.join(
888 self.xcode_settings.GetBundleModulesFolderPath(), module_path)
889 if arch:
890 # Fixing path for armv7, since Xcode expects it to have 'arm' name instead
891 if arch == 'armv7':
892 arch = 'arm'
893 module_path = os.path.join(module_path, self._AddSwiftModuleExt(arch))
894 return module_path
895
896 def WriteFrameworkHeaders(self, ninja_file, headers, headers_dir):
897 outputs = []
898 for header in headers:
899 out_path = os.path.join(headers_dir, os.path.basename(header))
900 outputs.append(out_path)
901 self.ninja.build(out_path, 'mac_tool', header,
902 variables=[('mactool_cmd', 'copy-bundle-resource'), \
903 ('binary', False)])
904 return outputs
905
906 def _GetModuleMapFilePath(self):
907 return os.path.join(self.xcode_settings.GetBundleModulesFolderPath(),
908 'module.modulemap')
909
910 def _IsFramework(self, spec):
911 is_framework = (spec['type'] == 'shared_library') and self.is_mac_bundle
912 return is_framework
913
914 def WriteModule(self, ninja_file, predepends, config_name, spec):
915 """Write build rules to build Clang module."""
916 if not self.xcode_settings.IsModuleDefined(config_name):
917 return None
918 if not self._IsFramework(spec):
919 # There are no any actions by Xcode for non-framework targets
920 return None
921
922 assert(self.xcode_settings.AreModulesEnabled(config_name))
923
924 ninja_file.newline()
925
926 module_inputs = []
927 # Copying headers to framework
928 public_headers = map(self.GypPathToNinja,
929 list(spec.get('mac_framework_headers', [])))
930 module_inputs += self.WriteFrameworkHeaders(
931 ninja_file, public_headers,
932 self.xcode_settings.GetBundlePublicHeadersFolderPath())
933
934 private_headers = map(self.GypPathToNinja,
935 list(spec.get('mac_framework_private_headers', [])))
936 module_inputs += self.WriteFrameworkHeaders(
937 ninja_file, private_headers,
938 self.xcode_settings.GetBundlePrivateHeadersFolderPath())
939
940 module_name = self.xcode_settings.GetProductModuleName(config_name)
941 umbrella_header = None
942 for header in public_headers:
943 filename, _ = os.path.splitext(os.path.basename(header))
944 if filename == module_name:
945 umbrella_header = header
946 break
947
948 assert(umbrella_header)
949
950 # Building module map file in the /Modules folder
951 module_map_path = self._GetModuleMapFilePath()
952 variables = {
953 'module_name': module_name,
954 'umbrella_header': os.path.basename(umbrella_header),
955 'map_file': module_map_path }
956 module_map_stamp = self.GypPathToUniqueOutput('modulemap.stamp')
957 self.ninja.build(module_map_stamp, 'modulemap', [umbrella_header],
958 variables=variables)
959 module_inputs.append(module_map_stamp)
960
961 # Resulting module stamp
962 module_stamp = self.GypPathToUniqueOutput('module.stamp')
963 self.ninja.build(module_stamp, 'stamp', module_inputs,
964 order_only=predepends)
965 self.target.module_stamp = module_stamp
966 ninja_file.newline()
967 return module_stamp
968
969 def WriteSwiftSourcesForArch(self, ninja_file, config_name, sources,
970 predepends, spec, arch=None):
971 assert(self.flavor == 'mac')
972
973 # Collecting all Swift sources
974 swift_sources = []
975 for source in sources:
976 filename, ext = os.path.splitext(source)
977 ext = ext[1:]
978 if ext == 'swift':
979 swift_sources.append(self.GypPathToNinja(source))
980 if not swift_sources:
981 return ([], None)
982
983 self.uses_swift = True
984
985 if not arch:
986 arch = self.archs[0]
987
988 # Writing compile flags
989 swift_compile_flags = self.xcode_settings.GetSwiftCompileFlags(
990 config_name, self.GypPathToNinja, arch)
991 self.WriteVariableList(ninja_file, 'swift_compile_flags',
992 map(self.ExpandSpecial, swift_compile_flags))
993 ninja_file.newline()
994
995 # Writing per-file rules
996 link_deps = []
997 partial_modules = []
998 for source in swift_sources:
999 filename, ext = os.path.splitext(os.path.basename(source))
1000 obj_path = self.GypPathToUniqueOutput(filename + self.obj_ext)
1001 obj_path = AddArch(obj_path, arch)
1002 src_module_path = self.GypPathToUniqueOutput(
1003 self._AddSwiftModuleExt(filename))
1004 src_module_path = AddArch(src_module_path, arch)
1005
1006 compile_input = [source]
1007 for another_source in swift_sources:
1008 if source != another_source:
1009 compile_input.append(another_source)
1010
1011 variables = {'out_obj': obj_path, 'out_module': src_module_path}
1012 ninja_file.build([obj_path, src_module_path], 'swift', compile_input,
1013 variables=variables,
1014 order_only=predepends)
1015
1016 link_deps.append(obj_path)
1017 partial_modules.append(src_module_path)
1018
1019 ninja_file.newline()
1020
1021 # Writing Swift merge flags
1022 swift_merge_flags = self.xcode_settings.GetSwiftMergeFlags(
1023 config_name, self.GypPathToNinja, arch)
1024 self.WriteVariableList(ninja_file, 'swift_merge_flags',
1025 map(self.ExpandSpecial, swift_merge_flags))
1026 ninja_file.newline()
1027
1028
1029 # Writing header for first arch without arch extension,
1030 # for it to be used by Objc sources
1031 header_arch = None if arch == self.archs[0] else arch
1032 header_path = self.xcode_settings.GetSwiftHeaderPath(
1033 config_name, self.GypPathToNinja, header_arch)
1034 module_path = self._GetSwiftModulePath(config_name, spec, arch)
1035 variables = {'out_module': module_path, 'out_header': header_path}
1036 ninja_file.build([module_path, header_path], 'swiftmerge',
1037 partial_modules, variables=variables)
1038 ninja_file.newline()
1039
1040 return (link_deps, module_path)
1041
1042 def WriteSwiftModule(self, ninja_file, config_name, spec):
1043 """Write build rules to build Swift module data"""
1044 if not self.uses_swift:
1045 return
1046
1047 assert(self.xcode_settings.AreModulesEnabled(config_name))
1048
1049 ninja_file.newline()
1050
1051 module_inputs = []
1052 map_depends = []
1053 for arch in self.archs:
1054 swift_module_path = self._GetSwiftModulePath(config_name, spec, arch)
1055 module_inputs.append(swift_module_path)
1056 map_depends.append(swift_module_path)
1057
1058 if self._IsFramework(spec):
1059 assert(self.xcode_settings.IsModuleDefined(config_name))
1060
1061 # Copying Swift header to framework
1062 swift_header = self.xcode_settings.GetSwiftHeaderPath(
1063 config_name, self.GypPathToNinja)
1064 module_inputs += self.WriteFrameworkHeaders(
1065 ninja_file, [swift_header],
1066 self.xcode_settings.GetBundlePublicHeadersFolderPath())
1067
1068 # Appending Swift info to the module map file in the /Modules folder
1069 module_name = self.xcode_settings.GetProductModuleName(config_name)
1070 module_map_path = self._GetModuleMapFilePath()
1071 variables = {
1072 'module_name': module_name,
1073 'swift_header': os.path.basename(swift_header),
1074 'map_file': module_map_path }
1075 module_map_stamp = self.GypPathToUniqueOutput('swiftmodulemap.stamp')
1076 self.ninja.build(module_map_stamp, 'swiftmodulemap', [swift_header],
1077 order_only=map_depends, variables=variables)
1078 module_inputs.append(module_map_stamp)
1079
1080 # Resulting Swift actions stamp
1081 module_stamp = self.GypPathToUniqueOutput('swift_module.stamp')
1082 self.ninja.build(module_stamp, 'stamp', module_inputs)
1083 self.target.module_stamp = module_stamp
1084 ninja_file.newline()
1085
1086 def AppendSwiftLinkerOptions(self, ldflags, implicit_deps, config_name, spec,
1087 arch):
1088 if not self.uses_swift:
1089 return
1090 if arch is None:
1091 arch = self.archs[0]
1092 module_path = self._GetSwiftModulePath(config_name, spec, arch)
1093 ldflags += self.xcode_settings.GetSwiftLdflags(config_name, module_path)
1094 implicit_deps.add(module_path)
1095
1096 def CopySwiftLibsToBundle(self, spec):
1097 is_final = spec['type'] in ('executable', 'loadable_module')
1098 if not gyp.xcode_emulation.IsSwiftSupported() or not is_final:
1099 return None
1100
1101 # Copying all needed Swift dylibs right into the bundle
1102 app_frameworks_path = (
1103 self.xcode_settings.GetBundleFrameworksFolderPath())
1104 swift_libs_path = self.xcode_settings.GetSwiftLibsPath(self.config_name)
1105 variables = {'swift_libs_path': swift_libs_path}
1106 self.ninja.build(app_frameworks_path, 'copyswiftlibs', self.target.binary,
1107 variables=variables)
1108 return app_frameworks_path
1109
858 def WriteSources(self, ninja_file, config_name, config, sources, predepends, 1110 def WriteSources(self, ninja_file, config_name, config, sources, predepends,
859 precompiled_header, spec): 1111 precompiled_header, spec):
860 """Write build rules to compile all of |sources|.""" 1112 """Write build rules to compile all of |sources|."""
861 if self.toolset == 'host': 1113 if self.toolset == 'host':
862 self.ninja.variable('ar', '$ar_host') 1114 self.ninja.variable('ar', '$ar_host')
863 self.ninja.variable('cc', '$cc_host') 1115 self.ninja.variable('cc', '$cc_host')
864 self.ninja.variable('cxx', '$cxx_host') 1116 self.ninja.variable('cxx', '$cxx_host')
865 self.ninja.variable('ld', '$ld_host') 1117 self.ninja.variable('ld', '$ld_host')
866 self.ninja.variable('ldxx', '$ldxx_host') 1118 self.ninja.variable('ldxx', '$ldxx_host')
867 self.ninja.variable('nm', '$nm_host') 1119 self.ninja.variable('nm', '$nm_host')
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 map(self.ExpandSpecial, cflags_cc)) 1221 map(self.ExpandSpecial, cflags_cc))
970 if self.flavor == 'mac': 1222 if self.flavor == 'mac':
971 self.WriteVariableList(ninja_file, 'cflags_objc', 1223 self.WriteVariableList(ninja_file, 'cflags_objc',
972 map(self.ExpandSpecial, cflags_objc)) 1224 map(self.ExpandSpecial, cflags_objc))
973 self.WriteVariableList(ninja_file, 'cflags_objcc', 1225 self.WriteVariableList(ninja_file, 'cflags_objcc',
974 map(self.ExpandSpecial, cflags_objcc)) 1226 map(self.ExpandSpecial, cflags_objcc))
975 self.WriteVariableList(ninja_file, 'arflags', 1227 self.WriteVariableList(ninja_file, 'arflags',
976 map(self.ExpandSpecial, arflags)) 1228 map(self.ExpandSpecial, arflags))
977 ninja_file.newline() 1229 ninja_file.newline()
978 outputs = [] 1230 outputs = []
1231
1232 if self.flavor == 'mac':
1233 swift_outputs, swift_module = self.WriteSwiftSourcesForArch(
1234 ninja_file, config_name, sources, predepends, spec, arch)
1235 outputs += swift_outputs
1236 predepends = swift_module or predepends
1237
979 has_rc_source = False 1238 has_rc_source = False
980 for source in sources: 1239 for source in sources:
981 filename, ext = os.path.splitext(source) 1240 filename, ext = os.path.splitext(source)
982 ext = ext[1:] 1241 ext = ext[1:]
983 obj_ext = self.obj_ext 1242 obj_ext = self.obj_ext
984 if ext in ('cc', 'cpp', 'cxx'): 1243 if ext in ('cc', 'cpp', 'cxx'):
985 command = 'cxx' 1244 command = 'cxx'
986 self.uses_cpp = True 1245 self.uses_cpp = True
987 elif ext == 'c' or (ext == 'S' and self.flavor != 'win'): 1246 elif ext == 'c' or (ext == 'S' and self.flavor != 'win'):
988 command = 'cc' 1247 command = 'cc'
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 1391
1133 is_executable = spec['type'] == 'executable' 1392 is_executable = spec['type'] == 'executable'
1134 # The ldflags config key is not used on mac or win. On those platforms 1393 # The ldflags config key is not used on mac or win. On those platforms
1135 # linker flags are set via xcode_settings and msvs_settings, respectively. 1394 # linker flags are set via xcode_settings and msvs_settings, respectively.
1136 env_ldflags = os.environ.get('LDFLAGS', '').split() 1395 env_ldflags = os.environ.get('LDFLAGS', '').split()
1137 if self.flavor == 'mac': 1396 if self.flavor == 'mac':
1138 ldflags = self.xcode_settings.GetLdflags(config_name, 1397 ldflags = self.xcode_settings.GetLdflags(config_name,
1139 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']), 1398 self.ExpandSpecial(generator_default_variables['PRODUCT_DIR']),
1140 self.GypPathToNinja, arch) 1399 self.GypPathToNinja, arch)
1141 ldflags = env_ldflags + ldflags 1400 ldflags = env_ldflags + ldflags
1401 self.AppendSwiftLinkerOptions(
1402 ldflags, implicit_deps, config_name, spec, arch)
1142 elif self.flavor == 'win': 1403 elif self.flavor == 'win':
1143 manifest_base_name = self.GypPathToUniqueOutput( 1404 manifest_base_name = self.GypPathToUniqueOutput(
1144 self.ComputeOutputFileName(spec)) 1405 self.ComputeOutputFileName(spec))
1145 ldflags, intermediate_manifest, manifest_files = \ 1406 ldflags, intermediate_manifest, manifest_files = \
1146 self.msvs_settings.GetLdflags(config_name, self.GypPathToNinja, 1407 self.msvs_settings.GetLdflags(config_name, self.GypPathToNinja,
1147 self.ExpandSpecial, manifest_base_name, 1408 self.ExpandSpecial, manifest_base_name,
1148 output, is_executable, 1409 output, is_executable,
1149 self.toplevel_build) 1410 self.toplevel_build)
1150 ldflags = env_ldflags + ldflags 1411 ldflags = env_ldflags + ldflags
1151 self.WriteVariableList(ninja_file, 'manifests', manifest_files) 1412 self.WriteVariableList(ninja_file, 'manifests', manifest_files)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 1502
1242 if len(solibs): 1503 if len(solibs):
1243 extra_bindings.append(('solibs', gyp.common.EncodePOSIXShellList(solibs))) 1504 extra_bindings.append(('solibs', gyp.common.EncodePOSIXShellList(solibs)))
1244 1505
1245 ninja_file.build(output, command + command_suffix, link_deps, 1506 ninja_file.build(output, command + command_suffix, link_deps,
1246 implicit=list(implicit_deps), 1507 implicit=list(implicit_deps),
1247 variables=extra_bindings) 1508 variables=extra_bindings)
1248 return linked_binary 1509 return linked_binary
1249 1510
1250 def WriteTarget(self, spec, config_name, config, link_deps, compile_deps): 1511 def WriteTarget(self, spec, config_name, config, link_deps, compile_deps):
1512 self.WriteSwiftModule(self.ninja, config_name, spec)
1251 extra_link_deps = any(self.target_outputs.get(dep).Linkable() 1513 extra_link_deps = any(self.target_outputs.get(dep).Linkable()
1252 for dep in spec.get('dependencies', []) 1514 for dep in spec.get('dependencies', [])
1253 if dep in self.target_outputs) 1515 if dep in self.target_outputs)
1254 if spec['type'] == 'none' or (not link_deps and not extra_link_deps): 1516 if spec['type'] == 'none' or (not link_deps and not extra_link_deps):
1255 # TODO(evan): don't call this function for 'none' target types, as 1517 # TODO(evan): don't call this function for 'none' target types, as
1256 # it doesn't do anything, and we fake out a 'binary' with a stamp file. 1518 # it doesn't do anything, and we fake out a 'binary' with a stamp file.
1257 self.target.binary = compile_deps 1519 self.target.binary = compile_deps
1258 self.target.type = 'none' 1520 self.target.type = 'none'
1259 elif spec['type'] == 'static_library': 1521 elif spec['type'] == 'static_library':
1260 self.target.binary = self.ComputeOutput(spec) 1522 self.target.binary = self.ComputeOutput(spec)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 self.ninja.build(self.target.binary, 'alink', inputs, 1555 self.ninja.build(self.target.binary, 'alink', inputs,
1294 # FIXME: test proving order_only=compile_deps isn't 1556 # FIXME: test proving order_only=compile_deps isn't
1295 # needed. 1557 # needed.
1296 variables=variables) 1558 variables=variables)
1297 else: 1559 else:
1298 self.target.binary = self.WriteLink(spec, config_name, config, link_deps) 1560 self.target.binary = self.WriteLink(spec, config_name, config, link_deps)
1299 return self.target.binary 1561 return self.target.binary
1300 1562
1301 def WriteMacBundle(self, spec, mac_bundle_depends, is_empty): 1563 def WriteMacBundle(self, spec, mac_bundle_depends, is_empty):
1302 assert self.is_mac_bundle 1564 assert self.is_mac_bundle
1565
1566 swift_frameworks = self.CopySwiftLibsToBundle(spec)
1567 if swift_frameworks:
1568 mac_bundle_depends.append(swift_frameworks)
1569
1570 if self.target.module_stamp:
1571 mac_bundle_depends.append(self.target.module_stamp)
1572
1303 package_framework = spec['type'] in ('shared_library', 'loadable_module') 1573 package_framework = spec['type'] in ('shared_library', 'loadable_module')
1304 output = self.ComputeMacBundleOutput() 1574 output = self.ComputeMacBundleOutput()
1305 if is_empty: 1575 if is_empty:
1306 output += '.stamp' 1576 output += '.stamp'
1307 variables = [] 1577 variables = []
1308 self.AppendPostbuildVariable(variables, spec, output, self.target.binary, 1578 self.AppendPostbuildVariable(variables, spec, output, self.target.binary,
1309 is_command_start=not package_framework) 1579 is_command_start=not package_framework)
1310 if package_framework and not is_empty: 1580 if package_framework and not is_empty:
1311 variables.append(('version', self.xcode_settings.GetFrameworkVersion())) 1581 variables.append(('version', self.xcode_settings.GetFrameworkVersion()))
1312 self.ninja.build(output, 'package_framework', mac_bundle_depends, 1582 self.ninja.build(output, 'package_framework', mac_bundle_depends,
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 master_ninja.variable('ldxx', CommandWithWrapper('LINK', wrappers, ldxx)) 2185 master_ninja.variable('ldxx', CommandWithWrapper('LINK', wrappers, ldxx))
1916 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], ar)) 2186 master_ninja.variable('ar', GetEnvironFallback(['AR_target', 'AR'], ar))
1917 if flavor != 'mac': 2187 if flavor != 'mac':
1918 # Mac does not use readelf/nm for .TOC generation, so avoiding polluting 2188 # Mac does not use readelf/nm for .TOC generation, so avoiding polluting
1919 # the master ninja with extra unused variables. 2189 # the master ninja with extra unused variables.
1920 master_ninja.variable( 2190 master_ninja.variable(
1921 'nm', GetEnvironFallback(['NM_target', 'NM'], nm)) 2191 'nm', GetEnvironFallback(['NM_target', 'NM'], nm))
1922 master_ninja.variable( 2192 master_ninja.variable(
1923 'readelf', GetEnvironFallback(['READELF_target', 'READELF'], readelf)) 2193 'readelf', GetEnvironFallback(['READELF_target', 'READELF'], readelf))
1924 2194
2195 if flavor == 'mac' and gyp.xcode_emulation.IsSwiftSupported():
2196 master_ninja.variable(
2197 'swift', subprocess.check_output(['xcrun', '-f', 'swift']))
2198
1925 if generator_supports_multiple_toolsets: 2199 if generator_supports_multiple_toolsets:
1926 if not cc_host: 2200 if not cc_host:
1927 cc_host = cc 2201 cc_host = cc
1928 if not cxx_host: 2202 if not cxx_host:
1929 cxx_host = cxx 2203 cxx_host = cxx
1930 2204
1931 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], ar_host)) 2205 master_ninja.variable('ar_host', GetEnvironFallback(['AR_host'], ar_host))
1932 master_ninja.variable('nm_host', GetEnvironFallback(['NM_host'], nm_host)) 2206 master_ninja.variable('nm_host', GetEnvironFallback(['NM_host'], nm_host))
1933 master_ninja.variable('readelf_host', 2207 master_ninja.variable('readelf_host',
1934 GetEnvironFallback(['READELF_host'], readelf_host)) 2208 GetEnvironFallback(['READELF_host'], readelf_host))
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 depfile='$out.d', 2373 depfile='$out.d',
2100 deps=deps) 2374 deps=deps)
2101 master_ninja.rule( 2375 master_ninja.rule(
2102 'objcxx', 2376 'objcxx',
2103 description='OBJCXX $out', 2377 description='OBJCXX $out',
2104 command=('$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_objcc ' 2378 command=('$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_objcc '
2105 '$cflags_pch_objcc -c $in -o $out'), 2379 '$cflags_pch_objcc -c $in -o $out'),
2106 depfile='$out.d', 2380 depfile='$out.d',
2107 deps=deps) 2381 deps=deps)
2108 master_ninja.rule( 2382 master_ninja.rule(
2383 'swift',
2384 description='SWIFT $out_obj',
2385 command=('$swift -frontend -c -primary-file $in $swift_compile_flags '
2386 '-emit-module-path $out_module '
2387 '-o $out_obj'))
2388 master_ninja.rule(
2389 'swiftmerge',
2390 description='SWIFT MERGE $out_module',
2391 command=('$swift -frontend -emit-module $in $swift_merge_flags '
2392 '-emit-objc-header-path $out_header '
2393 '-o $out_module'))
2394 master_ninja.rule(
2395 'copyswiftlibs',
2396 description='COPY SWIFT LIBS $out',
2397 command=('./gyp-mac-tool copy-swift-libs $swift_libs_path $out $in'))
2398 master_ninja.rule(
2399 'modulemap',
2400 description='MODULE MAP $map_file',
2401 command=('./gyp-mac-tool build-module-map-file '
2402 '$module_name $umbrella_header $map_file $out'))
2403 master_ninja.rule(
2404 'swiftmodulemap',
2405 description='SWIFT MODULE MAP $map_file',
2406 command=('./gyp-mac-tool append-swift-to-module-map-file '
2407 '$module_name $swift_header $map_file $out'))
2408 master_ninja.rule(
2109 'alink', 2409 'alink',
2110 description='LIBTOOL-STATIC $out, POSTBUILDS', 2410 description='LIBTOOL-STATIC $out, POSTBUILDS',
2111 command='rm -f $out && ' 2411 command='rm -f $out && '
2112 './gyp-mac-tool filter-libtool libtool $libtool_flags ' 2412 './gyp-mac-tool filter-libtool libtool $libtool_flags '
2113 '-static -o $out $in' 2413 '-static -o $out $in'
2114 '$postbuilds') 2414 '$postbuilds')
2115 master_ninja.rule( 2415 master_ninja.rule(
2116 'lipo', 2416 'lipo',
2117 description='LIPO $out, POSTBUILDS', 2417 description='LIPO $out, POSTBUILDS',
2118 command='rm -f $out && lipo -create $in -output $out$postbuilds') 2418 command='rm -f $out && lipo -create $in -output $out$postbuilds')
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2382 arglists.append( 2682 arglists.append(
2383 (target_list, target_dicts, data, params, config_name)) 2683 (target_list, target_dicts, data, params, config_name))
2384 pool.map(CallGenerateOutputForConfig, arglists) 2684 pool.map(CallGenerateOutputForConfig, arglists)
2385 except KeyboardInterrupt, e: 2685 except KeyboardInterrupt, e:
2386 pool.terminate() 2686 pool.terminate()
2387 raise e 2687 raise e
2388 else: 2688 else:
2389 for config_name in config_names: 2689 for config_name in config_names:
2390 GenerateOutputForConfig(target_list, target_dicts, data, params, 2690 GenerateOutputForConfig(target_list, target_dicts, data, params,
2391 config_name) 2691 config_name)
OLDNEW
« no previous file with comments | « no previous file | pylib/gyp/mac_tool.py » ('j') | pylib/gyp/xcode_emulation.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698