From 49d33f4c734c883318c880c1ff5c3d4efe096100 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 15 Nov 2021 08:37:42 -0500 Subject: [PATCH] Build minmdns examples with build_examples.py (#11735) * Add target and make minmdns compile * Update output logic to support multiple outputs per app * Fix output names * Update how output names are yielded * Restyle fixes * Update the build logic: targets decide options, no need for extra RPC guards. Fix rpc artifact names * Fix unit tests * Allow rpc console to be built natively only * Restyle fixes --- examples/minimal-mdns/AllInterfaceListener.h | 4 +- examples/minimal-mdns/client.cpp | 12 +++- examples/minimal-mdns/server.cpp | 10 ++- scripts/build/build/targets.py | 8 ++- scripts/build/builders/host.py | 67 ++++++++++--------- scripts/build/testdata/build_linux_on_x64.txt | 28 ++++++-- 6 files changed, 85 insertions(+), 44 deletions(-) diff --git a/examples/minimal-mdns/AllInterfaceListener.h b/examples/minimal-mdns/AllInterfaceListener.h index 178c91b189e8e4..4744583a7f0762 100644 --- a/examples/minimal-mdns/AllInterfaceListener.h +++ b/examples/minimal-mdns/AllInterfaceListener.h @@ -39,7 +39,7 @@ class AllInterfaces : public mdns::Minimal::ListenIterator if (mState == State::kIpV4) { #if INET_CONFIG_ENABLE_IPV4 - *id = Inet::InterfaceId::Null(); + *id = chip::Inet::InterfaceId::Null(); *type = chip::Inet::IPAddressType::kIPv4; #endif mState = State::kIpV6; @@ -113,7 +113,7 @@ class AllInterfaces : public mdns::Minimal::ListenIterator return true; } - printf("Usable interface: %s (%d)\n", name, static_cast(mIterator.GetInterfaceId())); + printf("Usable interface: %s\n", name); return false; } diff --git a/examples/minimal-mdns/client.cpp b/examples/minimal-mdns/client.cpp index 2788d813dc9c17..cacb5fcf438420 100644 --- a/examples/minimal-mdns/client.cpp +++ b/examples/minimal-mdns/client.cpp @@ -186,7 +186,10 @@ class ReportDelegate : public mdns::Minimal::ServerDelegate char addr[32]; info->SrcAddress.ToString(addr, sizeof(addr)); - printf("QUERY from: %-15s on port %d, via interface %d\n", addr, info->SrcPort, info->Interface); + char ifName[64]; + VerifyOrDie(info->Interface.GetInterfaceName(ifName, sizeof(ifName)) == CHIP_NO_ERROR); + + printf("QUERY from: %-15s on port %d, via interface %s\n", addr, info->SrcPort, ifName); Report("QUERY: ", data); } @@ -195,7 +198,10 @@ class ReportDelegate : public mdns::Minimal::ServerDelegate char addr[32]; info->SrcAddress.ToString(addr, sizeof(addr)); - printf("RESPONSE from: %-15s on port %d, via interface %d\n", addr, info->SrcPort, info->Interface); + char ifName[64]; + VerifyOrDie(info->Interface.GetInterfaceName(ifName, sizeof(ifName)) == CHIP_NO_ERROR); + + printf("RESPONSE from: %-15s on port %d, via interface %s\n", addr, info->SrcPort, ifName); Report("RESPONSE: ", data); } @@ -328,7 +334,7 @@ int main(int argc, char ** args) BroadcastPacket(&mdnsServer); err = DeviceLayer::SystemLayer().StartTimer( - gOptions.runtimeMs, + chip::System::Clock::Milliseconds32(gOptions.runtimeMs), [](System::Layer *, void *) { DeviceLayer::PlatformMgr().StopEventLoopTask(); DeviceLayer::PlatformMgr().Shutdown(); diff --git a/examples/minimal-mdns/server.cpp b/examples/minimal-mdns/server.cpp index 8ea5cda16ec028..1d310b9618851b 100644 --- a/examples/minimal-mdns/server.cpp +++ b/examples/minimal-mdns/server.cpp @@ -115,7 +115,10 @@ class ReplyDelegate : public mdns::Minimal::ServerDelegate, public mdns::Minimal char addr[INET6_ADDRSTRLEN]; info->SrcAddress.ToString(addr, sizeof(addr)); - printf("QUERY from: %-15s on port %d, via interface %d\n", addr, info->SrcPort, info->Interface); + char ifName[64]; + VerifyOrDie(info->Interface.GetInterfaceName(ifName, sizeof(ifName)) == CHIP_NO_ERROR); + + printf("QUERY from: %-15s on port %d, via interface %s\n", addr, info->SrcPort, ifName); Report("QUERY: ", data); mCurrentSource = info; @@ -131,7 +134,10 @@ class ReplyDelegate : public mdns::Minimal::ServerDelegate, public mdns::Minimal char addr[INET6_ADDRSTRLEN]; info->SrcAddress.ToString(addr, sizeof(addr)); - printf("RESPONSE from: %-15s on port %d, via interface %d\n", addr, info->SrcPort, info->Interface); + char ifName[64]; + VerifyOrDie(info->Interface.GetInterfaceName(ifName, sizeof(ifName)) == CHIP_NO_ERROR); + + printf("RESPONSE from: %-15s on port %d, via interface %s\n", addr, info->SrcPort, ifName); } // ParserDelegate diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index bfe09d3128103c..4c7d45573589bc 100644 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -105,13 +105,17 @@ def HostTargets(): targets.append(target.Extend('arm64', board=HostBoard.ARM64)) app_targets = [] + + # RPC console compilation only for native + app_targets.append( + targets[0].Extend('rpc-console', app=HostApp.RPC_CONSOLE)) + for target in targets: app_targets.append(target.Extend( 'all-clusters', app=HostApp.ALL_CLUSTERS)) app_targets.append(target.Extend('chip-tool', app=HostApp.CHIP_TOOL)) app_targets.append(target.Extend('thermostat', app=HostApp.THERMOSTAT)) - app_targets.append(target.Extend( - 'rpc-console', app=HostApp.RPC_CONSOLE)) + app_targets.append(target.Extend('minmdns', app=HostApp.MIN_MDNS)) for target in app_targets: yield target diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index b913d5fd2325dc..548358092d48e0 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -25,6 +25,7 @@ class HostApp(Enum): CHIP_TOOL = auto() THERMOSTAT = auto() RPC_CONSOLE = auto() + MIN_MDNS = auto() def ExamplePath(self): if self == HostApp.ALL_CLUSTERS: @@ -35,18 +36,30 @@ def ExamplePath(self): return 'thermostat/linux' elif self == HostApp.RPC_CONSOLE: return 'common/pigweed/rpc_console' + if self == HostApp.MIN_MDNS: + return 'minimal-mdns' else: raise Exception('Unknown app type: %r' % self) - def BinaryName(self): + def OutputNames(self): if self == HostApp.ALL_CLUSTERS: - return 'chip-all-clusters-app' + yield 'chip-all-clusters-app' + yield 'chip-all-clusters-app.map' elif self == HostApp.CHIP_TOOL: - return 'chip-tool' + yield 'chip-tool' + yield 'chip-tool.map' elif self == HostApp.THERMOSTAT: - return 'thermostat-app' + yield 'thermostat-app' + yield 'thermostat-app.map' elif self == HostApp.RPC_CONSOLE: - return 'rpc-console' + yield 'chip_rpc_console_wheels' + elif self == HostApp.MIN_MDNS: + yield 'mdns-advertiser' + yield 'mdns-advertiser.map' + yield 'minimal-mdns-client' + yield 'minimal-mdns-client.map' + yield 'minimal-mdns-server' + yield 'minimal-mdns-server.map' else: raise Exception('Unknown app type: %r' % self) @@ -91,12 +104,11 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE, enable_ip root=os.path.join(root, 'examples', app.ExamplePath()), runner=runner) - self.app_name = app.BinaryName() - self.map_name = self.app_name + '.map' + self.app = app self.board = board self.extra_gn_options = [] - if 'rpc-console' not in self.app_name and not enable_ipv4: + if not enable_ipv4: self.extra_gn_options.append('chip_inet_config_enable_ipv4=false') def GnBuildArgs(self): @@ -106,18 +118,12 @@ def GnBuildArgs(self): self.extra_gn_options.extend( [ 'target_cpu="arm64"', - 'is_clang=true' + 'is_clang=true', + 'chip_crypto="mbedtls"', + 'sysroot="%s"' % self.SysRootPath('SYSROOT_AARCH64') ] ) - if 'rpc-console' not in self.app_name: - self.extra_gn_options.extend( - [ - 'chip_crypto="mbedtls"', - 'sysroot="%s"' % self.SysRootPath('SYSROOT_AARCH64') - ] - ) - return self.extra_gn_options else: raise Exception('Unknown host board type: %r' % self) @@ -139,19 +145,18 @@ def SysRootPath(self, name): def build_outputs(self): outputs = {} - if 'rpc-console' not in self.app_name: - outputs.update( - { - self.app_name: os.path.join(self.output_dir, self.app_name), - self.map_name: os.path.join(self.output_dir, self.map_name) - } - ) - else: - outputs.update( - { - self.app_name: os.path.join( - self.output_dir, "chip_rpc_console_wheels") - } - ) + + for name in self.app.OutputNames(): + path = os.path.join(self.output_dir, name) + if os.path.isdir(path): + for root, dirs, files in os.walk(path): + for file in files: + outputs.update({ + file: os.path.join(root, file) + }) + else: + outputs.update({ + name: os.path.join(self.output_dir, name) + }) return outputs diff --git a/scripts/build/testdata/build_linux_on_x64.txt b/scripts/build/testdata/build_linux_on_x64.txt index 184665ebbef17d..99c49ec1d5ddeb 100644 --- a/scripts/build/testdata/build_linux_on_x64.txt +++ b/scripts/build/testdata/build_linux_on_x64.txt @@ -21,10 +21,15 @@ bash -c ' PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \ gn gen --check --fail-on-unused-args --root={root}/examples/chip-tool '"'"'--args=chip_inet_config_enable_ipv4=false target_cpu="arm64" is_clang=true chip_crypto="mbedtls" sysroot="SYSROOT_AARCH64"'"'"' {out}/linux-arm64-chip-tool-ipv6only' -# Generating linux-arm64-rpc-console +# Generating linux-arm64-minmdns bash -c ' PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \ - gn gen --check --fail-on-unused-args --root={root}/examples/common/pigweed/rpc_console '"'"'--args=target_cpu="arm64" is_clang=true'"'"' {out}/linux-arm64-rpc-console' + gn gen --check --fail-on-unused-args --root={root}/examples/minimal-mdns '"'"'--args=target_cpu="arm64" is_clang=true chip_crypto="mbedtls" sysroot="SYSROOT_AARCH64"'"'"' {out}/linux-arm64-minmdns' + +# Generating linux-arm64-minmdns-ipv6only +bash -c ' +PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \ + gn gen --check --fail-on-unused-args --root={root}/examples/minimal-mdns '"'"'--args=chip_inet_config_enable_ipv4=false target_cpu="arm64" is_clang=true chip_crypto="mbedtls" sysroot="SYSROOT_AARCH64"'"'"' {out}/linux-arm64-minmdns-ipv6only' # Generating linux-arm64-thermostat bash -c ' @@ -48,6 +53,12 @@ gn gen --check --fail-on-unused-args --root={root}/examples/chip-tool {out}/linu # Generating linux-x64-chip-tool-ipv6only gn gen --check --fail-on-unused-args --root={root}/examples/chip-tool --args=chip_inet_config_enable_ipv4=false {out}/linux-x64-chip-tool-ipv6only +# Generating linux-x64-minmdns +gn gen --check --fail-on-unused-args --root={root}/examples/minimal-mdns {out}/linux-x64-minmdns + +# Generating linux-x64-minmdns-ipv6only +gn gen --check --fail-on-unused-args --root={root}/examples/minimal-mdns --args=chip_inet_config_enable_ipv4=false {out}/linux-x64-minmdns-ipv6only + # Generating linux-x64-rpc-console gn gen --check --fail-on-unused-args --root={root}/examples/common/pigweed/rpc_console {out}/linux-x64-rpc-console @@ -69,8 +80,11 @@ ninja -C {out}/linux-arm64-chip-tool # Building linux-arm64-chip-tool-ipv6only ninja -C {out}/linux-arm64-chip-tool-ipv6only -# Building linux-arm64-rpc-console -ninja -C {out}/linux-arm64-rpc-console +# Building linux-arm64-minmdns +ninja -C {out}/linux-arm64-minmdns + +# Building linux-arm64-minmdns-ipv6only +ninja -C {out}/linux-arm64-minmdns-ipv6only # Building linux-arm64-thermostat ninja -C {out}/linux-arm64-thermostat @@ -90,6 +104,12 @@ ninja -C {out}/linux-x64-chip-tool # Building linux-x64-chip-tool-ipv6only ninja -C {out}/linux-x64-chip-tool-ipv6only +# Building linux-x64-minmdns +ninja -C {out}/linux-x64-minmdns + +# Building linux-x64-minmdns-ipv6only +ninja -C {out}/linux-x64-minmdns-ipv6only + # Building linux-x64-rpc-console ninja -C {out}/linux-x64-rpc-console