Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier authored Mar 21, 2024
0 parents commit 85a79f2
Show file tree
Hide file tree
Showing 35 changed files with 1,882 additions and 0 deletions.
111 changes: 111 additions & 0 deletions .github/initial-setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import os
import shutil
import re
import sys
import json


def replace_in_file(filename, mapping):
print('==> Editing '+filename)
infile = open(filename)
outfile = open(filename+'.tmp', 'w+')
for line in infile:
for k, v in mapping.items():
line = line.replace(k, v)
outfile.write(line)
infile.close()
outfile.close()
shutil.copyfile(filename+'.tmp', filename)
os.remove(filename+'.tmp')
os.system(f'git add {filename}')

def list_files_to_edit(root, extensions,
exclude_directories=[],
exclude_files=[]):
result = []
for dirname, dirnames, filenames in os.walk(root):
for filename in filenames:
if filename in exclude_files:
continue
for ext in extensions:
if filename.endswith(ext):
result.append(os.path.join(dirname, filename))
break
for d in exclude_directories:
if d in dirnames:
dirnames.remove(d)
return result

def rename_files_and_directories(root, extensions,
mapping,
exclude_directories=[],
exclude_files=[]):
for dirname, dirnames, filenames in os.walk(root):
# exclude directories
for d in exclude_directories:
if d in dirnames:
dirnames.remove(d)
# rename folders
names_to_changes = {}
for subdirname in dirnames:
new_name = subdirname
for k, v in mapping.items():
new_name = new_name.replace(k, v)
if new_name != subdirname:
print("==> Renaming "+os.path.join(dirname, subdirname)+" into "+os.path.join(dirname, new_name))
os.system(f'git mv {os.path.join(dirname, subdirname)} {os.path.join(dirname, new_name)}')
#shutil.move(os.path.join(dirname, subdirname),
# os.path.join(dirname, new_name))
dirnames.remove(subdirname)
dirnames.append(new_name)
# rename files
for filename in filenames:
if filename in exclude_files:
continue
for ext in extensions:
if filename.endswith(ext):
new_name = filename
for k, v in mapping.items():
new_name = new_name.replace(k, v)
if new_name != filename:
print("==> Renaming "+os.path.join(dirname, filename)+" into "+os.path.join(dirname, new_name))
os.system(f'git mv {os.path.join(dirname, filename)} {os.path.join(dirname, new_name)}')
#os.rename(os.path.join(dirname, filename),
# os.path.join(dirname, new_name))
break # don't try the next extension for this file


if __name__ == '__main__':
with open('initial-setup.json') as f:
info = json.loads(f.read())
service_name = info['service_name']
if(not re.match('[a-zA-Z_][a-zA-Z\d_]*', service_name)):
print("Error: service name must start with a letter and consist of letters, digits, or underscores")
sys.exit(-1)
resource_name = info['resource_name']
if(not re.match('[a-zA-Z_][a-zA-Z\d_]*', resource_name)):
print("Error: resource name must start with a letter and consist of letters, digits, or underscores")
sys.exit(-1)
mapping = {
'alpha' : service_name,
'ALPHA' : service_name.upper(),
'resource' : resource_name,
'RESOURCE' : resource_name.upper()
}
files_to_edit = list_files_to_edit('.',
extensions=['.c', '.cpp', '.h', '.txt', '.in', '.json'],
exclude_directories=['.git', '.github', 'build', '.spack-env'],
exclude_files=['uthash.h', 'initial-setup.json'])
for f in files_to_edit:
replace_in_file(f, mapping)
rename_files_and_directories('.',
extensions=['.c', '.cpp', '.h', '.txt', '.in', '.json'],
mapping=mapping,
exclude_directories=['.git', '.github', 'build', '.spack-env'],
exclude_files=['uthash.h', 'initial-setup.json'])
os.system('git rm .github/initial-setup.py')
os.system('git rm initial-setup.json')
os.system('git rm .github/workflows/setup.yml')
os.system('git rm COPYRIGHT')
with open('README.md', 'w+') as f:
f.write(f'Your project "{service_name}" has been setup!\n Enjoy programming with Mochi!')
55 changes: 55 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Code coverage

on:
workflow_dispatch: {}
push:
branches:
- main
pull_request:
branches:
- main

jobs:
codecov:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup spack
uses: spack/setup-spack@v2.1.1
with:
ref: develop

- name: Add mochi-spack-packages
run: |
git clone https://github.com/mochi-hpc/mochi-spack-packages
spack -e tests repo add mochi-spack-packages
- name: Install spack environment
run: |
spack -e tests install
- name: Show spack-installed packages for debugging
run: |
spack -e tests find -dlv
- name: Build code and run unit tests
run: |
eval `spack env activate --sh tests`
mkdir build
cd build
cmake .. -DENABLE_COVERAGE=ON \
-DENABLE_TESTS=ON \
-DENABLE_EXAMPLES=ON \
-DENABLE_BEDROCK=ON \
-DCMAKE_BUILD_TYPE=Debug
make
make test
- name: Send coverage report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true
gcov: true
32 changes: 32 additions & 0 deletions .github/workflows/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
paths:
- initial-setup.json
branches:
- main

name: Initial project setup

jobs:
setup:
if: ${{ !contains (github.repository, '/margo-microservice-template') }}
name: Initial project setup
runs-on: ubuntu-latest
steps:
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Setup from initial-setup.py
run: |
python3 "${GITHUB_WORKSPACE}/.github/initial-setup.py"
- uses: stefanzweifel/git-auto-commit-action@v5.0.0
with:
commit_message: Initial project setup from template
64 changes: 64 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Unit tests

on:
workflow_dispatch: {}
push:
branches:
- main
pull_request:
branches:
- main

jobs:
tests:
runs-on: ubuntu-22.04
### Uncomment these two lines to push dependencies into the build cache
# permissions:
# packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup spack
uses: spack/setup-spack@v2.1.1
with:
ref: develop

- name: Add mochi-spack-packages
run: |
git clone https://github.com/mochi-hpc/mochi-spack-packages
spack -e tests repo add mochi-spack-packages
- name: Install spack environment
run: |
spack -e tests install
- name: Show spack-installed packages for debugging
run: |
spack -e tests find -dlv
- name: Build code and run unit tests
run: |
eval `spack env activate --sh tests`
mkdir build
cd build
cmake .. -DENABLE_COVERAGE=OFF \
-DENABLE_TESTS=ON \
-DENABLE_EXAMPLES=ON \
-DENABLE_BEDROCK=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo
make
make test
# Uncomment the step bellow to push the dependencies into the build cache
# Note: to be able to push the specs to the build cache,
# The repository should have Write access here:
# https://github.com/orgs/mochi-hpc/packages/container/mochi-spack-buildcache/settings
# - name: Push packages to buildcache and update index
# if: ${{ !cancelled() }}
# run: |
# spack -e tests mirror set --push \
# --oci-username ${{ github.actor }} \
# --oci-password "${{ secrets.GITHUB_TOKEN }}" mochi-buildcache
# spack -e tests buildcache push --base-image ubuntu:22.04 \
# --unsigned --update-index mochi-buildcache
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/
/.spack-env/
/spack.lock
82 changes: 82 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# (C) 2020 The University of Chicago
# See COPYRIGHT in top-level directory.
cmake_minimum_required (VERSION 3.8)
project (alpha C CXX)
enable_testing ()

add_definitions (-Wextra -Wall -Wpedantic)

add_library (coverage_config INTERFACE)

option (ENABLE_TESTS "Build tests" OFF)
option (ENABLE_EXAMPLES "Build examples" OFF)
option (ENABLE_BEDROCK "Build bedrock module" OFF)
option (ENABLE_COVERAGE "Build with coverage" OFF)

# add our cmake module directory to the path
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# link shared lib with full rpath
set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# setup cache variables for ccmake
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release
CACHE STRING "Choose the type of build." FORCE)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "RelWithDebInfo" "MinSizeRel")
endif ()
set (CMAKE_PREFIX_PATH "" CACHE STRING "External dependencies path")
set (BUILD_SHARED_LIBS "ON" CACHE BOOL "Build a shared library")

if (ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options (coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options (coverage_config INTERFACE --coverage)
else ()
target_link_libraries (coverage_config INTERFACE --coverage)
endif ()
endif ()

find_package (PkgConfig REQUIRED)

if (${ENABLE_BEDROCK})
find_package (bedrock REQUIRED)
endif ()

# search for margo
pkg_check_modules (margo REQUIRED IMPORTED_TARGET margo)
# search for json-c
pkg_check_modules (json-c REQUIRED IMPORTED_TARGET json-c)

# library version set here (e.g. for shared libs).
set (ALPHA_VERSION_MAJOR 0)
set (ALPHA_VERSION_MINOR 1)
set (ALPHA_VERSION_PATCH 0)
set (ALPHA_VERSION
"${ALPHA_VERSION_MAJOR}.${ALPHA_VERSION_MINOR}.${ALPHA_VERSION_PATCH}")

add_subdirectory (src)
if (${ENABLE_TESTS})
enable_testing ()
find_package (Catch2 3.0.1 QUIET)
if (NOT Catch2_FOUND)
include (FetchContent)
FetchContent_Declare (
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.0.1
)
FetchContent_MakeAvailable (Catch2)
endif ()
add_subdirectory (tests)
endif (${ENABLE_TESTS})
if (${ENABLE_EXAMPLES})
add_subdirectory (examples)
endif (${ENABLE_EXAMPLES})
38 changes: 38 additions & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Copyright (c) 2020, UChicago Argonne, LLC
All Rights Reserved
SDS TOOLS (ANL-SF-16-009)

OPEN SOURCE LICENSE

Under the terms of Contract No. DE-AC02-06CH11357 with UChicago Argonne,
LLC, the U.S. Government retains certain rights in this software.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the names of UChicago Argonne, LLC or the Department of
Energy nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior
written permission.

******************************************************************************
DISCLAIMER

THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND.

NEITHER THE UNTED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT
OF ENERGY, NOR UCHICAGO ARGONNE, LLC, NOR ANY OF THEIR EMPLOYEES,
MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY
OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY
INFORMATION, DATA, APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS
THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.

******************************************************************************
Loading

0 comments on commit 85a79f2

Please sign in to comment.