[PATCH 1/3] waf_generator: Copy headers if necessary.

Chris Johns chrisj at rtems.org
Thu Aug 10 23:30:00 UTC 2017


OK with the minor change.

On 11/08/2017 04:14, Christian Mauderer wrote:
> From: Christian Mauderer <christian.mauderer at embedded-brains.de>
> 
> There are some cases, where a header is installed into a directory with
> a different name then it's source directory. In that case, the build
> might fail because the header is not found. One example would be the
> <openssl/opensslv.h>. The source for this file is in
> freebsd/crypto/openssl/crypto/opensslv.h.
> 
> To allow the build to work in such cases too, copy such files into a
> temporary location in the build tree.
> ---
>  builder.py       | 14 ++++++++++++++
>  libbsd_waf.py    | 15 +++++++++++++++
>  waf_generator.py | 24 +++++++++++++++++++++++-
>  3 files changed, 52 insertions(+), 1 deletion(-)
> 
> diff --git a/builder.py b/builder.py
> index bb633cb2..1be1ced1 100755
> --- a/builder.py
> +++ b/builder.py
> @@ -194,6 +194,10 @@ def includes():
>              '-ImDNSResponder/mDNSPosix',
>              '-Itestsuite/include']
>  
> +def buildInclude():
> +    """ Returns the path where headers will be copied during build. """
> +    return 'build-include'
> +
>  def cpuIncludes():
>      return ['-Irtemsbsd/@CPU@/include',
>              '-Ifreebsd/sys/@CPU@/include']
> @@ -205,6 +209,16 @@ def cxxflags():
>      return []
>  
>  def headerPaths():
> +    """ Returns a list of information about what header files should be
> +    installed.
> +
> +    The list is also used to find headers with a local path that doesn't match
> +    it's dest path. Due to the difference in the path name such files are
> +    problematic during the build if they are included using their later
> +    installation path (dest path) name. Therefore they are copied into a
> +    sub-directory of the build path so that they can be included with their
> +    normal installation path. """
> +
>      #         local path                      wildcard             dest path
>      return [('rtemsbsd/include',              '*.h',               ''),
>              ('rtemsbsd/mghttpd',              'mongoose.h',        'mghttpd'),
> diff --git a/libbsd_waf.py b/libbsd_waf.py
> index aee2e7ad..cbb0ae23 100644
> --- a/libbsd_waf.py
> +++ b/libbsd_waf.py
> @@ -83,6 +83,7 @@ def build(bld):
>      includes += ["mDNSResponder/mDNSShared"]
>      includes += ["mDNSResponder/mDNSPosix"]
>      includes += ["testsuite/include"]
> +    includes += ["build-include"]
>  
>      # Collect the libbsd uses
>      libbsd_use = []
> @@ -123,6 +124,20 @@ def build(bld):
>          rule = "sed -e 's/@NET_CFG_SELF_IP@/%s/' -e 's/@NET_CFG_NETMASK@/%s/' -e 's/@NET_CFG_PEER_IP@/%s/' -e 's/@NET_CFG_GATEWAY_IP@/%s/' < ${SRC} > ${TGT}" % (net_cfg_self_ip, net_cfg_netmask, net_cfg_peer_ip, net_cfg_gateway_ip),
>          update_outputs = True)
>  
> +    # copy headers if necessary
> +    header_build_copy_paths = [
> +                              ]
> +    for headers in header_build_copy_paths:
> +        target = os.path.join("build-include", headers[2])
> +        start_dir = bld.path.find_dir(headers[0])
> +        for header in start_dir.ant_glob("**/" + headers[1]):

Minor nit .. 'start_dir.ant_glob(os.path.join("**", headers[1]))' ?

> +            relsourcepath = header.path_from(start_dir)
> +            targetheader = os.path.join(target, relsourcepath)
> +            bld(features = 'subst',
> +                target = targetheader,
> +                source = header,
> +                is_copy = True)
> +
>      # KVM Symbols
>      bld(target = "rtemsbsd/rtems/rtems-kernel-kvm-symbols.c",
>          source = "rtemsbsd/rtems/generate_kvm_symbols",
> diff --git a/waf_generator.py b/waf_generator.py
> index 35fe35f4..271aed96 100755
> --- a/waf_generator.py
> +++ b/waf_generator.py
> @@ -392,7 +392,7 @@ class ModuleManager(builder.ModuleManager):
>          self.add('    if bld.get_env()["RTEMS_ARCH"] == "i386":')
>          self.add('        for i in %r:' % (builder.cpuIncludes()))
>          self.add('            includes += ["%s" % (i[2:].replace("@CPU@", "x86"))]')
> -        for i in builder.includes():
> +        for i in builder.includes() + ['-I' + builder.buildInclude()]:
>              self.add('    includes += ["%s"]' % (i[2:]))
>          self.add('')
>          self.add('    # Collect the libbsd uses')
> @@ -445,6 +445,28 @@ class ModuleManager(builder.ModuleManager):
>          self.add('')
>  
>          #
> +        # Add a copy rule for all headers where the install path and the source
> +        # path are not the same.
> +        #
> +        self.add('    # copy headers if necessary')
> +        self.add('    header_build_copy_paths = [')
> +        for hp in builder.headerPaths():
> +            if hp[2] != '' and not hp[0].endswith(hp[2]):
> +                self.add('                               %s,' % (str(hp)))
> +        self.add('                              ]')
> +        self.add('    for headers in header_build_copy_paths:')
> +        self.add('        target = os.path.join("%s", headers[2])' % (builder.buildInclude()))
> +        self.add('        start_dir = bld.path.find_dir(headers[0])')
> +        self.add('        for header in start_dir.ant_glob("**/" + headers[1]):')

>From above.

> +        self.add('            relsourcepath = header.path_from(start_dir)')
> +        self.add('            targetheader = os.path.join(target, relsourcepath)')
> +        self.add('            bld(features = \'subst\',')
> +        self.add('                target = targetheader,')
> +        self.add('                source = header,')
> +        self.add('                is_copy = True)')
> +        self.add('')
> +
> +        #
>          # Add the specific rule based builders for generating files.
>          #
>          if 'KVMSymbols' in data:
> 



More information about the devel mailing list