Skip to content

Commit

Permalink
Build minmdns examples with build_examples.py (#11735)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
andy31415 authored and pull[bot] committed Dec 12, 2023
1 parent c3f20e1 commit 49d33f4
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 44 deletions.
4 changes: 2 additions & 2 deletions examples/minimal-mdns/AllInterfaceListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,7 +113,7 @@ class AllInterfaces : public mdns::Minimal::ListenIterator
return true;
}

printf("Usable interface: %s (%d)\n", name, static_cast<int>(mIterator.GetInterfaceId()));
printf("Usable interface: %s\n", name);

return false;
}
Expand Down
12 changes: 9 additions & 3 deletions examples/minimal-mdns/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down
10 changes: 8 additions & 2 deletions examples/minimal-mdns/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 36 additions & 31 deletions scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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
28 changes: 24 additions & 4 deletions scripts/build/testdata/build_linux_on_x64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 49d33f4

Please sign in to comment.