From c97d7505a7cc370b0cc5140206aec5d9e4414ea6 Mon Sep 17 00:00:00 2001 From: Nikita Kniazev Date: Sat, 11 Mar 2023 16:25:16 +0300 Subject: [PATCH] A few fixes to PCH (#213) * Test: Invoke b2 with .exe suffix on Windows * GCC: Pass -ftemplate-depth-xxx when building PCH * MSVC: Fix PCH include directory and pass only PCH-header name to -Yu Apparently `[ $(pch-header).path ]` gives the wrong path to the header. --- src/tools/gcc.jam | 2 +- src/tools/msvc.jam | 11 +++++------ test/BoostBuild.py | 2 +- test/pch.py | 16 ++++++++-------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/tools/gcc.jam b/src/tools/gcc.jam index 8a49068570..bbbb3e6a35 100644 --- a/src/tools/gcc.jam +++ b/src/tools/gcc.jam @@ -611,7 +611,7 @@ toolset.flags gcc.compile PCH_FILE on : ; actions compile.c++.pch { - "$(CONFIG_COMMAND)" -x c++-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -c -o "$(<)" "$(>:T)" + "$(CONFIG_COMMAND)" -x c++-header -ftemplate-depth-$(TEMPLATE_DEPTH) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -c -o "$(<)" "$(>:T)" } actions compile.c.pch diff --git a/src/tools/msvc.jam b/src/tools/msvc.jam index adfcfeb81f..447187249a 100644 --- a/src/tools/msvc.jam +++ b/src/tools/msvc.jam @@ -740,12 +740,12 @@ toolset.flags msvc YLOPTION : "-Yl" ; # actions compile-c-c++ bind PDB_NAME PCH_HEADER { - $(.SETUP) $(.CC) @($(<[1]:W).rsp:O=FC:<=@":>=":E="$(>[1]:W)" -c -Fo"$(<[1]:W)" $(PDB_CFLAG)"$(PDB_NAME)" -FI"$(PCH_HEADER)" -Yu"$(>[3]:D=)" -Fp"$(>[2]:W)" $(CC_RSPLINE)) $(.CC.FILTER) + $(.SETUP) $(.CC) @($(<[1]:W).rsp:O=FC:<=@":>=":E="$(>[1]:W)" -c -Fo"$(<[1]:W)" $(PDB_CFLAG)"$(PDB_NAME)" -I"$(PCH_HEADER:D)" -FI"$(PCH_HEADER:D=)" -Yu"$(>[3]:D=)" -Fp"$(>[2]:W)" $(CC_RSPLINE)) $(.CC.FILTER) } actions preprocess-c-c++ bind PDB_NAME PCH_HEADER { - $(.SETUP) $(.CC) @($(<[1]:W).rsp:O=FC:<=@":>=":E="$(>[1]:W)" -P -Fi"$(<[1]:W)" $(PDB_CFLAG)"$(PDB_NAME)" -FI"$(PCH_HEADER)" -Yu"$(>[3]:D=)" -Fp"$(>[2]:W)" $(CC_RSPLINE)) + $(.SETUP) $(.CC) @($(<[1]:W).rsp:O=FC:<=@":>=":E="$(>[1]:W)" -P -Fi"$(<[1]:W)" $(PDB_CFLAG)"$(PDB_NAME)" -I"$(PCH_HEADER:D)" -FI"$(PCH_HEADER:D=)" -Yu"$(>[3]:D=)" -Fp"$(>[2]:W)" $(CC_RSPLINE)) } rule compile-c-c++ ( targets + : sources * ) @@ -772,7 +772,7 @@ rule preprocess-c-c++ ( targets + : sources * ) # syntax highlighting in the messy N-quoted code below. actions compile-c-c++-pch { - $(.SETUP) $(.CC) @($(<[1]:W).rsp:O=FC:<=@":>=":E="$(>[2]:W)" -c -Fo"$(<[2]:W)" -Yc"$(>[1]:D=)" $(YLOPTION)"__bjam_pch_symbol_$(>[1]:D=)" -Fp"$(<[1]:W)" $(CC_RSPLINE)) @($(<[1]:W).cpp:<=":>=":E=$(.hash)include $(.escaped-double-quote)$(>[1]:D=)$(.escaped-double-quote)$(.nl)) $(.CC.FILTER) + $(.SETUP) $(.CC) @($(<[1]:W).rsp:O=FC:<=@":>=":E="$(>[2]:W)" -c -Fo"$(<[2]:W)" -I"$(>[1]:D)" -Yc"$(>[1]:D=)" $(YLOPTION)"__bjam_pch_symbol_$(>[1]:D=)" -Fp"$(<[1]:W)" $(CC_RSPLINE)) @($(<[1]:W).cpp:<=":>=":E=$(.hash)include $(.escaped-double-quote)$(>[1]:D=)$(.escaped-double-quote)$(.nl)) $(.CC.FILTER) } @@ -781,7 +781,7 @@ actions compile-c-c++-pch # given as one of the source parameters. actions compile-c-c++-pch-s { - $(.SETUP) $(.CC) @($(<[1]:W).rsp:O=FC:<=@":>=":E="$(>[2]:W)" -c -Fo"$(<[2]:W)" -Yc"$(>[1]:D=)" $(YLOPTION)"__bjam_pch_symbol_$(>[1]:D=)" -Fp"$(<[1]:W)" $(CC_RSPLINE)) $(.CC.FILTER) + $(.SETUP) $(.CC) @($(<[1]:W).rsp:O=FC:<=@":>=":E="$(>[2]:W)" -c -Fo"$(<[2]:W)" -I"$(>[1]:D)" -Yc"$(>[1]:D=)" $(YLOPTION)"__bjam_pch_symbol_$(>[1]:D=)" -Fp"$(<[1]:W)" $(CC_RSPLINE)) $(.CC.FILTER) } @@ -1005,14 +1005,13 @@ class msvc-pch-generator : pch-generator # If we do not have the PCH source - that is fine. We will just create a # temporary .cpp file in the action. - local pch-header-dir = [ $(pch-header).path ] ; local generated = [ generator.run $(project) $(name) : [ property-set.create # Passing of is a dirty trick, needed because # non-composing generators with multiple inputs are subtly # broken. For more detailed information see: # https://zigzag.cs.msu.su:7813/boost.build/ticket/111 - $(pch-source) "$(pch-header-dir)" + $(pch-source) [ $(property-set).raw ] ] : $(pch-header) ] ; diff --git a/test/BoostBuild.py b/test/BoostBuild.py index e7dee30631..c3e6ac2c13 100644 --- a/test/BoostBuild.py +++ b/test/BoostBuild.py @@ -259,7 +259,7 @@ def __init__(self, arguments=None, executable=None, if not executable: executable = os.getenv('B2') if not executable: - executable = 'b2' + executable = 'b2' if os.name != 'nt' else 'b2.exe' assert arguments.__class__ is not str self.original_workdir = os.path.dirname(__file__) diff --git a/test/pch.py b/test/pch.py index fe6c792f33..bcb9bd57af 100644 --- a/test/pch.py +++ b/test/pch.py @@ -15,9 +15,9 @@ t.write("jamroot.jam", """ import pch ; project : requirements on ; -cpp-pch pch : pch.hpp ; -cpp-pch pch-afx : pch.hpp : HELLO ; -cpp-pch pch-msvc-source : pch.hpp : msvc:pch.cpp ; +cpp-pch pch : a/pch.hpp ; +cpp-pch pch-afx : a/pch.hpp : HELLO ; +cpp-pch pch-msvc-source : a/pch.hpp : msvc:a/pch.cpp ; exe hello : hello.cpp pch ; exe hello-afx : hello-afx.cpp pch-afx : HELLO ; exe hello-msvc-source : hello-msvc-source.cpp pch-msvc-source ; @@ -31,9 +31,9 @@ class TestClass TestClass( int, int ) {} }; """ -t.write("pch.hpp", pch_content) +t.write("a/pch.hpp", pch_content) -t.write("pch.cpp", """#include +t.write("a/pch.cpp", """#include """) toolset = BoostBuild.get_toolset() @@ -52,10 +52,10 @@ class TestClass # B2 will not recreate PCH, and compiler will happily use pre-compiled # header, not noticing that the real header is bad. -t.rename("pch.hpp", "pch.hpp.orig") +t.rename("a/pch.hpp", "a/pch.hpp.orig") s = "THIS WILL NOT COMPILE. " -t.write("pch.hpp", s + (len(pch_content) - len(s)) * 'x') -t.copy_timestamp("pch.hpp.orig", "pch.hpp") +t.write("a/pch.hpp", s + (len(pch_content) - len(s)) * 'x') +t.copy_timestamp("a/pch.hpp.orig", "a/pch.hpp") t.rm("bin/$toolset/debug*/hello.obj") t.rm("bin/$toolset/debug*/hello-afx.obj")