Skip to content

Commit 4392380

Browse files
jturcottebbandix
authored andcommitted
<tools/gyp> Allow letting qmake do the link step
This adds a let_qmake_do_the_linking target variable to tell ninja not to link but rather dump the linking information from gyp in a file that we'll parse with qmake. Reviewed-by: Zoltan Arvai <[email protected]> Reviewed-by: Andras Becsi <[email protected]> Change-Id: I753888776679e449d7a64b6bf5b47e7a60dfa827 Reviewed-by: Zeno Albisser <[email protected]>
1 parent 6ebae8b commit 4392380

File tree

1 file changed

+43
-0
lines changed
  • chromium/tools/gyp/pylib/gyp/generator

1 file changed

+43
-0
lines changed

chromium/tools/gyp/pylib/gyp/generator/ninja.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,49 @@ def WriteLinkForArch(self, ninja_file, spec, config_name, config,
11011101
else:
11021102
command = command + '_notoc'
11031103

1104+
if config.get('let_qmake_do_the_linking', 0):
1105+
def toAbsPaths(paths):
1106+
return [os.path.relpath(path, self.toplevel_build) if os.path.isabs(path) else path
1107+
for path in paths]
1108+
def qmakeLiteral(s):
1109+
return s.replace('"', '\\"')
1110+
1111+
# Generate this file for all solink targets, this assumes that
1112+
# a .pro file will pick up this pri file and do the rest of the work.
1113+
pri_file = open(os.path.join(self.toplevel_build, self.name + "_linking.pri"), 'w')
1114+
1115+
if self.flavor == 'win':
1116+
# qmake will take care of the manifest
1117+
ldflags = filter(lambda x: not x.lower().startswith('/manifest'), ldflags)
1118+
1119+
# Replace "$!PRODUCT_DIR" with "$$PWD" in link flags (which might contain some -L directives).
1120+
prefixed_lflags = [self.ExpandSpecial(f, '$$PWD') for f in ldflags]
1121+
prefixed_library_dirs = ['-L' + self.ExpandSpecial(f, '$$PWD') for f in config.get('library_dirs', [])]
1122+
prefixed_libraries = gyp.common.uniquer([self.ExpandSpecial(f, '$$PWD') for f in spec.get('libraries', [])])
1123+
if self.flavor == 'mac':
1124+
prefixed_libraries = self.xcode_settings.AdjustLibraries(prefixed_libraries)
1125+
elif self.flavor == 'win':
1126+
prefixed_libraries = self.msvs_settings.AdjustLibraries(prefixed_libraries)
1127+
1128+
# Make sure that we have relative paths to our out/(Release|Debug), where we generate our .pri file, and then prepend $$PWD to them.
1129+
prefixed_object_and_archives = ['$$PWD/' + o for o in toAbsPaths(link_deps)]
1130+
1131+
pri_file.write("QMAKE_LFLAGS += %s\n" % qmakeLiteral(' '.join(prefixed_lflags)))
1132+
# Follow the logic of the solink rule.
1133+
if self.flavor != 'mac' and self.flavor != 'win':
1134+
pri_file.write("LIBS_PRIVATE += -Wl,--whole-archive %s -Wl,--no-whole-archive\n" % qmakeLiteral(' '.join(prefixed_object_and_archives)))
1135+
else:
1136+
pri_file.write("LIBS_PRIVATE += %s\n" % qmakeLiteral(' '.join(prefixed_object_and_archives)))
1137+
# External libs have to come after objects/archives, the linker resolve them in order.
1138+
pri_file.write("LIBS_PRIVATE += %s\n" % qmakeLiteral(' '.join(prefixed_library_dirs + prefixed_libraries)))
1139+
# Make sure that if ninja modifies one of the inputs, qmake/make will link again.
1140+
pri_file.write("POST_TARGETDEPS += %s\n" % qmakeLiteral(' '.join(prefixed_object_and_archives)))
1141+
pri_file.close()
1142+
1143+
# In this mode we prevent letting ninja link at all.
1144+
command = 'phony'
1145+
command_suffix = ''
1146+
11041147
if len(solibs):
11051148
extra_bindings.append(('solibs', gyp.common.EncodePOSIXShellList(solibs)))
11061149

0 commit comments

Comments
 (0)