build-unit-test-docker: use docker stagename everywhere

In some cases the script used a 'stagename' as the temporary docker
image used to create dependencies.  Use this throughout for
consistency.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I8b2d8624747b8a36630dd27f6aee32ddf10defa7
diff --git a/scripts/build-unit-test-docker b/scripts/build-unit-test-docker
index c274bec..5dc8d92 100755
--- a/scripts/build-unit-test-docker
+++ b/scripts/build-unit-test-docker
@@ -84,10 +84,13 @@
     "openbmc/stdplus": {},
 }
 
-
 def pkg_rev(pkg):
     return packages[pkg]["rev"]
 
+def pkg_stagename(pkg):
+    if not pkg.startswith("openbmc/"):
+        pkg = "openbmc/" + pkg
+    return pkg.replace("/", "-")
 
 # Look up the HEAD for missing a static rev.
 pkg_lookups = {}
@@ -131,19 +134,12 @@
     ]
 )
 
-
-def stagename(name):
-    if not name.startswith("openbmc/"):
-        name = "openbmc/" + name
-    return name.replace("/", "-")
-
-
 # Build the commands needed to compose our final image
 # We must sort the packages, otherwise we might produce an unstable
 # docker file and rebuild the image unnecessarily
 copy_cmds = ""
 for pkg in sorted(packages.keys()):
-    copy_cmds += f"COPY --from={stagename(pkg)} {prefix} {prefix}\n"
+    copy_cmds += f"COPY --from={pkg_stagename(pkg)} {prefix} {prefix}\n"
     # Workaround for upstream docker bug and multiple COPY cmds
     # https://github.com/moby/moby/issues/37965
     copy_cmds += "RUN true\n"
@@ -283,17 +279,17 @@
 RUN pip3 install meson==0.54.3
 RUN pip3 install protobuf
 
-FROM openbmc-base as openbmc-lcov
+FROM openbmc-base as {pkg_stagename('lcov')}
 RUN curl -L https://github.com/linux-test-project/lcov/archive/{pkg_rev('lcov')}.tar.gz | tar -xz && \
 cd lcov-* && \
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-function2
+FROM openbmc-base as {pkg_stagename('function2')}
 RUN mkdir {prefix}/include/function2 && \
 curl -L -o {prefix}/include/function2/function2.hpp https://raw.githubusercontent.com/Naios/function2/{pkg_rev('function2')}/include/function2/function2.hpp
 
-FROM openbmc-base as openbmc-googletest
+FROM openbmc-base as {pkg_stagename('googletest')}
 RUN curl -L https://github.com/google/googletest/archive/{pkg_rev('googletest')}.tar.gz | tar -xz && \
 cd googletest-* && \
 mkdir build && \
@@ -302,7 +298,7 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-catch2
+FROM openbmc-base as {pkg_stagename('catch2')}
 RUN curl -L https://github.com/catchorg/Catch2/archive/{pkg_rev('catch2')}.tar.gz | tar -xz && \
 cd Catch2-* && \
 mkdir build && \
@@ -311,11 +307,11 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-cereal
+FROM openbmc-base as {pkg_stagename('cereal')}
 RUN curl -L https://github.com/USCiLab/cereal/archive/{pkg_rev('cereal')}.tar.gz | tar -xz && \
 cp -a cereal-*/include/cereal/ {prefix}/include/
 
-FROM openbmc-base as openbmc-CLI11
+FROM openbmc-base as {pkg_stagename('CLI11')}
 RUN curl -L https://github.com/CLIUtils/CLI11/archive/{pkg_rev('CLI11')}.tar.gz | tar -xz && \
 cd CLI11-* && \
 mkdir build && \
@@ -324,7 +320,7 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-fmt
+FROM openbmc-base as {pkg_stagename('fmt')}
 RUN curl -L https://github.com/fmtlib/fmt/archive/{pkg_rev('fmt')}.tar.gz | tar -xz && \
 cd fmt-* && \
 mkdir build && \
@@ -333,16 +329,16 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-json
+FROM openbmc-base as {pkg_stagename('json')}
 RUN mkdir {prefix}/include/nlohmann/ && \
 curl -L -o {prefix}/include/nlohmann/json.hpp https://github.com/nlohmann/json/releases/download/{pkg_rev('json')}/json.hpp && \
 ln -s nlohmann/json.hpp {prefix}/include/json.hpp
 
-FROM openbmc-base as openbmc-fifo_map
+FROM openbmc-base as {pkg_stagename('fifo_map')}
 RUN curl -L https://github.com/nlohmann/fifo_map/archive/{pkg_rev('fifo_map')}.tar.gz | tar -xz && \
 cd fifo_map-*/src && cp fifo_map.hpp {prefix}/include/
 
-FROM openbmc-base as openbmc-span-lite
+FROM openbmc-base as {pkg_stagename('span-lite')}
 RUN curl -L https://github.com/martinmoene/span-lite/archive/{pkg_rev('span-lite')}.tar.gz | tar -xz && \
 cd span-lite-* && \
 mkdir build && \
@@ -351,19 +347,19 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-linux-headers
+FROM openbmc-base as {pkg_stagename('linux-headers')}
 RUN curl -L https://github.com/openbmc/linux/archive/{pkg_rev('linux-headers')}.tar.gz | tar -xz && \
 cd linux-* && \
 make -j{proc_count} defconfig && \
 make INSTALL_HDR_PATH=/usr/local headers_install
 
-FROM openbmc-base as openbmc-boost
+FROM openbmc-base as {pkg_stagename('boost')}
 RUN curl -L https://dl.bintray.com/boostorg/release/{pkg_rev('boost')}/source/boost_$(echo "{pkg_rev('boost')}" | tr '.' '_').tar.bz2 | tar -xj && \
 cd boost_*/ && \
 ./bootstrap.sh --prefix={prefix} --with-libraries=context,coroutine && \
 ./b2 && ./b2 install --prefix={prefix}
 
-FROM openbmc-base as openbmc-tinyxml2
+FROM openbmc-base as {pkg_stagename('tinyxml2')}
 RUN curl -L https://github.com/leethomason/tinyxml2/archive/{pkg_rev('tinyxml2')}.tar.gz | tar -xz && \
 cd tinyxml2-* && \
 mkdir build && \
@@ -372,7 +368,7 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-boost-url
+FROM openbmc-base as {pkg_stagename('boost-url')}
 RUN curl -L https://github.com/CPPAlliance/url/archive/{pkg_rev('boost-url')}.tar.gz | tar -xz && \
 cd url-* && \
 mkdir buildir && \
@@ -381,7 +377,7 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-valijson
+FROM openbmc-base as {pkg_stagename('valijson')}
 RUN curl -L https://github.com/tristanpenman/valijson/archive/{pkg_rev('valijson')}.tar.gz | tar -xz && \
 cd valijson-* && \
 mkdir build && \
@@ -390,7 +386,7 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-libvncserver
+FROM openbmc-base as {pkg_stagename('libvncserver')}
 RUN curl -L https://github.com/LibVNC/libvncserver/archive/{pkg_rev('libvncserver')}.tar.gz | tar -xz && \
 cd libvncserver-* && \
 mkdir build && \
@@ -399,16 +395,16 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-stdplus
-COPY --from=openbmc-fmt {prefix} {prefix}
-COPY --from=openbmc-span-lite {prefix} {prefix}
+FROM openbmc-base as {pkg_stagename('openbmc/stdplus')}
+COPY --from={pkg_stagename('fmt')} {prefix} {prefix}
+COPY --from={pkg_stagename('span-lite')} {prefix} {prefix}
 RUN curl -L https://github.com/openbmc/stdplus/archive/{pkg_rev('openbmc/stdplus')}.tar.gz | tar -xz && \
 cd stdplus-* && \
 meson build {meson_flags} -Dtests=disabled -Dexamples=false && \
 ninja -C build && \
 ninja -C build install
 
-FROM openbmc-base as openbmc-sdbusplus
+FROM openbmc-base as {pkg_stagename('openbmc/sdbusplus')}
 RUN curl -L https://github.com/openbmc/sdbusplus/archive/{pkg_rev('openbmc/sdbusplus')}.tar.gz | tar -xz && \
 cd sdbusplus-* && \
 cd tools && ./setup.py install --root=/ --prefix={prefix} && \
@@ -416,37 +412,37 @@
 ninja -C build && \
 ninja -C build install
 
-FROM openbmc-base as openbmc-sdeventplus
-COPY --from=openbmc-function2 {prefix} {prefix}
-COPY --from=openbmc-stdplus {prefix} {prefix}
+FROM openbmc-base as {pkg_stagename('openbmc/sdeventplus')}
+COPY --from={pkg_stagename('function2')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/stdplus')} {prefix} {prefix}
 RUN curl -L https://github.com/openbmc/sdeventplus/archive/{pkg_rev('openbmc/sdeventplus')}.tar.gz | tar -xz && \
 cd sdeventplus-* && \
 meson build {meson_flags} -Dtests=disabled -Dexamples=false && \
 ninja -C build && \
 ninja -C build install
 
-FROM openbmc-base as openbmc-gpioplus
-COPY --from=openbmc-stdplus {prefix} {prefix}
+FROM openbmc-base as {pkg_stagename('openbmc/gpioplus')}
+COPY --from={pkg_stagename('openbmc/stdplus')} {prefix} {prefix}
 RUN curl -L https://github.com/openbmc/gpioplus/archive/{pkg_rev('openbmc/gpioplus')}.tar.gz | tar -xz && \
 cd gpioplus-* && \
 meson build {meson_flags} -Dtests=disabled -Dexamples=false && \
 ninja -C build && \
 ninja -C build install
 
-FROM openbmc-base as openbmc-phosphor-dbus-interfaces
-COPY --from=openbmc-sdbusplus {prefix} {prefix}
+FROM openbmc-base as {pkg_stagename('openbmc/phosphor-dbus-interfaces')}
+COPY --from={pkg_stagename('openbmc/sdbusplus')} {prefix} {prefix}
 RUN curl -L https://github.com/openbmc/phosphor-dbus-interfaces/archive/{pkg_rev('openbmc/phosphor-dbus-interfaces')}.tar.gz | tar -xz && \
 cd phosphor-dbus-interfaces-* && \
 meson build {meson_flags} -Ddata_org_open_power=true -Ddata_com_ibm=true && \
 ninja -C build && \
 ninja -C build install
 
-FROM openbmc-base as openbmc-phosphor-logging
-COPY --from=openbmc-cereal {prefix} {prefix}
-COPY --from=openbmc-sdbusplus {prefix} {prefix}
-COPY --from=openbmc-sdeventplus {prefix} {prefix}
-COPY --from=openbmc-phosphor-dbus-interfaces {prefix} {prefix}
-COPY --from=openbmc-fifo_map {prefix} {prefix}
+FROM openbmc-base as {pkg_stagename('openbmc/phosphor-logging')}
+COPY --from={pkg_stagename('cereal')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/sdbusplus')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/sdeventplus')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/phosphor-dbus-interfaces')} {prefix} {prefix}
+COPY --from={pkg_stagename('fifo_map')} {prefix} {prefix}
 RUN curl -L https://github.com/openbmc/phosphor-logging/archive/{pkg_rev('openbmc/phosphor-logging')}.tar.gz | tar -xz && \
 cd phosphor-logging-* && \
 ./bootstrap.sh && \
@@ -454,11 +450,11 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-phosphor-objmgr
-COPY --from=openbmc-boost {prefix} {prefix}
-COPY --from=openbmc-sdbusplus {prefix} {prefix}
-COPY --from=openbmc-tinyxml2 {prefix} {prefix}
-COPY --from=openbmc-phosphor-logging {prefix} {prefix}
+FROM openbmc-base as {pkg_stagename('openbmc/phosphor-objmgr')}
+COPY --from={pkg_stagename('boost')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/sdbusplus')} {prefix} {prefix}
+COPY --from={pkg_stagename('tinyxml2')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/phosphor-logging')} {prefix} {prefix}
 RUN curl -L https://github.com/openbmc/phosphor-objmgr/archive/{pkg_rev('openbmc/phosphor-objmgr')}.tar.gz | tar -xz && \
 cd phosphor-objmgr-* && \
 ./bootstrap.sh && \
@@ -466,7 +462,7 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-open-power-pdbg
+FROM openbmc-base as {pkg_stagename('open-power/pdbg')}
 RUN curl -L https://github.com/open-power/pdbg/archive/{pkg_rev('open-power/pdbg')}.tar.gz | tar -xz && \
 cd pdbg-* && \
 ./bootstrap.sh && \
@@ -474,14 +470,14 @@
 make -j{proc_count} && \
 make install
 
-FROM openbmc-base as openbmc-pldm
-COPY --from=openbmc-sdbusplus {prefix} {prefix}
-COPY --from=openbmc-sdeventplus {prefix} {prefix}
-COPY --from=openbmc-boost {prefix} {prefix}
-COPY --from=openbmc-phosphor-dbus-interfaces {prefix} {prefix}
-COPY --from=openbmc-phosphor-logging {prefix} {prefix}
-COPY --from=openbmc-json {prefix} {prefix}
-COPY --from=openbmc-CLI11 {prefix} {prefix}
+FROM openbmc-base as {pkg_stagename('openbmc/pldm')}
+COPY --from={pkg_stagename('openbmc/sdbusplus')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/sdeventplus')} {prefix} {prefix}
+COPY --from={pkg_stagename('boost')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/phosphor-dbus-interfaces')} {prefix} {prefix}
+COPY --from={pkg_stagename('openbmc/phosphor-logging')} {prefix} {prefix}
+COPY --from={pkg_stagename('json')} {prefix} {prefix}
+COPY --from={pkg_stagename('CLI11')} {prefix} {prefix}
 RUN curl -L https://github.com/openbmc/pldm/archive/{pkg_rev('openbmc/pldm')}.tar.gz | tar -xz && \
 cd pldm-* && \
 meson build {meson_flags} -Dlibpldm-only=enabled -Doem-ibm=enabled -Dtests=disabled && \