Macro Arguments

Can the arguments being passed on the substitutions be macro’s themselves?

I am trying to do something like

a.repo: ${if;${local.repo.common};${workspace.repo;${local.repo.common}};${repo.def;Common;common}}

In effect if the user defines local.repo.common then I want to use the workspace.repo and pass the value of the local.repo.common property otherwise get the default definition with substitutions

Can the arguments being passed on the substitutions be macro’s themselves?
Yes.

However, it gets complex and hard to read quickly. Using intermediate values makes the expression easier to pass for humans.

if the user defines local.repo.common then I want to use the workspace.repo and pass the value of the local.repo.common property otherwise get the default definition with substitutions

ws    = ${workspace.repo;${local.repo.common}}
deflt = ${repo.def;Common;common}
x     = ${if;${local.repo.common};${ws};${deflt}}

If you use bndtools, you can select a macro expression. If you then hover the cursor over the selection block, it will show you the expansion. Alternatively, the bnd command line has a shell command that allows you to debug macros. make sure you start it with a workspace as working directory.

$ bnd shell
Base Workspace [bndtools.workspace.min]
> ${foo}
${foo}
-----------------
Warnings
000: No translation found for macro: foo
> foo=4
> 
> ${foo}
4
> 

corrected typo ‘:’ to ‘;’

Can I confirm that the : is a typo and you meant

x = ${if;${local.repo.common};${ws};${deflt}}

java -jar ~/git/repo/compile/biz.aQute.bnd-6.4.1.jar bnd shell
Base
> override.repo.def = aQute.bnd.repository.osgi.OSGiRepository; name="Override rep ${1}";locations=file://${1}/index.xml
> repo.override.core.actual = ${override.repo.def;${repo.override.core}}
> repo.def = aQute.bnd.repository.osgi.OSGiRepository; name="${1}"; locations=${baserepo}/${2}/index.xml.gz
> core.repo = ${if;${repo.override.core};${repo.override.core.actual};${repo.def;Core;core}}
> ${core.repo}
aQute.bnd.repository.osgi.OSGiRepository;name = Override rep ${repo.override.core};locations = file://${repo.override.core}/index.xml
-----------------
Warnings
000: No translation found for macro: repo.override.core
>

I thought if the first arg is undefined then it should move to the default?

If you want a default for an undefined macro use ${def;repo.override.core; some value }. Otherwise the value is the literal macro, e.g. ${repo.override.core}.

Figured it out. On the if block the condition is either a value or an ldap expression. This means ${repo.override.core} this just evaluates as a string. What I REALLY want to say is (repo.override.core=*) IE if this property exists.

The working version is

override.repo.def = aQute.bnd.repository.osgi.OSGiRepository; name="Override rep ${1}";locations=file://${1}/index.xml
repo.def = aQute.bnd.repository.osgi.OSGiRepository; name="${1}"; locations=${baserepo}/${2}/index.xml.gz
core.repo = ${if;(repo.override.core=*);${override.repo.def;${repo.override.core}};${repo.def;Core;core}}

I would suggest an update to the documentation (if ‘;’ STRING ‘;’ STRING ( ‘;’ STRING )? | bnd) for the if macro to say as much. The condition text is quite unclear and I had to poke at the source to figure it out.

The filter option is quite obscure. It is better to use ${def}. I’d also simplify it to make it more readable. Just a suggestion but I learned over time that if you start to do more than basic things with macros it is quite crucial to keep them as simple as possible.

I see that you want to define a repository with two different locations and names based on when a macro is set. I came up wit this:

repo         = \
   aQute.bnd.repository.osgi.OSGiRepository; \
     name=“${1}”; \
     locations=${2}

core.repo         = 
	${if;${def;repo.override.core}; \
		${repo;Override rep ${repo.override.core};file://${repo.override.core}/index.xml}; \
		${repo;Core;${baserepo}/core/index.xml.gz} \
        }

I would suggest an update to the documentation (if ‘;’ STRING ‘;’ STRING ( ‘;’ STRING )? | bnd) for the if macro to say as much. The condition text is quite unclear and I had to poke at the source to figure it out.

:slight_smile: The beauty of open source :slight_smile: The filter function was added one day in the isTruthy function because it is kind of handy. However, it was at the time not intended as a first class feature.

However, if you create a PR with an update of Macro Reference | bnd and refer to this from $if

You can find the source code here: https://github.com/bndtools/bnd/blob/master/docs/_chapters/850-macros.md