Skip to content

Commit

Permalink
Rename environment variables controlling the Makefile (#26)
Browse files Browse the repository at this point in the history
Prefix `ARCH` and `PASS` with `DEVICE_` to communicate that they
refer to the architecture and password of the device under test,
as is already done for `DEVICE_IP`.

Prefix all the variables with `AXIS_` to make it less likely that they
will collide with variables used differently way by other programs.
This specific prefix is chosen to align with acap-native-sdk-examples
where `AXIS_DEVICE_IP` was recently adopted as the only placeholder
name for the IP address or domain name of a camera.
  • Loading branch information
apljungquist authored Jul 3, 2024
1 parent 2f226ee commit 64970ae
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
run: |
devcontainer up --workspace-folder .
devcontainer exec --workspace-folder . make --always-make check_all
devcontainer exec --workspace-folder . make build PACKAGE=licensekey_handler
devcontainer exec --workspace-folder . make build PACKAGE=embedded_web_page
devcontainer exec --workspace-folder . make build AXIS_PACKAGE=licensekey_handler
devcontainer exec --workspace-folder . make build AXIS_PACKAGE=embedded_web_page
- name: Install host dependencies
run: cargo install cross
- name: Run checks on host
Expand Down
70 changes: 35 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
# Name of package containing the app to be built.
# Rust does not enforce that the path to the package matches the package name, but
# this makefile does to keep things simple.
PACKAGE ?= hello_world
AXIS_PACKAGE ?= hello_world

# The architecture that will be assumed when interacting with the device.
ARCH ?= aarch64
AXIS_DEVICE_ARCH ?= aarch64

# The IP address of the device to interact with.
DEVICE_IP ?= 192.168.0.90
AXIS_DEVICE_IP ?= 192.168.0.90

# The password to use when interacting with the device.
PASS ?= pass
AXIS_DEVICE_PASS ?= pass

# Other
# -----
Expand Down Expand Up @@ -46,23 +46,23 @@ ACAP_BUILD = . /opt/axis/acapsdk/$(ENVIRONMENT_SETUP) && cd $(@D) && acap-build
CROSS := cargo

# It doesn't matter which SDK is sourced for installing, but using a wildcard would fail since there are multiple in the container.
EAP_INSTALL = cd $(CURDIR)/target/$(ARCH)/$(PACKAGE)/ \
&& . /opt/axis/acapsdk/environment-setup-cortexa53-crypto-poky-linux && eap-install.sh $(DEVICE_IP) $(PASS) $@
EAP_INSTALL = cd $(CURDIR)/target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/ \
&& . /opt/axis/acapsdk/environment-setup-cortexa53-crypto-poky-linux && eap-install.sh $(AXIS_DEVICE_IP) $(AXIS_DEVICE_PASS) $@

# Use a containerized environment when running on host.
else

# Bare minimum to make the output from the container available on host with correct permissions.
DOCKER_RUN = docker run \
--volume ${CURDIR}/target/$(ARCH)/$(PACKAGE)/:/opt/app \
--volume ${CURDIR}/target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/:/opt/app \
--user $(shell id -u):$(shell id -g) \
axisecp/acap-native-sdk:1.12-$(ARCH)-ubuntu22.04
axisecp/acap-native-sdk:1.12-$(AXIS_DEVICE_ARCH)-ubuntu22.04

ACAP_BUILD = $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && acap-build --build no-build ."

CROSS := cross

EAP_INSTALL = $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) $@"
EAP_INSTALL = $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(AXIS_DEVICE_IP) $(AXIS_DEVICE_PASS) $@"

endif

Expand All @@ -73,32 +73,32 @@ endif
help:
@mkhelp print_docs $(firstword $(MAKEFILE_LIST)) help

## Build <PACKAGE> for <ARCH>
build: target/$(ARCH)/$(PACKAGE)/_envoy
## Build <AXIS_PACKAGE> for <AXIS_DEVICE_ARCH>
build: target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/_envoy
mkdir -p target/acap
cp $(patsubst %/_envoy,%/*.eap,$^) target/acap

## Install <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Install <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
install:
@ $(EAP_INSTALL) \
| grep -v '^to start your application type$$' \
| grep -v '^ eap-install.sh start$$'

## Remove <PACKAGE> from <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Remove <AXIS_PACKAGE> from <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
remove:
@ $(EAP_INSTALL)

## Start <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Start <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
start:
@ $(EAP_INSTALL) \
| grep -v '^to stop your application type$$' \
| grep -v '^ eap-install.sh stop$$'

## Stop <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Stop <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
stop:
@ $(EAP_INSTALL)

## Build and run <PACKAGE> directly on <DEVICE_IP> assuming architecture <ARCH>
## Build and run <AXIS_PACKAGE> directly on <AXIS_DEVICE_IP> assuming architecture <AXIS_DEVICE_ARCH>
##
## Forwards the following environment variables to the remote process:
##
Expand All @@ -110,10 +110,10 @@ stop:
## * The app is installed on the device.
## * The app is stopped.
## * The device has SSH enabled the ssh user root configured.
run: target/$(ARCH)/$(PACKAGE)/$(PACKAGE)
scp $< root@$(DEVICE_IP):/usr/local/packages/$(PACKAGE)/$(PACKAGE)
ssh root@$(DEVICE_IP) \
"cd /usr/local/packages/$(PACKAGE) && su - acap-$(PACKAGE) -s /bin/sh --preserve-environment -c '$(if $(RUST_LOG_STYLE),RUST_LOG_STYLE=$(RUST_LOG_STYLE) )$(if $(RUST_LOG),RUST_LOG=$(RUST_LOG) )./$(PACKAGE)'"
run: target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/$(AXIS_PACKAGE)
scp $< root@$(AXIS_DEVICE_IP):/usr/local/packages/$(AXIS_PACKAGE)/$(AXIS_PACKAGE)
ssh root@$(AXIS_DEVICE_IP) \
"cd /usr/local/packages/$(AXIS_PACKAGE) && su - acap-$(AXIS_PACKAGE) -s /bin/sh --preserve-environment -c '$(if $(RUST_LOG_STYLE),RUST_LOG_STYLE=$(RUST_LOG_STYLE) )$(if $(RUST_LOG),RUST_LOG=$(RUST_LOG) )./$(AXIS_PACKAGE)'"

## Install development dependencies
sync_env: venv/bin/npm
Expand All @@ -129,7 +129,7 @@ check_all: check_build check_docs check_format check_lint check_tests check_gene
.PHONY: check_all

## Check that all crates can be built
check_build: target/aarch64/$(PACKAGE)/_envoy target/armv7hf/$(PACKAGE)/_envoy
check_build: target/aarch64/$(AXIS_PACKAGE)/_envoy target/armv7hf/$(AXIS_PACKAGE)/_envoy
cargo build \
--exclude licensekey \
--exclude licensekey-sys \
Expand Down Expand Up @@ -223,44 +223,44 @@ crates/%-sys/src/bindings.rs: FORCE
# * `.DELETE_ON_ERROR` does not work for directories, and
# * the name of the `.eap` file is annoying to predict.
# When building for all targets using a single image we cannot rely on wildcard matching.
target/aarch64/$(PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa53-crypto-poky-linux
target/armv7hf/$(PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa9hf-neon-poky-linux-gnueabi
target/%/$(PACKAGE)/_envoy: ARCH=$*
target/%/$(PACKAGE)/_envoy: target/%/$(PACKAGE)/lib target/%/$(PACKAGE)/html target/%/$(PACKAGE)/$(PACKAGE) target/%/$(PACKAGE)/manifest.json target/%/$(PACKAGE)/LICENSE
target/aarch64/$(AXIS_PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa53-crypto-poky-linux
target/armv7hf/$(AXIS_PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa9hf-neon-poky-linux-gnueabi
target/%/$(AXIS_PACKAGE)/_envoy: AXIS_DEVICE_ARCH=$*
target/%/$(AXIS_PACKAGE)/_envoy: target/%/$(AXIS_PACKAGE)/lib target/%/$(AXIS_PACKAGE)/html target/%/$(AXIS_PACKAGE)/$(AXIS_PACKAGE) target/%/$(AXIS_PACKAGE)/manifest.json target/%/$(AXIS_PACKAGE)/LICENSE
$(ACAP_BUILD)
touch $@

target/%/$(PACKAGE)/html: FORCE
target/%/$(AXIS_PACKAGE)/html: FORCE
mkdir -p $(dir $@)
if [ -d $@ ]; then rm -r $@; fi
if [ -d apps/$(PACKAGE)/html ]; then cp -r apps/$(PACKAGE)/html $@; fi
if [ -d apps/$(AXIS_PACKAGE)/html ]; then cp -r apps/$(AXIS_PACKAGE)/html $@; fi

target/%/$(PACKAGE)/lib: FORCE
target/%/$(AXIS_PACKAGE)/lib: FORCE
mkdir -p $(dir $@)
if [ -d $@ ]; then rm -r $@; fi
if [ -d apps/$(PACKAGE)/lib ]; then cp -r apps/$(PACKAGE)/lib $@; fi
if [ -d apps/$(AXIS_PACKAGE)/lib ]; then cp -r apps/$(AXIS_PACKAGE)/lib $@; fi

target/%/$(PACKAGE)/manifest.json: apps/$(PACKAGE)/manifest.json
target/%/$(AXIS_PACKAGE)/manifest.json: apps/$(AXIS_PACKAGE)/manifest.json
mkdir -p $(dir $@)
cp $< $@

target/%/$(PACKAGE)/LICENSE: apps/$(PACKAGE)/LICENSE
target/%/$(AXIS_PACKAGE)/LICENSE: apps/$(AXIS_PACKAGE)/LICENSE
mkdir -p $(dir $@)
cp $< $@

# The target triple and the name of the docker image do not match, so
# at some point we need to map one to the other. It might as well be here.
target/aarch64/$(PACKAGE)/$(PACKAGE): target/aarch64-unknown-linux-gnu/release/$(PACKAGE)
target/aarch64/$(AXIS_PACKAGE)/$(AXIS_PACKAGE): target/aarch64-unknown-linux-gnu/release/$(AXIS_PACKAGE)
mkdir -p $(dir $@)
cp $< $@

target/armv7hf/$(PACKAGE)/$(PACKAGE): target/thumbv7neon-unknown-linux-gnueabihf/release/$(PACKAGE)
target/armv7hf/$(AXIS_PACKAGE)/$(AXIS_PACKAGE): target/thumbv7neon-unknown-linux-gnueabihf/release/$(AXIS_PACKAGE)
mkdir -p $(dir $@)
cp $< $@

# Always rebuild the executable because configuring accurate cache invalidation is annoying.
target/%/release/$(PACKAGE): FORCE
$(CROSS) -v build --release --target $* --package $(PACKAGE)
target/%/release/$(AXIS_PACKAGE): FORCE
$(CROSS) -v build --release --target $* --package $(AXIS_PACKAGE)
touch $@ # This is a hack to make the `_envoy` target above always build


Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To simply get started with a new app, please see [acap-rs-app-template](https://

## Quickstart guide

The quickest way to build the `hello_world` example is to launch the dev container and run `make build PACKAGE=hello_world`.
The quickest way to build the `hello_world` example is to launch the dev container and run `make build AXIS_PACKAGE=hello_world`.
Once it completes there should be two `.eap` files in `target/acap`:

```console
Expand All @@ -32,7 +32,7 @@ docker run \
--volume $(pwd):$(pwd) \
--workdir $(pwd) \
acap-rs \
make build PACKAGE=hello_world
make build AXIS_PACKAGE=hello_world
```

This works with any of the [example applications](#example-applications).
Expand Down

0 comments on commit 64970ae

Please sign in to comment.