Skip to content

Commit b8577ff

Browse files
committed
Initial commit
0 parents  commit b8577ff

File tree

14 files changed

+328
-0
lines changed

14 files changed

+328
-0
lines changed

CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cmake_minimum_required(VERSION "3.12")
2+
3+
project("spackexample" VERSION 0.3.0)
4+
5+
find_package(Boost
6+
1.65.1
7+
REQUIRED
8+
filesystem
9+
)
10+
11+
find_package(yaml-cpp
12+
0.7.0
13+
REQUIRED
14+
)
15+
16+
add_library(spackexamplelib filesystem/filesystem.cpp flatset/flatset.cpp yamlParser/yamlParser.cpp)
17+
18+
set_target_properties(spackexamplelib
19+
PROPERTIES
20+
PUBLIC_HEADER filesystem/filesystem.hpp
21+
PUBLIC_HEADER flatset/flatset.hpp
22+
PUBLIC_HEADER yamlParser/yamlParser.hpp
23+
)
24+
25+
include_directories(${YAML_CPP_INCLUDE_DIR})
26+
27+
add_executable(spackexample main.cpp)
28+
target_link_libraries(spackexample spackexamplelib)
29+
target_link_libraries(spackexamplelib Boost::filesystem yaml-cpp)
30+
31+
target_include_directories(spackexamplelib
32+
PRIVATE
33+
${CMAKE_CURRENT_SOURCE_DIR}/spackexamplelib
34+
PUBLIC
35+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/spackexamplelib>
36+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/spackexamplelib>
37+
)
38+
39+
# Create install targets
40+
include(GNUInstallDirs)
41+
install(TARGETS spackexample spackexamplelib
42+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
43+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
44+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
45+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spackexample
46+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spackexample
47+
)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Simulation-Software-Engineering
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Packaging with Spack
2+
3+
Repository for the [Spack exercise](https://github.com/Simulation-Software-Engineering/Lecture-Material/blob/main/03_building_and_packaging/spack_exercise.md). The code is a slightly modified version of the [code used in the CMake exercise](https://github.com/Simulation-Software-Engineering/cmake-exercise-wt2425).
4+
5+
The directory `docker/` contains the recipe of the Docker image that has been prepared for the exercise. Build a Docker image from the recipe and start a container from this image.

docker/Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM ubuntu:20.04
2+
3+
ENV DEBIAN_FRONTEND noninteractive
4+
5+
RUN apt-get update && apt-get install -y apt-utils vim tmux htop git curl wget cmake build-essential sudo python3 python-is-python3 pkg-config python3-openssl bash gzip file openssl gnupg nano
6+
RUN apt-get install -y libboost-filesystem-dev libboost-container-dev
7+
8+
# Cleanup
9+
RUN apt-get clean
10+
RUN rm -rf /tmp/*
11+
12+
# Create user
13+
ARG USER_NAME=spackbuilder
14+
ARG USER_HOME=/home/${USER_NAME}
15+
#ARG USER_ID=1000
16+
ARG USER_ID=1000
17+
ARG GROUP_ID=1000
18+
19+
RUN groupadd -g $GROUP_ID "$USER_NAME"
20+
RUN adduser \
21+
--home "$USER_HOME" \
22+
--uid $USER_ID \
23+
--gid $GROUP_ID \
24+
--disabled-password \
25+
"$USER_NAME"
26+
27+
RUN echo "$USER_NAME" ALL=\(root\) NOPASSWD:ALL > "/etc/sudoers.d/$USER_NAME" && \
28+
chmod 0440 "/etc/sudoers.d/$USER_NAME"
29+
30+
USER "$USER_NAME"
31+
WORKDIR "$USER_HOME"
32+
33+
ENV USER "$USER_NAME"
34+
ENV LD_LIBRARY_PATH /usr/local/lib:"${LD_LIBRARY_PATH}"
35+
36+
# Set up Spack
37+
COPY spack-config ${USER_HOME}/.spack
38+
RUN git clone -b releases/v0.19 https://github.com/spack/spack.git spack && echo ". ${USER_HOME}/spack/share/spack/setup-env.sh" >> ${USER_HOME}/.bashrc
39+
RUN sudo chown -R $USER_NAME:$USER_NAME .spack && . ${USER_HOME}/spack/share/spack/setup-env.sh && spack spec yaml-cpp
40+
# Bootstrap clingo
41+
#COPY bootstrap-spack.sh ${USER_HOME}/bootstrap-spack.sh
42+
#RUN su - $USER_NAME -c ./${USER_HOME}/bootstrap-spack.sh && rm bootstrap-spack.sh
43+
44+
CMD ["bash"]
45+
46+
# Reset frontend for interactive use
47+
ENV DEBIAN_FRONTEND=
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
compilers:
2+
- compiler:
3+
spec: gcc@9.3.0
4+
paths:
5+
cc: /usr/bin/gcc
6+
cxx: /usr/bin/g++
7+
f77: null
8+
fc: null
9+
flags: {}
10+
operating_system: ubuntu20.04
11+
target: x86_64
12+
modules: []
13+
environment: {}
14+
extra_rpaths: []

docker/spack-config/packages.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
packages:
2+
bash:
3+
externals:
4+
- spec: bash@5.0.17
5+
prefix: /usr
6+
boost:
7+
externals:
8+
- spec: boost@1.71.0~atomic~chrono~date_time~exception~graph~iostreams~locale~log~math~multithreaded~program_options~random~regex~serialization~signals~system~test~thread~timer~wave
9+
prefix: /usr
10+
bzip2:
11+
externals:
12+
- spec: bzip2@1.0.8
13+
prefix: /usr
14+
cmake:
15+
externals:
16+
- spec: cmake@3.16.3
17+
prefix: /usr
18+
diffutils:
19+
externals:
20+
- spec: diffutils@3.7
21+
prefix: /usr
22+
file:
23+
externals:
24+
- spec: file@5.38
25+
prefix: /usr
26+
findutils:
27+
externals:
28+
- spec: findutils@4.7.0
29+
prefix: /usr
30+
gcc:
31+
externals:
32+
- spec: gcc@9.3.0 languages=c,c++
33+
prefix: /usr
34+
extra_attributes:
35+
compilers:
36+
c: /usr/bin/x86_64-linux-gnu-gcc-9
37+
cxx: /usr/bin/x86_64-linux-gnu-g++-9
38+
git:
39+
externals:
40+
- spec: git@2.25.1~tcltk
41+
prefix: /usr
42+
gmake:
43+
externals:
44+
- spec: gmake@4.2.1
45+
prefix: /usr
46+
openssh:
47+
externals:
48+
- spec: openssh@8.2p1
49+
prefix: /usr
50+
openssl:
51+
externals:
52+
- spec: openssl@1.1.1f
53+
prefix: /usr
54+
perl:
55+
externals:
56+
- spec: perl@5.30.0~cpanm+shared+threads
57+
prefix: /usr
58+
pkg-config:
59+
externals:
60+
- spec: pkg-config@0.29.1
61+
prefix: /usr
62+
python:
63+
externals:
64+
- spec: python@3.8.10+bz2+ctypes+dbm+lzma+nis+pyexpat+readline+sqlite3+ssl~tix~tkinter+uuid+zlib
65+
prefix: /usr
66+
sed:
67+
externals:
68+
- spec: sed@4.7
69+
prefix: /usr
70+
tar:
71+
externals:
72+
- spec: tar@1.30
73+
prefix: /usr
74+
xz:
75+
externals:
76+
- spec: xz@5.2.4
77+
prefix: /usr

filesystem/filesystem.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "filesystem.hpp"
2+
#include <iostream>
3+
#include <vector>
4+
#include <algorithm>
5+
#include <boost/filesystem.hpp>
6+
using namespace boost::filesystem;
7+
8+
void inspectDirectory()
9+
{
10+
11+
path p (".");
12+
13+
try
14+
{
15+
if (exists(p))
16+
{
17+
if (is_regular_file(p))
18+
std::cout << p << " size is " << file_size(p) << '\n';
19+
20+
else if (is_directory(p))
21+
{
22+
std::cout << p << " is a directory containing:\n";
23+
24+
std::vector<path> v;
25+
26+
for (auto&& x : directory_iterator(p))
27+
v.push_back(x.path());
28+
29+
std::sort(v.begin(), v.end());
30+
31+
for (auto&& x : v)
32+
std::cout << " " << x.filename() << '\n';
33+
}
34+
else
35+
std::cout << p << " exists, but is not a regular file or directory\n";
36+
}
37+
else
38+
std::cout << p << " does not exist\n";
39+
}
40+
41+
catch (const filesystem_error& ex)
42+
{
43+
std::cout << ex.what() << '\n';
44+
}
45+
46+
}

filesystem/filesystem.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
void inspectDirectory();

flatset/flatset.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "flatset.hpp"
2+
#include <iostream>
3+
#include <boost/container/flat_set.hpp>
4+
5+
void modifyAndPrintSets() {
6+
//Different ways of initializing the flat_set container
7+
boost::container::flat_set<int> s1;
8+
9+
//Inserting values into s1
10+
s1.insert(3);
11+
s1.insert(1);
12+
s1.insert(2);
13+
s1.insert(4);
14+
15+
s1.insert(4); //Eventhough 4 is inserted multiple times only one is considered
16+
17+
std::cout << "Elements in s1: ";
18+
for(int i:s1)
19+
std::cout<<i<<" ";
20+
std::cout<<std::endl;
21+
}
22+

flatset/flatset.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
void modifyAndPrintSets();

0 commit comments

Comments
 (0)