dlang / dub

Package and build management system for D
MIT License
673 stars 230 forks source link

Version is added to subPackage dependency #2659

Open andrey-zherikov opened 1 year ago

andrey-zherikov commented 1 year ago

System information

Bug Description

When a subPackage declares some version and depends on another subPackage, that version is populated to dependent package.

How to reproduce?

mkdir -p {a,b}/source

cat <<EOF >dub.json
{
        "license": "BSL-1.0",
        "name": "all",
        "targetType":"none",
        "dependencies":{
                "all:a":"*",
                "all:b":"*"
        },
        "subPackages": [
                "a",
                "b"
        ]
}
EOF

cat <<EOF >a/dub.json
{
        "name": "a",
        "targetType":"executable",
        "versions": ["MY_VERSION"]
}
EOF

cat <<EOF >b/dub.json
{
        "name": "b",
        "targetType":"executable",
        "versions": ["MY_VERSION"],
        "dependencies":{
                "all:a":"*"
        },
}
EOF

echo "void main() {}" | tee {a,b}/source/app.d >/dev/null

dub build -v | grep MY_VERSION

Output:

/usr/bin/dmd -c -of/home/andrey/.dub/cache/all/~master/+a/build/-debug-hn8j62aHsiDTDynm9acZxg/all_a.o -debug -g -w -version=MY_VERSION -version=Have_all_a -Ia/source/ a/source/app.d -vcolumns
/usr/bin/dmd -c -of/home/andrey/.dub/cache/all/~master/+b/build/-debug-5dpDg2vSWpcWgMqLulR0kA/all_b.o -debug -g -w -version=MY_VERSION -version=Have_all_b -Ib/source/ b/source/app.d -vcolumns

Note -version=MY_VERSION parameter while compiling a/source/app.d

Expected Behavior

No -version=MY_VERSION in compilation of dependency.

rikkimax commented 1 year ago

I'm not seeing anything wrong, both all:a and all:b add MY_VERSION.

There is no situation where the version would not be applied.

andrey-zherikov commented 1 year ago

Sorry, I didn't pay attention during copy-paste and provided wrong example.

The thing is that I have 3 sub packages: one library and two executables that depend on it; one executable defines version. The problem is that both executables as well as a library get the version defined which is unexpected. I expect version to be defined only for one sub package.

Here is correct example:

mkdir -p {l,a,b}/source
# top level project
cat <<EOF >dub.json
{
        "license": "BSL-1.0",
        "name": "all",
        "targetType":"none",
        "dependencies":{
                "all:l":"*",
                "all:a":"*",
                "all:b":"*"
        },
        "subPackages": [
                "l",
                "a",
                "b"
        ]
}
EOF
# library
cat <<EOF >l/dub.json
{
        "name": "l",
        "targetType":"library"
}
EOF
# executable that defines version
cat <<EOF >a/dub.json
{
        "name": "a",
        "targetType":"executable",
        "versions": ["MY_VERSION"],
        "dependencies":{
                "all:l":"*"
        },
}
EOF
# executable without version
cat <<EOF >b/dub.json
{
        "name": "b",
        "targetType":"executable",
        "dependencies":{
                "all:l":"*"
        },
}
EOF

echo "void foo() {}" >l/source/src.d
echo "void main() {}" | tee {a,b}/source/app.d >/dev/null

dub build -v | grep MY_VERSION

Output:

/usr/bin/dmd -lib -of/home/andrey/.dub/cache/all/~master/+l/build/library-debug-gVn44vagq5bsE1r9pPxkiQ/liball_l.a -debug -g -w -version=MY_VERSION -version=Have_all_l -Il/source/ l/source/src.d -vcolumns

/usr/bin/dmd -c -of/home/andrey/.dub/cache/all/~master/+a/build/-debug-hiJcs1-SeTS8y8-ChV0T0g/all_a.o -debug -g -w -version=MY_VERSION -version=Have_all_a -version=Have_all_l -Ia/source/ -Il/source/ a/source/app.d -vcolumns

/usr/bin/dmd -c -of/home/andrey/.dub/cache/all/~master/+b/build/-debug-sxmJ5-Yy5yjLua-L92xTMA/all_b.o -debug -g -w -version=Have_all_b -version=Have_all_l -version=MY_VERSION -Ib/source/ -Il/source/ b/source/app.d -vcolumns

As you can see -version=MY_VERSION is defined for all subpackages