1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 ###########################
11 # DotnetTest Target Class #
12 ###########################
14 ####### Constant Strings #########
16 gb_DotnetTest_CS
:= cs
17 gb_DotnetTest_FS
:= fs
18 gb_DotnetTest_VB
:= vb
20 define gb_DotnetTest__TEST_NUGETS
21 <PackageReference Include
="NUnit" Version
="4.1.0" /> \
22 <PackageReference Include
="NUnit3TestAdapter" Version
="4.5.0" /> \
23 <PackageReference Include
="Microsoft.NET.Test.Sdk" Version
="17.10.0" /> \
27 ####### Build and Clean Targets #########
29 # Template for a target to generate the project file for a DotnetTest
30 define gb_DotnetTest__project_target
31 $$(gb_DotnetTest_
$(1)_project
) :
32 $$(shell mkdir
-p
$$(dir $$@
))
33 $$(file
>$$@
,<Project Sdk
="Microsoft.NET.Sdk">)
34 $$(file
>>$$@
,<PropertyGroup
>)
35 $$(file
>>$$@
,$$(DOTNET_PROPERTY_ELEMENTS
))
36 $$(file
>>$$@
,</PropertyGroup
>)
37 $$(file
>>$$@
,<ItemGroup
>)
38 $$(file
>>$$@
,$$(DOTNET_ITEM_ELEMENTS
))
39 $$(file
>>$$@
,</ItemGroup
>)
40 $$(file
>>$$@
,</Project
>)
44 # Template for a target to build and run a DotnetTest
45 define gb_DotnetTest__build_target
46 $$(call gb_DotnetTest_get_target
,$(1)) : $$(gb_DotnetTest_
$(1)_project
)
47 $$(call gb_Output_announce
,$(1),$(true
),NET
,4)
48 $$(call gb_Trace_StartRange
,$(1),NET
)
49 $$(call gb_Helper_abbreviate_dirs
,\
50 $$(call gb_Helper_print_on_error
,\
51 "$$(DOTNET)" test $$< $$(DOTNET_BUILD_FLAGS
) -o
$$(dir $$@
),\
52 $$(gb_DotnetTest_workdir
)/$(1)/log
))
53 $$(call gb_Trace_EndRange
,$(1),NET
)
57 # Template for a target to clean a DotnetTest
58 define gb_DotnetTest__clean_target
59 $$(call gb_DotnetTest_get_clean_target
,$(1)) :
60 $$(call gb_Output_announce
,$(1),$(false
),NET
,4)
61 $$(call gb_Helper_abbreviate_dirs
,\
62 rm -rf
$$(gb_DotnetTest_
$(1)_project
))
66 ####### Test Target Constructor #########
68 # Generates one test project for the given language, instantiating
69 # the project file, build/run and clean targets from above templates
70 # call gb_DotnetTest_DotnetTest,targetname,language
71 define gb_DotnetTest_DotnetTest
72 gb_DotnetTest_
$(1)_language
:= $(2)
73 gb_DotnetTest_
$(1)_project
:= $(gb_DotnetTest_workdir
)/$(1)/$(1).
$(2)proj
75 $$(gb_DotnetTest_
$(1)_project
) : DOTNET_PROPERTY_ELEMENTS
:= <TargetFramework
>net8.0
</TargetFramework
>
76 $$(gb_DotnetTest_
$(1)_project
) : DOTNET_PROPERTY_ELEMENTS
+= <IsPackable
>false
</IsPackable
>
77 $$(gb_DotnetTest_
$(1)_project
) : DOTNET_PROPERTY_ELEMENTS
+= <IsTestProject
>true
</IsTestProject
>
78 $$(gb_DotnetTest_
$(1)_project
) : DOTNET_PROPERTY_ELEMENTS
+= <AssemblyName
>$(1)</AssemblyName
>
79 $$(gb_DotnetTest_
$(1)_project
) : DOTNET_ITEM_ELEMENTS
:= $(gb_DotnetTest__TEST_NUGETS
)
80 $$(eval
$$(call gb_DotnetTest__project_target
,$(1)))
82 $$(call gb_DotnetTest_get_target
,$(1)) : DOTNET_BUILD_FLAGS
:= $(if
$(ENABLE_DEBUG
),-c Debug
,-c Release
)
83 .PHONY
: $$(call gb_DotnetTest_get_target
,$(1))
84 $$(eval
$$(call gb_DotnetTest__build_target
,$(1)))
86 .PHONY
: $$(call gb_DotnetTest_get_clean_target
,$(1))
87 $$(eval
$$(call gb_DotnetTest__clean_target
,$(1)))
89 $$(eval
$$(call gb_Module_register_target
, \
90 $(call gb_DotnetTest_get_target
,$(1)), \
91 $(call gb_DotnetTest_get_clean_target
,$(1))))
92 $(call gb_Helper_make_userfriendly_targets
,$(1),DotnetTest
)
96 ####### Target Property Setters #########
98 # Add flags used for compilation
99 # call gb_DotnetTest_add_build_flags,target,flags
100 define gb_DotnetTest_add_build_flags
101 $(call gb_DotnetTest_get_target
,$(1)) : DOTNET_BUILD_FLAGS
+= $(2)
105 # Add <PropertyGroup> elements to the project file
106 # call gb_DotnetTest_add_properties,target,properties
107 define gb_DotnetTest_add_properties
108 $(gb_DotnetTest_
$(1)_project
) : DOTNET_PROPERTY_ELEMENTS
+= $(2)
112 # Add <ItemGroup> elements to the project file
113 # call gb_DotnetTest_add_items,target,items
114 define gb_DotnetTest_add_items
115 $(gb_DotnetTest_
$(1)_project
) : DOTNET_ITEM_ELEMENTS
+= $(2)
119 # Add one source file to the project file
120 # This adds it to the project, and makes it a build dependency
121 # so the test is rebuilt if the source changes
122 # call gb_DotnetTest_add_source,target,source
123 define gb_DotnetTest_add_source
124 $(gb_DotnetTest_
$(1)_project
) : $(SRCDIR
)/$(2).
$(gb_DotnetTest_
$(1)_language
)
125 $(call gb_DotnetTest_add_items
,$(1),<Compile Include
="$(SRCDIR)/$(2).$(gb_DotnetTest_$(1)_language)"/>)
129 # Add source files to the project file
130 # This adds them to the project, and makes it them build dependency
131 # so the test is rebuilt if the sources change
132 # call gb_DotnetTest_add_sources,target,sources
133 define gb_DotnetTest_add_sources
134 $(foreach source
,$(2),$(call gb_DotnetTest_add_source
,$(1),$(source
)))
138 # Link to a DotnetLibrary target
139 # call gb_DotnetTest_link_library,target,library
140 define gb_DotnetTest_link_library
141 $(gb_DotnetTest_
$(1)_project
) : $(call gb_DotnetLibrary_get_target
,$(2))
142 $(call gb_DotnetTest_add_items
,$(1),<ProjectReference Include
="$(gb_DotnetLibrary_$(2)_project)"/>)
146 # vim: set noet sw=4 ts=4: