Skip to content

Commit

Permalink
Fix msvc.makedep.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseefeld committed Jul 29, 2020
1 parent a524fb5 commit 8ef1164
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/faber/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from . import output
import re
import logging
import sys

action_logger = logging.getLogger('actions')
command_logger = logging.getLogger('commands')
Expand Down Expand Up @@ -161,7 +162,7 @@ def __call__(self, targets, sources=[], **kwds):
if stdout:
print(stdout)
if stderr:
print(stderr)
print(stderr, file=sys.stderr)
if not status:
raise CallError(cmd)
return status
Expand Down
32 changes: 20 additions & 12 deletions src/faber/tools/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
# Boost Software License, Version 1.0.
# (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt)

from ..action import action
from ..action import action, CallError
from ..feature import set as fset, map, translate, select_if
from ..artefact import artefact
from .. import types
from ..assembly import implicit_rule as irule
from ..utils import capture_output
from . import compiler
from .cc import cc
from .cxx import cxx, cxxstd
Expand All @@ -23,17 +24,15 @@
from collections import OrderedDict
from subprocess import *
import logging
import sys

logger = logging.getLogger('tools')


class makedep(action):

# TODO: It seems hard to capture include dependencies *only*.
# We either have to also collect the full preprocessor output,
# or we need to redirect stderr, which is dangerous as it may
# hide valuable error messages...
command = 'cl /nologo $(cppflags) /showIncludes /EP $(>) 2>$(<)'
# /showIncludes emits to stderr !
command = 'cl /nologo $(cppflags) /showIncludes /EP $(>)'
cppflags = map(compiler.cppflags)
cppflags += map(compiler.define, translate, prefix='/D')
cppflags += map(compiler.include, translate, prefix='/I"', suffix='"')
Expand All @@ -51,19 +50,28 @@ def map(self, fs):
return self.cmd.map(fs) # just forward variables from makedep

def makedep(self, targets, sources):
dfile = targets[0]._filename
self.cmd(targets, sources)
with open(dfile) as f:
# skip 'Note: including file: ', and remove dupliates
headers = set([l[22:].lstrip() for l in f.readlines()
if l.startswith('Note: including file: ')])
with capture_output() as (out, err):
try:
status = self.cmd(targets, sources)
except CallError as e:
status = False
stderr = err.getvalue()
if status is False:
# on error make sure to report stderr
print(stderr, file=sys.stderr)
return status
# skip 'Note: including file: ', and remove dupliates
headers = set([l[22:].lstrip() for l in stderr
if l.startswith('Note: including file: ')])
# header paths are relative to the toplevel srcdir,
# while we need them to be relative to the current module
base = targets[0].module.srcdir
rp = lambda f, base: f if isabs(f) else relpath(f, base)
headers = [rp(h, base) for h in headers]
dfile = targets[0]._filename
with open(dfile, 'w') as f:
f.writelines(headers)
print(f'wrote {dfile}')


class compile(action):
Expand Down

0 comments on commit 8ef1164

Please sign in to comment.