From 9389f5d5ccd0a45b45e0b73fb5d1f86a7ac67d16 Mon Sep 17 00:00:00 2001 From: swaldhoer <34184299+swaldhoer@users.noreply.github.com> Date: Sun, 26 Apr 2020 19:47:03 +0200 Subject: [PATCH] add the idea as documentation --- demos/c++/wscript | 2 +- demos/c/file-include/wscript_build | 2 +- waflib/Node.py | 4 ++-- waflib/Tools/c.py | 2 +- waflib/Tools/ccroot.py | 27 +++++---------------------- waflib/Tools/cxx.py | 2 +- waflib/Tools/msvc.py | 4 ++-- 7 files changed, 13 insertions(+), 30 deletions(-) diff --git a/demos/c++/wscript b/demos/c++/wscript index 3303a447..ac97a6c6 100644 --- a/demos/c++/wscript +++ b/demos/c++/wscript @@ -23,7 +23,7 @@ def build(bld): bld.shlib(source='a.cpp', target='mylib3') bld.program(source='main.cpp', target='app', use='mylib') bld.stlib(target='foo', source='b.cpp') - bld.program(source='c.cpp', target='file-include', include_files='file-include/inc-file/header.h') + bld.program(source='c.cpp', target='file-include', includes='file-include/inc-file/header.h') # just a test to check if the .c is compiled as c++ when no c compiler is found bld.program(features='cxx cxxprogram', source='main.c', target='app2') diff --git a/demos/c/file-include/wscript_build b/demos/c/file-include/wscript_build index c45bc6aa..371e9e8f 100644 --- a/demos/c/file-include/wscript_build +++ b/demos/c/file-include/wscript_build @@ -1 +1 @@ -bld(features='c cprogram', source='main.c', include_files='inc-file/header.h', target='app') +bld(features='c cprogram', source='main.c', includes='inc-file/header.h', target='app') diff --git a/waflib/Node.py b/waflib/Node.py index 6b8cb0d8..f5052527 100644 --- a/waflib/Node.py +++ b/waflib/Node.py @@ -518,7 +518,7 @@ class Node(object): else: return self.abspath() - def is_file(self): + def isfile(self): """ Returns True if the Node object is a file. @@ -526,7 +526,7 @@ class Node(object): """ return os.path.isfile(self.abspath()) - def is_directory(self): + def isdir(self): """ Returns True if the Node object is a directory. diff --git a/waflib/Tools/c.py b/waflib/Tools/c.py index 3ffb801e..effd6b6e 100644 --- a/waflib/Tools/c.py +++ b/waflib/Tools/c.py @@ -17,7 +17,7 @@ def c_hook(self, node): class c(Task.Task): "Compiles C files into object files" - run_str = '${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPFILES_ST:INCFILES} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}' + run_str = '${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}' vars = ['CCDEPS'] # unused variable to depend on, just in case ext_in = ['.h'] # set the build order easily by using ext_out=['.h'] scan = c_preproc.scan diff --git a/waflib/Tools/ccroot.py b/waflib/Tools/ccroot.py index 9c21ab71..5a898aef 100644 --- a/waflib/Tools/ccroot.py +++ b/waflib/Tools/ccroot.py @@ -119,29 +119,12 @@ def apply_incpaths(self): """ lst = self.to_incnodes(self.to_list(getattr(self, 'includes', [])) + self.env.INCLUDES) - self.includes_nodes = lst + inc_files = [x for x in lst if x.isfile()] + self.includes_nodes = list(set(lst) - set(inc_files)) # diff only holds directory cwd = self.get_cwd() - self.env.INCPATHS = [x.path_from(cwd) for x in lst] - -@feature('c', 'cxx', 'include_files') -@after_method('propagate_uselib_vars', 'process_source') -def apply_incfiles(self): - """ - Task generator method that processes the attribute *include_files*:: - - tg = bld(features='include_files', include_files='my-header.h') - - The files need to be given relative to the current directory. - - This method will add a list of header file nodes to ``tg.env.INCFILES``. - """ - node_lst = [] - for x in self.to_list(getattr(self, 'include_files', [])) + self.env.INCLUDE_FILES: - if isinstance(x, Node.Node): - node_lst.append(x) - else: - node_lst.append(self.path.find_node(x)) - self.env.INCFILES = [x.abspath() for x in node_lst if x.is_file()] + self.env.INCPATHS = [x.path_from(cwd) for x in self.includes_nodes] + self.env.prepend_value('CFLAGS', [self.env.CPPFILES_ST % x for x in inc_files]) + self.env.prepend_value('CXXFLAGS', [self.env.CPPFILES_ST % x for x in inc_files]) class link_task(Task.Task): """ diff --git a/waflib/Tools/cxx.py b/waflib/Tools/cxx.py index 6adbee0b..194fad74 100644 --- a/waflib/Tools/cxx.py +++ b/waflib/Tools/cxx.py @@ -18,7 +18,7 @@ if not '.c' in TaskGen.task_gen.mappings: class cxx(Task.Task): "Compiles C++ files into object files" - run_str = '${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPFILES_ST:INCFILES} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}' + run_str = '${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT[0].abspath()} ${CPPFLAGS}' vars = ['CXXDEPS'] # unused variable to depend on, just in case ext_in = ['.h'] # set the build order easily by using ext_out=['.h'] scan = c_preproc.scan diff --git a/waflib/Tools/msvc.py b/waflib/Tools/msvc.py index b3778bd4..dda0ac97 100644 --- a/waflib/Tools/msvc.py +++ b/waflib/Tools/msvc.py @@ -909,8 +909,8 @@ def msvc_common_flags(conf): v.CC_TGT_F = ['/FC'] + v.CC_TGT_F v.CXX_TGT_F = ['/FC'] + v.CXX_TGT_F - v.CPPPATH_ST = '/I%s' # template for adding include paths - v.CPPFILES_ST = '/FI%s' + v.CPPPATH_ST = '/I%s' # template for adding include paths + v.CPPFILES_ST = '/FI%s' v.AR_TGT_F = v.CCLNK_TGT_F = v.CXXLNK_TGT_F = '/OUT:'