Index: pylib/gyp/generator/ninja.py |
=================================================================== |
--- pylib/gyp/generator/ninja.py (revision 1197) |
+++ pylib/gyp/generator/ninja.py (working copy) |
@@ -76,7 +76,7 @@ |
return path |
# Only need to handle relative paths into subdirectories for now. |
assert '..' not in path, path |
- depth = len(path.split('/')) |
+ depth = len(path.split(os.path.sep)) |
return '/'.join(['..'] * depth) |
@@ -180,6 +180,7 @@ |
self.ninja = ninja_syntax.Writer(output_file) |
self.flavor = flavor |
self.abs_build_dir = abs_build_dir |
+ self.obj_ext = '.obj' if flavor == 'win' else '.o' |
# Relative path from build output dir to base dir. |
self.build_to_base = os.path.join(InvertRelativePath(build_dir), base_dir) |
@@ -348,7 +349,8 @@ |
self.xcode_settings, self.GypPathToNinja, |
lambda path, lang: self.GypPathToUniqueOutput(path + '-' + lang))) |
# Some actions/rules output 'sources' that are already object files. |
- link_deps += [self.GypPathToNinja(f) for f in sources if f.endswith('.o')] |
+ link_deps += [self.GypPathToNinja(f) |
+ for f in sources if f.endswith(self.obj_ext)] |
# Write out a link step, if needed. |
output = None |
@@ -627,7 +629,7 @@ |
# TODO: should we assert here on unexpected extensions? |
continue |
input = self.GypPathToNinja(source) |
- output = self.GypPathToUniqueOutput(filename + '.o') |
+ output = self.GypPathToUniqueOutput(filename + self.obj_ext) |
implicit = precompiled_header.GetObjDependencies([input], [output]) |
self.ninja.build(output, command, input, |
implicit=[gch for _, _, gch in implicit], |
@@ -966,6 +968,12 @@ |
global generator_extra_sources_for_rules |
generator_extra_sources_for_rules = getattr(xcode_generator, |
'generator_extra_sources_for_rules', []) |
+ elif flavor == 'win': |
+ default_variables.setdefault('EXECUTABLE_SUFFIX', '.exe') |
+ default_variables.setdefault('STATIC_LIB_PREFIX', '') |
+ default_variables.setdefault('STATIC_LIB_SUFFIX', '.lib') |
+ default_variables.setdefault('SHARED_LIB_PREFIX', '') |
+ default_variables.setdefault('SHARED_LIB_SUFFIX', '.dll') |
else: |
operating_system = flavor |
if flavor == 'android': |
@@ -1004,7 +1012,10 @@ |
gyp.common.CopyTool(flavor, os.path.join(options.toplevel_dir, build_dir)) |
# Grab make settings for CC/CXX. |
- cc, cxx = 'gcc', 'g++' |
+ if flavor == 'win': |
+ cc = cxx = 'cl' |
+ else: |
+ cc, cxx = 'gcc', 'g++' |
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) |
make_global_settings = data[build_file].get('make_global_settings', []) |
build_to_root = InvertRelativePath(build_dir) |
@@ -1017,27 +1028,46 @@ |
flock = './gyp-mac-tool flock' |
master_ninja.variable('cc', os.environ.get('CC', cc)) |
master_ninja.variable('cxx', os.environ.get('CXX', cxx)) |
- master_ninja.variable('ld', flock + ' linker.lock $cxx') |
+ if flavor == 'win': |
+ master_ninja.variable('ld', 'link') |
+ else: |
+ master_ninja.variable('ld', flock + ' linker.lock $cxx') |
master_ninja.variable('cc_host', '$cc') |
master_ninja.variable('cxx_host', '$cxx') |
if flavor == 'mac': |
master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) |
master_ninja.newline() |
- master_ninja.rule( |
- 'cc', |
- description='CC $out', |
- command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' |
- '$cflags_pch_c -c $in -o $out'), |
- depfile='$out.d') |
- master_ninja.rule( |
- 'cxx', |
- description='CXX $out', |
- command=('$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_cc ' |
- '$cflags_pch_cc -c $in -o $out'), |
- depfile='$out.d') |
- if flavor != 'mac': |
+ if flavor != 'win': |
master_ninja.rule( |
+ 'cc', |
+ description='CC $out', |
+ command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' |
+ '$cflags_pch_c -c $in -o $out'), |
+ depfile='$out.d') |
+ master_ninja.rule( |
+ 'cxx', |
+ description='CXX $out', |
+ command=('$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_cc ' |
+ '$cflags_pch_cc -c $in -o $out'), |
+ depfile='$out.d') |
+ else: |
+ # TODO(scottmg): Decide how /showIncludes handling should work in ninja. |
+ master_ninja.rule( |
+ 'cc', |
+ description='CC $out', |
+ command=('$cc /nologo $defines $includes $cflags $cflags_c ' |
+ '$cflags_pch_c /c $in /Fo$out'), |
+ depfile='$out.d') |
+ master_ninja.rule( |
+ 'cxx', |
+ description='CXX $out', |
+ command=('$cxx /nologo $defines $includes $cflags $cflags_cc ' |
+ '$cflags_pch_cc /c $in /Fo$out'), |
+ depfile='$out.d') |
+ |
+ if flavor != 'mac' and flavor != 'win': |
+ master_ninja.rule( |
'alink', |
description='AR $out', |
command='rm -f $out && ar rcsT $out $in') |
@@ -1056,6 +1086,23 @@ |
description='LINK $out', |
command=('$ld $ldflags -o $out -Wl,-rpath=\$$ORIGIN/lib ' |
'-Wl,--start-group $in -Wl,--end-group $libs')) |
+ elif flavor == 'win': |
+ master_ninja.rule( |
+ 'alink', |
+ description='AR $out', |
+ command='lib /nologo /OUT:$out.lib $in') |
+ master_ninja.rule( |
+ 'solink', |
+ description='SOLINK $out', |
+ command=('$ld /nologo /DLL $ldflags /OUT:$out.dll $in $libs')) |
+ master_ninja.rule( |
+ 'solink_module', |
+ description='SOLINK(module) $out', |
+ command=('$ld /nologo /DLL $ldflags /OUT:$out.dll $in $libs')) |
+ master_ninja.rule( |
+ 'link', |
+ description='LINK $out', |
+ command=('$ld /nologo $ldflags /OUT:$out.exe $in $libs')) |
else: |
master_ninja.rule( |
'objc', |
@@ -1110,10 +1157,17 @@ |
'stamp', |
description='STAMP $out', |
command='${postbuilds}touch $out') |
- master_ninja.rule( |
- 'copy', |
- description='COPY $in $out', |
- command='ln -f $in $out 2>/dev/null || (rm -rf $out && cp -af $in $out)') |
+ if flavor == 'win': |
+ # TODO(scottmg): Copy fallback? |
+ master_ninja.rule( |
+ 'copy', |
+ description='COPY $in $out', |
+ command='mklink /h $out $in >nul') |
+ else: |
+ master_ninja.rule( |
+ 'copy', |
+ description='COPY $in $out', |
+ command='ln -f $in $out 2>/dev/null || (rm -rf $out && cp -af $in $out)') |
master_ninja.newline() |
all_targets = set() |