Tue, 12 Nov 2024 17:00:51 +0100
add target data for disabled features - resolves #476
--- a/src/main/java/de/unixwork/uwproj/Feature.java Tue Nov 12 16:53:27 2024 +0100 +++ b/src/main/java/de/unixwork/uwproj/Feature.java Tue Nov 12 17:00:51 2024 +0100 @@ -10,8 +10,9 @@ private final String name; private final String arg; private final boolean auto; - private final String desc; private final TargetData targetData; + private final TargetData disabled = new TargetData(); + private String desc = ""; public Feature(Element e) { name = e.getAttribute("name"); @@ -19,12 +20,12 @@ auto = Boolean.parseBoolean(e.getAttribute("default")); targetData = new TargetData(e); - // TODO: when Option also receives descriptions, we will move desc to TargetData - desc = Util.getChildElements(e) - .filter(c -> c.getNodeName().equals("desc")) - .map(Util::getContent) - .findAny() - .orElse(""); + Util.getChildElements(e).forEach(elm -> { + switch (elm.getNodeName()) { + case "disabled" -> disabled.readFrom(elm); + case "desc" -> desc = Util.getContent(elm); + } + }); } public String getVarName() { @@ -32,11 +33,15 @@ } public List<String> getDependencies() { - return getTargetData().getDependencies(); + return targetData.getDependencies(); } public List<Define> getDefines() { - return getTargetData().getDefines(); + return targetData.getDefines(); + } + + public TargetData getDisabled() { + return disabled; } public String getMake() { @@ -63,10 +68,6 @@ return auto; } - public TargetData getTargetData() { - return targetData; - } - /** * Generates help text for the feature option. * <p>
--- a/src/main/java/de/unixwork/uwproj/TargetData.java Tue Nov 12 16:53:27 2024 +0100 +++ b/src/main/java/de/unixwork/uwproj/TargetData.java Tue Nov 12 17:00:51 2024 +0100 @@ -13,7 +13,14 @@ private final List<String> dependencies = new LinkedList<>(); private final List<String> make = new LinkedList<>(); + public TargetData() { + } + public TargetData(Element element) { + readFrom(element); + } + + public void readFrom(Element element) { Util.getChildElements(element).forEach(elm -> { switch (elm.getNodeName()) { case "define" -> defines.add(new Define(
--- a/src/main/resources/make/configure.vm Tue Nov 12 16:53:27 2024 +0100 +++ b/src/main/resources/make/configure.vm Tue Nov 12 17:00:51 2024 +0100 @@ -579,6 +579,23 @@ $feature.make __EOF__ #end +else + : +#foreach( $def in $feature.disabled.defines ) + TEMP_CFLAGS="$TEMP_CFLAGS ${def.toFlags()}" + TEMP_CXXFLAGS="$TEMP_CXXFLAGS ${def.toFlags()}" +#end +#if( $feature.disabled.hasMake() ) + cat >> "$TEMP_DIR/make.mk" << __EOF__ +$feature.disabled.make +__EOF__ +#end +#foreach( $dependency in $feature.disabled.dependencies ) + if dependency_error_$dependency ; then + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} " + ERROR=1 + fi +#end fi #end
--- a/src/main/resources/make/uwproj.xsd Tue Nov 12 16:53:27 2024 +0100 +++ b/src/main/resources/make/uwproj.xsd Tue Nov 12 17:00:51 2024 +0100 @@ -196,6 +196,9 @@ <code>dependencies</code> are satisfied. If a feature is enabled, all <code>define</code> and <code>make</code> definitions are supposed to be applied to the config file. + If a feature is disabled, an optional <code>disabled</code> element may specify which + <code>define</code> and <code>make</code> definitions are supposed to be applied. + There might also be <code>dependencies</code> when the feature is disabled (e.g. specifying a fallback). In case the optional <code>default</code> attribute is set to true, the feature is enabled by default and is supposed to be automatically disabled (without error) when the dependencies are not satisfied. The name that is supposed to be used for the --enable and --disable arguments can be optionally @@ -207,6 +210,13 @@ <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:group ref="TargetDataGroup"/> <xs:element name="desc" type="xs:string"/> + <xs:element name="disabled"> + <xs:complexType> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:group ref="TargetDataGroup"/> + </xs:choice> + </xs:complexType> + </xs:element> </xs:choice> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="arg" type="xs:string"/>
--- a/test/configure Tue Nov 12 16:53:27 2024 +0100 +++ b/test/configure Tue Nov 12 17:00:51 2024 +0100 @@ -584,6 +584,8 @@ fi if [ -n "$FEATURE_PG" ]; then : +else + : fi
--- a/test/configure2 Tue Nov 12 16:53:27 2024 +0100 +++ b/test/configure2 Tue Nov 12 17:00:51 2024 +0100 @@ -654,6 +654,8 @@ : TEMP_CFLAGS="$TEMP_CFLAGS -DDATABASE" TEMP_CXXFLAGS="$TEMP_CXXFLAGS -DDATABASE" +else + : fi if [ -n "$FEATURE_GUI" ]; then # check dependency @@ -674,6 +676,10 @@ : TEMP_CFLAGS="$TEMP_CFLAGS -DUI=GTK3" TEMP_CXXFLAGS="$TEMP_CXXFLAGS -DUI=GTK3" +else + : + TEMP_CFLAGS="$TEMP_CFLAGS -DCONSOLE" + TEMP_CXXFLAGS="$TEMP_CXXFLAGS -DCONSOLE" fi # Option: --toolkit
--- a/test/make/configure.vm Tue Nov 12 16:53:27 2024 +0100 +++ b/test/make/configure.vm Tue Nov 12 17:00:51 2024 +0100 @@ -579,6 +579,23 @@ $feature.make __EOF__ #end +else + : +#foreach( $def in $feature.disabled.defines ) + TEMP_CFLAGS="$TEMP_CFLAGS ${def.toFlags()}" + TEMP_CXXFLAGS="$TEMP_CXXFLAGS ${def.toFlags()}" +#end +#if( $feature.disabled.hasMake() ) + cat >> "$TEMP_DIR/make.mk" << __EOF__ +$feature.disabled.make +__EOF__ +#end +#foreach( $dependency in $feature.disabled.dependencies ) + if dependency_error_$dependency ; then + DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} " + ERROR=1 + fi +#end fi #end
--- a/test/make/project2.xml Tue Nov 12 16:53:27 2024 +0100 +++ b/test/make/project2.xml Tue Nov 12 17:00:51 2024 +0100 @@ -58,6 +58,9 @@ <feature name="gui"> <dependencies>gtk3</dependencies> <define name="UI" value="GTK3" /> + <disabled> + <define name="CONSOLE" /> + </disabled> </feature> <option arg="toolkit"> <value str="gtk3">
--- a/test/make/uwproj.xsd Tue Nov 12 16:53:27 2024 +0100 +++ b/test/make/uwproj.xsd Tue Nov 12 17:00:51 2024 +0100 @@ -196,6 +196,9 @@ <code>dependencies</code> are satisfied. If a feature is enabled, all <code>define</code> and <code>make</code> definitions are supposed to be applied to the config file. + If a feature is disabled, an optional <code>disabled</code> element may specify which + <code>define</code> and <code>make</code> definitions are supposed to be applied. + There might also be <code>dependencies</code> when the feature is disabled (e.g. specifying a fallback). In case the optional <code>default</code> attribute is set to true, the feature is enabled by default and is supposed to be automatically disabled (without error) when the dependencies are not satisfied. The name that is supposed to be used for the --enable and --disable arguments can be optionally @@ -207,6 +210,13 @@ <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:group ref="TargetDataGroup"/> <xs:element name="desc" type="xs:string"/> + <xs:element name="disabled"> + <xs:complexType> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:group ref="TargetDataGroup"/> + </xs:choice> + </xs:complexType> + </xs:element> </xs:choice> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="arg" type="xs:string"/>