Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: [nasa/nos3#254] Build in external directory #415

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
#
BUILDTYPE ?= debug
INSTALLPREFIX ?= exe
FSWBUILDDIR ?= $(CURDIR)/fsw/build
GSWBUILDDIR ?= $(CURDIR)/gsw/build
SIMBUILDDIR ?= $(CURDIR)/sims/build
NOS3BUILDDIR ?= /tmp/nos3
FSWBUILDDIR ?= $(NOS3BUILDDIR)/fsw
GSWBUILDDIR ?= $(NOS3BUILDDIR)/gsw
SIMBUILDDIR ?= $(NOS3BUILDDIR)/sims

export CFS_APP_PATH = ../components
export MISSION_DEFS = ../cfg/build/
export MISSIONCONFIG = ../cfg/build/nos3
export MISSION_DEFS = /tmp/nos3/cfg/nos3_defs
export MISSIONCONFIG = nos3

# The "prep" step requires extra options that are specified via enviroment variables.
# Certain special ones should be passed via cache (-D) options to CMake.
# These are only needed for the "prep" target but they are computed globally anyway.
PREP_OPTS :=
PREP_OPTS := -DMISSION_DEFS=$(MISSION_DEFS)

ifneq ($(INSTALLPREFIX),)
PREP_OPTS += -DCMAKE_INSTALL_PREFIX=$(INSTALLPREFIX)
Expand Down Expand Up @@ -48,29 +49,29 @@ all:

build-cryptolib:
mkdir -p $(GSWBUILDDIR)
cd $(GSWBUILDDIR) && cmake $(PREP_OPTS) -DSUPPORT=1 ../../components/cryptolib
cd $(GSWBUILDDIR) && cmake -DSUPPORT=1 $(CURDIR)/components/cryptolib
$(MAKE) --no-print-directory -C $(GSWBUILDDIR)

build-fsw:
ifeq ($(FLIGHT_SOFTWARE), fprime)
cd fsw/fprime/fprime-nos3 && fprime-util generate && fprime-util build
else
mkdir -p $(FSWBUILDDIR)
cd $(FSWBUILDDIR) && cmake $(PREP_OPTS) ../cfe
cd $(FSWBUILDDIR) && cmake $(PREP_OPTS) $(CURDIR)/fsw/cfe
$(MAKE) --no-print-directory -C $(FSWBUILDDIR) mission-install
endif

build-sim:
mkdir -p $(SIMBUILDDIR)
cd $(SIMBUILDDIR) && cmake -DCMAKE_INSTALL_PREFIX=$(SIMBUILDDIR) ..
cd $(SIMBUILDDIR) && cmake -DCMAKE_INSTALL_PREFIX=$(SIMBUILDDIR) $(CURDIR)/sims
$(MAKE) --no-print-directory -C $(SIMBUILDDIR) install

build-test:
ifeq ($(FLIGHT_SOFTWARE), fprime)
# TODO
else
mkdir -p $(FSWBUILDDIR)
cd $(FSWBUILDDIR) && cmake $(PREP_OPTS) -DENABLE_UNIT_TESTS=true ../cfe
cd $(FSWBUILDDIR) && cmake $(PREP_OPTS) -DENABLE_UNIT_TESTS=true $(CURDIR)/fsw/cfe
$(MAKE) --no-print-directory -C $(FSWBUILDDIR) mission-install
endif

Expand All @@ -81,22 +82,19 @@ clean:
$(MAKE) clean-fsw
$(MAKE) clean-sim
$(MAKE) clean-gsw
rm -rf cfg/build
./scripts/clean.sh

clean-fsw:
rm -rf cfg/build/nos3_defs
rm -rf fsw/build
rm -rf fsw/fprime/fprime-nos3/build-artifacts
rm -rf fsw/fprime/fprime-nos3/build-fprime-automatic-native
rm -rf fsw/fprime/fprime-nos3/fprime-venv
./scripts/fsw/fsw_clean.sh

clean-sim:
rm -rf sims/build
./scripts/sim/sim_clean.sh

clean-gsw:
rm -rf gsw/build
rm -rf gsw/cosmos/build
rm -rf /tmp/nos3
./scripts/gsw/gsw_clean.sh

config:
./scripts/cfg/config.sh
Expand All @@ -105,17 +103,17 @@ debug:
./scripts/debug.sh

fsw:
./cfg/build/fsw_build.sh
$(NOS3BUILDDIR)/cfg/fsw_build.sh $(CURDIR)

gsw:
./scripts/gsw/build_cryptolib.sh
./cfg/build/gsw_build.sh
$(NOS3BUILDDIR)/cfg/gsw_build.sh $(CURDIR)

igniter:
./scripts/igniter_launch.sh

launch:
./cfg/build/launch.sh
$(NOS3BUILDDIR)/cfg/launch.sh $(CURDIR)

log:
./scripts/log.sh
Expand All @@ -130,7 +128,7 @@ prep-sat:
./scripts/cfg/prep_sat.sh

sim:
./scripts/build_sim.sh
./scripts/sim/build_sim.sh

start-gsw:
./scripts/gsw/launch_gsw.sh
Expand Down
2 changes: 1 addition & 1 deletion cfg/InOut/Inp_Graphics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Skymap09.txt ! Star Catalog File Name
TRUE ! Map Window Exists
FALSE ! Orrery Window Exists
TRUE ! Unit Sphere Window Exists
FALSE ! Unit Sphere Window Exists
******************************* POV *********************************
FALSE ! Pause at Startup
TRACK_HOST ! POV Mode (TRACK_HOST, TRACK_TARGET, FIXED_IN_HOST)
Expand Down
2 changes: 1 addition & 1 deletion cfg/nos3_defs/targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ list(APPEND MISSION_GLOBAL_APPLIST
fm
lc
sbn
sbn_tcp
sbn/modules/protocol/sbn_tcp
sbn_client
sc
sch
Expand Down
16 changes: 11 additions & 5 deletions scripts/cfg/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/../env.sh

# Make flight software configuration directory
mkdir -p $BASE_DIR/cfg/build
# Make build directories
mkdir -p $USER_NOS3_BUILD_DIR/cfg
mkdir -p $USER_NOS3_BUILD_DIR/fsw
mkdir -p $USER_NOS3_BUILD_DIR/gsw
mkdir -p $USER_NOS3_BUILD_DIR/sims

# Copy baseline configurations into build directory
cp -r $BASE_DIR/cfg/InOut $BASE_DIR/cfg/build/
cp -r $BASE_DIR/cfg/nos3_defs $BASE_DIR/cfg/build/
cp -r $BASE_DIR/cfg/sims $BASE_DIR/cfg/build/
cp -r $BASE_DIR/cfg/InOut $USER_NOS3_BUILD_DIR/cfg/
cp -r $BASE_DIR/cfg/nos3_defs $USER_NOS3_BUILD_DIR/cfg/
cp -r $BASE_DIR/cfg/sims $USER_NOS3_BUILD_DIR/cfg/

# Configure flight software
python3 $SCRIPT_DIR/cfg/configure.py

# Set permissions
chmod 777 -R $USER_NOS3_BUILD_DIR
44 changes: 22 additions & 22 deletions scripts/cfg/configure.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

if (fsw_cfg == 'fprime'):
fsw_identified = 1
os.system('cp ./scripts/fsw/fsw_fprime_build.sh ./cfg/build/fsw_build.sh')
os.system('cp ./scripts/fsw/fsw_fprime_launch.sh ./cfg/build/launch.sh')
os.system('cp ./scripts/fsw/fsw_fprime_build.sh /tmp/nos3/cfg/fsw_build.sh')
os.system('cp ./scripts/fsw/fsw_fprime_launch.sh /tmp/nos3/cfg/launch.sh')
if (fsw_cfg == 'cfs'):
fsw_identified = 1
os.system('cp ./scripts/fsw/fsw_cfs_build.sh ./cfg/build/fsw_build.sh')
os.system('cp ./scripts/fsw/fsw_cfs_launch.sh ./cfg/build/launch.sh')
os.system('cp ./scripts/fsw/fsw_cfs_build.sh /tmp/nos3/cfg/fsw_build.sh')
os.system('cp ./scripts/fsw/fsw_cfs_launch.sh /tmp/nos3/cfg/launch.sh')
if (fsw_identified == 0):
print('Invalid FSW in configuration file!')
print('Exiting due to error...')
Expand All @@ -41,25 +41,25 @@

gsw_identified = 0
if (gsw_cfg == 'openc3'):
# Copy openc3 scripts into ./cfg/build
# Copy openc3 scripts into /tmp/nos3
gsw_identified = 1
os.system('cp ./scripts/gsw/gsw_openc3_build.sh ./cfg/build/gsw_build.sh')
os.system('cp ./scripts/gsw/gsw_openc3_launch.sh ./cfg/build/gsw_launch.sh')
os.system('cp ./scripts/gsw/gsw_openc3_build.sh /tmp/nos3/cfg/gsw_build.sh')
os.system('cp ./scripts/gsw/gsw_openc3_launch.sh /tmp/nos3/cfg/gsw_launch.sh')
if (gsw_cfg == 'cosmos'):
# Copy cosmos scripts into ./cfg/build
# Copy cosmos scripts into /tmp/nos3
gsw_identified = 1
os.system('cp ./scripts/gsw/gsw_cosmos_build.sh ./cfg/build/gsw_build.sh')
os.system('cp ./scripts/gsw/gsw_cosmos_launch.sh ./cfg/build/gsw_launch.sh')
os.system('cp ./scripts/gsw/gsw_cosmos_build.sh /tmp/nos3/cfg/gsw_build.sh')
os.system('cp ./scripts/gsw/gsw_cosmos_launch.sh /tmp/nos3/cfg/gsw_launch.sh')
if (gsw_cfg == 'fprime'):
# Copy fprime scripts into ./cfg/build
# Copy fprime scripts into /tmp/nos3
gsw_identified = 1
os.system('cp ./scripts/gsw/gsw_fprime_build.sh ./cfg/build/gsw_build.sh')
os.system('cp ./scripts/gsw/gsw_fprime_launch.sh ./cfg/build/gsw_launch.sh')
os.system('cp ./scripts/gsw/gsw_fprime_build.sh /tmp/nos3/cfg/gsw_build.sh')
os.system('cp ./scripts/gsw/gsw_fprime_launch.sh /tmp/nos3/cfg/gsw_launch.sh')
if (gsw_cfg == 'ait'):
# Copy ait scripts into ./cfg/build
# Copy ait scripts into /tmp/nos3
gsw_identified = 1
os.system('cp ./scripts/gsw/gsw_ait_build.sh ./cfg/build/gsw_build.sh')
os.system('cp ./scripts/gsw/gsw_ait_launch.sh ./cfg/build/gsw_launch.sh')
os.system('cp ./scripts/gsw/gsw_ait_build.sh /tmp/nos3/cfg/gsw_build.sh')
os.system('cp ./scripts/gsw/gsw_ait_launch.sh /tmp/nos3/cfg/gsw_launch.sh')
if (gsw_identified == 0):
print('Invalid GSW in configuration file!')
print('Exiting due to error...')
Expand Down Expand Up @@ -242,7 +242,7 @@
lines.insert(sc_startup_eof, cf_line)

# Write startup script file
with open('./cfg/build/nos3_defs/cpu1_cfe_es_startup.scr', 'w') as fp:
with open('/tmp/nos3/cfg/nos3_defs/cpu1_cfe_es_startup.scr', 'w') as fp:
lines = "".join(lines)
fp.write(lines)

Expand Down Expand Up @@ -273,7 +273,7 @@
lines[date_index] = mission_start_time_utc.strftime('%m %d %Y') + ' ! Date (UTC) (Month, Day, Year)\n'
lines[time_index] = mission_start_time_utc.strftime('%H %M %S') + ' ! Time (UTC) (Hr,Min,Sec)\n'

with open('./cfg/build/InOut/Inp_Sim.txt', 'w') as fp:
with open('/tmp/nos3/cfg/InOut/Inp_Sim.txt', 'w') as fp:
lines = "".join(lines)
fp.write(lines)

Expand All @@ -288,7 +288,7 @@

lines[tipoff_index] = sc_orbit_tipoff_x + ' ' + sc_orbit_tipoff_y + ' ' + sc_orbit_tipoff_z + ' ! Ang Vel (deg/sec)\n'

with open('./cfg/build/InOut/SC_NOS3.txt', 'w') as fp:
with open('/tmp/nos3/cfg/InOut/SC_NOS3.txt', 'w') as fp:
lines = "".join(lines)
fp.write(lines)

Expand Down Expand Up @@ -385,7 +385,7 @@
if (sc_thruster_en != 'true'):
lines[thruster_index] = ipc_off

with open('./cfg/build/InOut/Inp_IPC.txt', 'w') as fp:
with open('/tmp/nos3/cfg/InOut/Inp_IPC.txt', 'w') as fp:
lines = "".join(lines)
fp.write(lines)

Expand All @@ -408,7 +408,7 @@
torquer_index = 999
thruster_index = 999

with open('./cfg/build/sims/nos3-simulator.xml', 'r') as fp:
with open('/tmp/nos3/cfg/sims/nos3-simulator.xml', 'r') as fp:
lines = fp.readlines()
for line in lines:
if line.find('camsim</name>') != -1:
Expand Down Expand Up @@ -487,6 +487,6 @@
if (sc_thruster_en != 'true'):
lines[thruster_index] = sim_disabled

with open('./cfg/build/sims/nos3-simulator.xml', 'w') as fp:
with open('/tmp/nos3/cfg/sims/nos3-simulator.xml', 'w') as fp:
lines = "".join(lines)
fp.write(lines)
19 changes: 19 additions & 0 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash -i
#
# Convenience script for NOS3 development
# Use with the Dockerfile in the deployment repository
# https://github.com/nasa-itc/deployment
#

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/env.sh

# Check that NOS3 build directory exists
if [ -d $USER_NOS3_BUILD_DIR ]; then

# Cleanup all build files
$DFLAGS -v $USER_NOS3_BUILD_DIR:$USER_NOS3_BUILD_DIR --name "nos_clean" -w $BASE_DIR $DBOX rm -rf $USER_NOS3_BUILD_DIR/*

# Remove build directory
yes | rm -r $USER_NOS3_BUILD_DIR 2> /dev/null
fi
2 changes: 1 addition & 1 deletion scripts/debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/env.sh

mkdir -p $BASE_DIR/fsw/build
$DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR -v $USER_NOS3_DIR:$USER_NOS3_DIR -w $BASE_DIR --sysctl fs.mqueue.msg_max=10000 --ulimit rtprio=99 --cap-add=sys_nice --name "nos3_debug" $DBOX bash
$DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR -v $USER_NOS3_DIR:$USER_NOS3_DIR -v $USER_NOS3_BUILD_DIR:$USER_NOS3_BUILD_DIR -w $BASE_DIR --sysctl fs.mqueue.msg_max=10000 --ulimit rtprio=99 --cap-add=sys_nice --name "nos3_debug" $DBOX bash
19 changes: 11 additions & 8 deletions scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BASE_DIR=$(cd `dirname $SCRIPT_DIR` && pwd)
FSW_DIR=$BASE_DIR/fsw/build/exe/cpu1

USERDIR=$(cd ~/ && pwd)
USER_NOS3_DIR=$USERDIR/.nos3
USER_NOS3_BUILD_DIR=/tmp/nos3

FSW_DIR=$USER_NOS3_BUILD_DIR/fsw/exe/cpu1
GSW_BIN=$BASE_DIR/gsw/cosmos/build/openc3-cosmos-nos3
GSW_DIR=$BASE_DIR/gsw/cosmos
SIM_DIR=$BASE_DIR/sims/build
SIM_DIR=$USER_NOS3_BUILD_DIR/sims
SIM_BIN=$SIM_DIR/bin

if [ -d $SIM_DIR/bin ]; then
SIMS=$(ls $SIM_BIN/nos3*simulator)
fi
#if [ -d $SIM_DIR/bin ]; then
# SIMS=$(ls $SIM_BIN/nos3*simulator)
#fi

DATE=$(date "+%Y%m%d%H%M")
NUM_CPUS="$( nproc )"

USERDIR=$(cd ~/ && pwd)
USER_NOS3_DIR=$(cd ~/ && pwd)/.nos3
OPENC3_DIR=$USER_NOS3_DIR/cosmos
OPENC3_PATH=$OPENC3_DIR/openc3.sh

Expand All @@ -39,7 +42,7 @@ INFLUXDB_ADMIN_PASSWORD=admin_password
# DNETWORK="docker network"
#else
DCALL="docker"
DFLAGS="docker run --rm -it -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -u $(id -u $(stat -c '%U' $SCRIPT_DIR/env.sh)):$(getent group $(stat -c '%G' $SCRIPT_DIR/env.sh) | cut -d: -f3)"
DFLAGS="docker run --rm -it -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -u $(id -u):$(getent group $(stat -c '%G' $SCRIPT_DIR/env.sh) | cut -d: -f3)"
DFLAGS_CPUS="$DFLAGS --cpus=$NUM_CPUS"
DCREATE="docker create --rm -it"
DNETWORK="docker network"
Expand Down
12 changes: 4 additions & 8 deletions scripts/fsw/fsw_cfs_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
# https://github.com/nasa-itc/deployment
#

# Note this is copied to ./cfg/build as part of `make config`
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/../../scripts/env.sh
# Note the first argument passed is expected to be the BASE_DIR of the NOS3 repository
source $1/scripts/env.sh

# Check that local NOS3 directory exists
if [ ! -d $USER_NOS3_DIR ]; then
Expand All @@ -18,15 +17,12 @@ if [ ! -d $USER_NOS3_DIR ]; then
fi

# Check that configure build directory exists
if [ ! -d $BASE_DIR/cfg/build ]; then
if [ ! -d $USER_NOS3_BUILD_DIR/cfg ]; then
echo ""
echo " Need to run make config first!"
echo ""
exit 1
fi

# Make flight software build directory
mkdir -p $BASE_DIR/fsw/build

# Build
$DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR --name "nos_build_fsw" -w $BASE_DIR $DBOX make -j$NUM_CPUS -e FLIGHT_SOFTWARE=cfs build-fsw
$DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR -v $USER_NOS3_BUILD_DIR:$USER_NOS3_BUILD_DIR --name "nos_build_fsw" -w $BASE_DIR $DBOX make -j$NUM_CPUS -e FLIGHT_SOFTWARE=cfs build-fsw
Loading