@@ -154,76 +154,109 @@ static Result<Profile>
154154parseDevProfile (
155155 const toml::value& val, const BaseProfile& baseProfile
156156) noexcept {
157- auto devCxxflags = Try (validateFlags (
157+ static constexpr const char * key = " dev" ;
158+
159+ auto cxxflags = Try (validateFlags (
158160 " cxxflags" , toml::find_or<std::vector<std::string>>(
159- val, " profile" , " dev " , " cxxflags" , baseProfile.cxxflags
161+ val, " profile" , key , " cxxflags" , baseProfile.cxxflags
160162 )
161163 ));
162- auto devLdflags = Try (validateFlags (
164+ auto ldflags = Try (validateFlags (
163165 " ldflags" , toml::find_or<std::vector<std::string>>(
164- val, " profile" , " dev " , " ldflags" , baseProfile.ldflags
166+ val, " profile" , key , " ldflags" , baseProfile.ldflags
165167 )
166168 ));
167- const auto devLto =
168- toml::find_or<bool >(val, " profile" , " dev " , " lto" , baseProfile.lto );
169- const auto devDebug = toml::find_or<bool >(
170- val, " profile" , " dev " , " debug" , baseProfile.debug .unwrap_or (true )
171- );
172- const auto devCompDb =
173- toml::find_or<bool >(val, " profile" , " dev " , " compdb" , baseProfile.compDb );
174- const auto devOptLevel = Try (validateOptLevel (
169+ const auto lto =
170+ toml::find_or<bool >(val, " profile" , key , " lto" , baseProfile.lto );
171+ const auto debug = toml::find_or<bool >(
172+ val, " profile" , key , " debug" , baseProfile.debug .unwrap_or (true )
173+ );
174+ const auto compDb =
175+ toml::find_or<bool >(val, " profile" , key , " compdb" , baseProfile.compDb );
176+ const auto optLevel = Try (validateOptLevel (
175177 toml::find_or<std::uint8_t >(
176- val, " profile" , " dev " , " opt-level" , baseProfile.optLevel .unwrap_or (0 )
178+ val, " profile" , key , " opt-level" , baseProfile.optLevel .unwrap_or (0 )
177179 )
178180 ));
179181
180182 return Ok (Profile (
181- std::move (devCxxflags), std::move (devLdflags), devLto, devDebug,
182- devCompDb, devOptLevel
183+ std::move (cxxflags), std::move (ldflags), lto, debug, compDb, optLevel
183184 ));
184185}
185186
186187static Result<Profile>
187188parseReleaseProfile (
188189 const toml::value& val, const BaseProfile& baseProfile
189190) noexcept {
190- auto relCxxflags = Try (validateFlags (
191- " cxxflags" ,
192- toml::find_or<std::vector<std::string>>(
193- val, " profile" , " release" , " cxxflags" , baseProfile.cxxflags
191+ static constexpr const char * key = " release" ;
192+
193+ auto cxxflags = Try (validateFlags (
194+ " cxxflags" , toml::find_or<std::vector<std::string>>(
195+ val, " profile" , key, " cxxflags" , baseProfile.cxxflags
196+ )
197+ ));
198+ auto ldflags = Try (validateFlags (
199+ " ldflags" , toml::find_or<std::vector<std::string>>(
200+ val, " profile" , key, " ldflags" , baseProfile.ldflags
201+ )
202+ ));
203+ const auto lto =
204+ toml::find_or<bool >(val, " profile" , key, " lto" , baseProfile.lto );
205+ const auto debug = toml::find_or<bool >(
206+ val, " profile" , key, " debug" , baseProfile.debug .unwrap_or (false )
207+ );
208+ const auto compDb =
209+ toml::find_or<bool >(val, " profile" , key, " compdb" , baseProfile.compDb );
210+ const auto optLevel = Try (validateOptLevel (
211+ toml::find_or<std::uint8_t >(
212+ val, " profile" , key, " opt-level" , baseProfile.optLevel .unwrap_or (3 )
194213 )
195214 ));
196- auto relLdflags = Try (validateFlags (
215+
216+ return Ok (Profile (
217+ std::move (cxxflags), std::move (ldflags), lto, debug, compDb, optLevel
218+ ));
219+ }
220+
221+ // Inherits from `dev`.
222+ static Result<Profile>
223+ parseTestProfile (const toml::value& val, const Profile& devProfile) noexcept {
224+ static constexpr const char * key = " test" ;
225+
226+ auto cxxflags = Try (validateFlags (
227+ " cxxflags" , toml::find_or<std::vector<std::string>>(
228+ val, " profile" , key, " cxxflags" , devProfile.cxxflags
229+ )
230+ ));
231+ auto ldflags = Try (validateFlags (
197232 " ldflags" , toml::find_or<std::vector<std::string>>(
198- val, " profile" , " release " , " ldflags" , baseProfile .ldflags
233+ val, " profile" , key , " ldflags" , devProfile .ldflags
199234 )
200235 ));
201- const auto relLto =
202- toml::find_or<bool >(val, " profile" , " release" , " lto" , baseProfile.lto );
203- const auto relDebug = toml::find_or<bool >(
204- val, " profile" , " release" , " debug" , baseProfile.debug .unwrap_or (false )
205- );
206- const auto relCompDb = toml::find_or<bool >(
207- val, " profile" , " release" , " compdb" , baseProfile.compDb
208- );
209- const auto relOptLevel = Try (validateOptLevel (
236+ const auto lto =
237+ toml::find_or<bool >(val, " profile" , key, " lto" , devProfile.lto );
238+ const auto debug =
239+ toml::find_or<bool >(val, " profile" , key, " debug" , devProfile.debug );
240+ const auto compDb =
241+ toml::find_or<bool >(val, " profile" , key, " compdb" , devProfile.compDb );
242+ const auto optLevel = Try (validateOptLevel (
210243 toml::find_or<std::uint8_t >(
211- val, " profile" , " release" , " opt-level" ,
212- baseProfile.optLevel .unwrap_or (3 )
244+ val, " profile" , key, " opt-level" , devProfile.optLevel
213245 )
214246 ));
215247
216248 return Ok (Profile (
217- std::move (relCxxflags), std::move (relLdflags), relLto, relDebug,
218- relCompDb, relOptLevel
249+ std::move (cxxflags), std::move (ldflags), lto, debug, compDb, optLevel
219250 ));
220251}
221252
222253static Result<std::unordered_map<BuildProfile, Profile>>
223254parseProfiles (const toml::value& val) noexcept {
224255 std::unordered_map<BuildProfile, Profile> profiles;
225256 const BaseProfile baseProfile = Try (parseBaseProfile (val));
226- profiles.emplace (BuildProfile::Dev, Try (parseDevProfile (val, baseProfile)));
257+ Profile devProfile = Try (parseDevProfile (val, baseProfile));
258+ profiles.emplace (BuildProfile::Test, Try (parseTestProfile (val, devProfile)));
259+ profiles.emplace (BuildProfile::Dev, std::move (devProfile));
227260 profiles.emplace (
228261 BuildProfile::Release, Try (parseReleaseProfile (val, baseProfile))
229262 );
@@ -821,17 +854,19 @@ testParseProfiles() {
821854 const toml::value empty = " " _toml;
822855
823856 const auto profiles = parseProfiles (empty).unwrap ();
824- assertEq (profiles.size (), 2UL );
857+ assertEq (profiles.size (), 3UL );
825858 assertEq (profiles.at (BuildProfile::Dev), devProfileDefault);
826859 assertEq (profiles.at (BuildProfile::Release), relProfileDefault);
860+ assertEq (profiles.at (BuildProfile::Test), devProfileDefault);
827861 }
828862 {
829863 const toml::value profOnly = " [profile]" _toml;
830864
831865 const auto profiles = parseProfiles (profOnly).unwrap ();
832- assertEq (profiles.size (), 2UL );
866+ assertEq (profiles.size (), 3UL );
833867 assertEq (profiles.at (BuildProfile::Dev), devProfileDefault);
834868 assertEq (profiles.at (BuildProfile::Release), relProfileDefault);
869+ assertEq (profiles.at (BuildProfile::Test), devProfileDefault);
835870 }
836871 {
837872 const toml::value baseOnly = R"(
@@ -851,9 +886,10 @@ testParseProfiles() {
851886 );
852887
853888 const auto profiles = parseProfiles (baseOnly).unwrap ();
854- assertEq (profiles.size (), 2UL );
889+ assertEq (profiles.size (), 3UL );
855890 assertEq (profiles.at (BuildProfile::Dev), expected);
856891 assertEq (profiles.at (BuildProfile::Release), expected);
892+ assertEq (profiles.at (BuildProfile::Test), expected);
857893 }
858894 {
859895 const toml::value overwrite = R"(
@@ -868,9 +904,10 @@ testParseProfiles() {
868904 )" _toml;
869905
870906 const auto profiles = parseProfiles (overwrite).unwrap ();
871- assertEq (profiles.size (), 2UL );
907+ assertEq (profiles.size (), 3UL );
872908 assertEq (profiles.at (BuildProfile::Dev), devProfileDefault);
873909 assertEq (profiles.at (BuildProfile::Release), relProfileDefault);
910+ assertEq (profiles.at (BuildProfile::Test), devProfileDefault);
874911 }
875912 {
876913 const toml::value overwrite = R"(
@@ -879,6 +916,9 @@ testParseProfiles() {
879916
880917 [profile.dev]
881918 opt-level = 1
919+
920+ [profile.test]
921+ cxxflags = ["-fno-rtti"]
882922 )" _toml;
883923
884924 const Profile devExpected (
@@ -891,11 +931,17 @@ testParseProfiles() {
891931 /* debug=*/ false ,
892932 /* compDb=*/ false , /* optLevel=*/ 2 // here, the default is 3
893933 );
934+ const Profile testExpected (
935+ /* cxxflags=*/ { " -fno-rtti" }, /* ldflags=*/ {}, /* lto=*/ false ,
936+ /* debug=*/ true ,
937+ /* compDb=*/ false , /* optLevel=*/ 1
938+ );
894939
895940 const auto profiles = parseProfiles (overwrite).unwrap ();
896- assertEq (profiles.size (), 2UL );
941+ assertEq (profiles.size (), 3UL );
897942 assertEq (profiles.at (BuildProfile::Dev), devExpected);
898943 assertEq (profiles.at (BuildProfile::Release), relExpected);
944+ assertEq (profiles.at (BuildProfile::Test), testExpected);
899945 }
900946}
901947
0 commit comments