Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jakub.both/dune-common
  • samuel.burbulla/dune-common
  • patrick.jaap/dune-common
  • tobias.leibner/dune-common
  • alexander.mueller/dune-common
  • pipping/dune-common
  • Xinyun.Li/dune-common
  • felix.schindler/dune-common
  • simon.praetorius/dune-common
  • ani.anciaux-sedrakian/dune-common
  • henrik.stolzmann/dune-common
  • matthew.t.collins/dune-common
  • liam.keegan/dune-common
  • felix.mueller/dune-common
  • ansgar/dune-common
  • dominic/dune-common
  • lars.lubkoll/dune-common
  • exadune/dune-common
  • felix.gruber/dune-common
  • govind.sahai/dune-common
  • michael.sghaier/dune-common
  • core/dune-common
  • kilian.weishaupt/dune-common
  • markus.blatt/dune-common
  • joscha.podlesny/dune-common
  • tobias.meyer.andersen/dune-common
  • andreas.thune/dune-common
  • lars.bilke/dune-common
  • daniel.kienle/dune-common
  • lukas.renelt/dune-common
  • smuething/dune-common
  • stephan.hilb/dune-common
  • tkoch/dune-common
  • nils.dreier/dune-common
  • rene.milk/dune-common
  • lasse.hinrichsen/dune-common
  • yunus.sevinchan/dune-common
  • lisa_julia.nebel/dune-common
  • claus-justus.heine/dune-common
  • lorenzo.cerrone/dune-common
  • eduardo.bueno/dune-common
41 results
Show changes
Preparing the SVN-sources
=========================
Additional to the software mentioned in README you'll need the
following programs installed on your system:
automake >= 1.5
autoconf >= 2.50
libtool
For the documentation to build you'll need doxygen, wml, convert and latex
installed.
Dune also features a self-test. As some grid-components (e.g. Albert,
UG) depend on external libraries their self-tests will only run if
those libraries are found. The pathes would then need to be passed via
--with-...= parameters.
Important! If you don't want to develop Dune itself you won't need to
provide external components! The Dune-library and -headers are
independent of other libraries, instead the applications can choose
what parts to use.
$Id$
<!--
SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
-->
DUNE-library
============
DUNE, the Distributed and Unified Numerics Environment is a modular toolbox
for solving partial differential equations with grid-based methods.
The main intention is to create slim interfaces allowing an efficient use of
legacy and/or new libraries. Using C++ techniques DUNE allows one to use very
different implementation of the same concept (i.e. grid, solver, ...) under
a common interface with a very low overhead.
DUNE was designed with flexibility in mind. It supports easy discretization
using methods, like Finite Elements, Finite Volume and also Finite
Differences. Through separation of data structures DUNE allows fast Linear
Algebra like provided in the ISTL module, or usage of external libraries
like BLAS.
This package contains the basic DUNE common classes.
Dependencies
------------
dune-common depends on the following software packages
- CMake >= 3.16
- Compiler (C, C++): GNU >= 10 or Clang >= 13
- Library: GNU libstdc++ >= 10 or Clang libc++ >= 13
Other compilers may also work, but they must support C++20 to the same extent as
the above. For an overview of the C++20 features supported by these versions, see
https://en.cppreference.com/w/cpp/compiler_support. For compiling the Python
bindings, libc++ is not currently supported.
The following software is recommended but optional:
- pkg-config
- MPI (either OpenMPI, lam, or mpich suffice)
- Python >= 3.7 (interpreter and development kit for building the python bindings)
For a full explanation of the DUNE installation process please read
the [installation notes][installation]. The following introduction is meant for
the impatient.
License
-------
The DUNE-library and headers are licensed under version 2 of the GNU
General Public License, with the so-called "runtime exception", as
follows:
> As a special exception, you may use the DUNE source files as part
> of a software library or application without restriction.
> Specifically, if other files instantiate templates or use macros or
> inline functions from one or more of the DUNE source files, or you
> compile one or more of the DUNE source files and link them with
> other files to produce an executable, this does not by itself cause
> the resulting executable to be covered by the GNU General Public
> License. This exception does not however invalidate any other
> reasons why the executable file might be covered by the GNU General
> Public License.
This license clones the one of the libstdc++ library. For further
implications of this library please see their [license page][license]
See the file COPYING for full copying permissions.
Installation
------------
Short installation instructions can be found in file INSTALL. For the
full instructions please see [here][installation].
Links
-----
0. https://www.dune-project.org/installation/installation-faq/
1. https://dune-project.org/releases/
2. https://dune-project.org/doc/buildsystem/
3. https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.license
[installation]: https://www.dune-project.org/installation/installation-buildsrc
[license]: https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.license
- nach perl und makedepend suchen (für undefAllMacros.pl)
- doxygen configuration files
- Installation doku in docs
- operator schnittstelle erweitern, damit man mehr Informationen
übergeben kann
Makefile
Makefile.in
semantic.cache
\ No newline at end of file
# $Id$
EXTRA_DIST = inkscape.am webstuff global-rules sourcescheck \
no-check-without-lib latex checklog update-libs
#noinst_DATA = inkscape.am
amdir = $(datadir)/dune-common/am
am_DATA = $(EXTRA_DIST)
include $(top_srcdir)/am/global-rules
# -*- Makefile -*-
# $Id$
LOG_FILE = $(top_srcdir)/check-log.log
LOG_DIR = $(top_srcdir)/check-log
LOG_STORE = $(SHELL) $(DUNE_COMMON_ROOT)/bin/check-log-store $(LOG_FILE) $(LOG_DIR)
LOG_SET_OPTIONS = \
path=$$(test "$(subdir)" = "." && \
echo "/@PACKAGE_NAME@"|| echo "/@PACKAGE_NAME@/$(subdir)"); \
ppath=$$(dirname $$path); \
dir=$$(basename $$path)
$(DUNE_COMMON_ROOT)/bin/check-log-store: $(DUNE_COMMON_ROOT)/bin/check-log-store.in
cd $(DUNE_COMMON_ROOT)/bin/ && $(MAKE) check-log-store
check-log: $(DUNE_COMMON_ROOT)/bin/check-log-store
check-log:
rm -f $(LOG_FILE)
check-log: check-log-libs
check-log: check-log-build
check-log: check-log-test
check-log: check-log-sources
check-log: check-log-dir
check-log-libs: check-log-libs-recursive
check-log-build: check-log-build-recursive
check-log-test: check-log-test-recursive
check-log-sources: check-log-sources-recursive
check-log-dir: check-log-dir-recursive
check-log-sources-am:
$(LOG_SET_OPTIONS); \
$(MAKE) sourcescheck-am > $(LOG_FILE) 2>&1; \
$(LOG_STORE) "sources" "Makefile.am" "$$path"
check-log-libs-am:
$(LOG_SET_OPTIONS); \
for lib in $(LTLIBRARIES); do \
$(MAKE) $$lib > $(LOG_FILE) 2>&1; \
$(LOG_STORE) "lib" "$$lib" "$$path"; \
done;
check-log-build-am:
$(LOG_SET_OPTIONS); \
for target in $(check_PROGRAMS) $(PROGRAMS); do \
$(MAKE) $$target > $(LOG_FILE) 2>&1; \
$(LOG_STORE) "build" "$$target" "$$path"; \
done;
check-log-test-am:
@LOG () { \
echo "$$1" > $(LOG_FILE).2; \
cat $(LOG_FILE) >> $(LOG_FILE).2; \
mv $(LOG_FILE).2 $(LOG_FILE); \
}; \
$(LOG_SET_OPTIONS); \
for tst in $(TESTS); do \
if test -f ./$$tst; then dir=./; \
elif test -f $$tst; then dir=; \
else dir="$(srcdir)/"; fi; \
if $(TESTS_ENVIRONMENT) $${dir}$$tst > $(LOG_FILE) 2>&1; then \
case " $(XFAIL_TESTS) " in \
*" $$tst "*) \
LOG "ERROR: XPASS ($$tst)"; \
$(LOG_STORE) "run" "$$tst" "$$path" 1 0; \
;; \
*) \
LOG "SUCCESS: PASS ($$tst)"; \
$(LOG_STORE) "run" "$$tst" "$$path" 0 0; \
;; \
esac; \
elif test $$? -ne 77; then \
case " $(XFAIL_TESTS) " in \
*" $$tst "*) \
LOG "SUCCESS: XFAIL ($$tst)"; \
$(LOG_STORE) "run" "$$tst" "$$path" 0 0; \
;; \
*) \
LOG "ERROR: FAIL ($$tst)"; \
$(LOG_STORE) "run" "$$tst" "$$path" 1 0; \
;; \
esac; \
else \
LOG "WARNING: SKIP ($$tst)"; \
$(LOG_STORE) "run" "$$tst" "$$path" 0 1; \
fi; \
done;
check-log-dir-am:
$(LOG_SET_OPTIONS); \
$(LOG_STORE) "dir" "$$dir" "$$ppath"
check-log-libs-recursive \
check-log-build-recursive \
check-log-test-recursive \
check-log-sources-recursive \
check-log-dir-recursive:
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
.PHONY: check-log \
check-log-lib check-log-lib-am check-log-lib-recursive \
check-log-build check-log-build-am check-log-build-recursive \
check-log-test check-log-test-am check-log-test-recursive \
check-log-sources check-log-sources-am check-log-sources-recursive \
check-log-dir check-log-dir-am check-log-dir-recursive
# -*- Makefile -*-
# $Id$
#
# this file should be included into any Makefile.am so that we can
# easily introduce new global rules. DO NOT OVERUSE!
#
# add "sourcescheck"-target testing if all source files are mentioned
include $(top_srcdir)/am/sourcescheck
# add "check-log"-target to create automated build logs
include $(top_srcdir)/am/checklog
# automaticly update libs
include $(top_srcdir)/am/update-libs
if INKSCAPE
.svg.png:
$(INKSCAPE) -e $@ $<
endif INKSCAPE
# Rules for latex stuff
# rerun TEX if log-file suggests that
.tex.dvi:
set -e; \
TEXINPUTS=.:$(srcdir):${TEXINPUTS}: $(TEX) </dev/null $*; \
while grep Rerun $*.log > /dev/null ; do \
TEXINPUTS=.:$(srcdir):${TEXINPUTS}: $(TEX) </dev/null $* || exit $$?; \
done; \
if grep '^\\bibdata{' *.aux > /dev/null \
&& grep '^\\citation{' *.aux > /dev/null; \
then \
BSTINPUTS=.:$(srcdir):${BSTINPUTS}: BIBINPUTS=.:$(srcdir):${BIBINPUTS}: $(BIBTEX) $* || exit $$?; \
TEXINPUTS=.:$(srcdir):${TEXINPUTS}: $(TEX) </dev/null $* || exit $$?; \
while grep Rerun $*.log > /dev/null ; do \
TEXINPUTS=.:$(srcdir):${TEXINPUTS}: $(TEX) </dev/null $* || exit $$?; \
done ; \
fi
.dvi.pdf:
TEXINPUTS=.:$(srcdir):${TEXINPUTS}: $(DVIPDF) $*
.dvi.ps:
TEXINPUTS=.:$(srcdir):${TEXINPUTS}: $(DVIPS) $* -o
# -*- Makefile -*-
# $Id$
# many tests need parts of libdune. Telling the tests to use
# previously build partial libs is possible but difficult to maintain:
# the SUBDIRS have to be very carefully defined for this to work...
# Additionally, testing with a partial lib is unrealistic.
#
# As users may try to use "make check" without a full build we
# generate a meaningful error message instead of silently failing on a
# lib-dependency
# add a new dependency to automake-internal rule
check-am: libcheck
libcheck: libcheck-FORCE
@if test ! -f $(top_builddir)/lib/libdune.la ; then \
echo ; \
echo ' libdune not built, checks will not work yet!' ; \
echo ' Run a full make to fix this' ; \
echo ; \
exit 1; \
fi
libcheck-FORCE:
.PHONY: libcheck libcheck-FORCE
# -*- Makefile -*-
# $Id$
sourcescheck_LIST = $(SOURCES) $(DIST_SOURCES) $(HEADERS) $(DIST_HEADERS) \
$(sourcescheck_NOSOURCES) $(dist_noinst_DATA)
sourcescheck: sourcescheck-recursive
# @(for f in $(sourcescheck_LIST) fnord; do echo $$f; done) | \
# grep '\.[hc][hc]$$' | sort | uniq > header_CHECK.install
sourcescheck-am:
@echo $(sourcescheck_LIST) | tr ' ' '\n' | \
grep '\.[hc][hc]$$' | sort | uniq > header_CHECK.install
@ls | \
grep '\.[hc][hc]$$' | sort | uniq > header_CHECK.present
@RESULT=0; \
if diff header_CHECK.* | grep ^[\<\>] -q; then \
echo "==== WARNING ===="; \
echo -n "Directory: "; pwd; \
echo "Files present but not installed:"; \
diff -u header_CHECK.install header_CHECK.present | \
grep -v ^+++ | grep ^+; \
echo "Files listed for install but not present:"; \
diff -u header_CHECK.install header_CHECK.present | \
grep -v ^--- | grep ^-; \
echo "==== END ===="; \
RESULT=1; \
fi; \
rm -f header_CHECK.install header_CHECK.present; \
exit $$RESULT
sourcescheck-recursive:
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
.PHONY: sourcescheck sourcescheck-recursive
# -*- Makefile -*-
# $Id$
#
# -- update libs in an other directory --
#
# applications linking against local libraries should also depend on these libs
#
# app_SOURCE = app.cc
# app_LDADD = $(LOCAL_LIBS)
# app_DEPENDENCIES = $(LOCAL_LIBS)
#
# instead, you can also write
#
# app_SOURCE = app.cc
# app_LIBADD = $(LOCAL_LIBS)
#
LOCAL_LIBS = @LOCAL_LIBS@
%.la: MAKELIBS.force
cd $$(dirname $@) && $(MAKE) $$(basename $@)
MAKELIBS.force:
.PHONY: MAKELIBS.force
# -*- makefile -*-
# $Id$
## rules to create HTML-pages from wml-files with additional magic to
## possibly use the layout of the Dune-homepage
# if DUNEWEBDIR is set to the dune-web directory the layout and
# install-stuff from that place will be used
# CURDIR should be defined in the same way as in dune-web
# pass files through wrapper
# pass variables to wmlwrap via environment
.wml.html:
export DUNEWEBDIR=$(DUNEWEBDIR); \
export BASEDIR=$(BASEDIR); \
sh $(DUNE_COMMON_ROOT)/bin/wmlwrap -I $(srcdir) $< -o $@
web-install: all
if test -d $(DUNEWEBDIR) && test -r $(DUNEWEBDIR)/Make.global ; then \
for DIR in $(SUBDIRS) ; do \
$(MAKE) -C $$DIR web-install || exit 1; \
done ; \
$(MAKE) -f $(DUNEWEBDIR)/Make.global \
EXTRAINSTALL="$(EXTRAINSTALL)" CURDIR="$(CURDIR)" install ; \
fi
#!/bin/sh
# $Id$
# barf on errors
set -e
usage () {
echo "Usage: ./autogen.sh [options]"
echo " --ac=, --acversion=VERSION use a specific VERSION of autoconf"
echo " --am=, --amversion=VERSION use a specific VERSION of automake"
echo " -h, --help you already found this :-)"
}
for OPT in "$@"; do
set +e
# stolen from configure...
# when no option is set, this returns an error code
arg=`expr "x$OPT" : 'x[^=]*=\(.*\)'`
set -e
case "$OPT" in
--ac=*|--acversion=*)
if test "x$arg" = "x"; then
usage;
exit 1;
fi
ACVERSION=$arg
;;
--am=*|--amversion=*)
if test "x$arg" = "x"; then
usage;
exit 1;
fi
AMVERSION=$arg
;;
-h|--help) usage ; exit 0 ;;
*)
if test -d "$OPT/m4"; then
ACLOCAL_FLAGS="$ACLOCAL_FLAGS -I $OPT/m4"
fi
if test -d "$OPT/am"; then
am_dir="$OPT/am"
fi
;;
esac
done
## report parameters
if test "x$ACVERSION" != "x"; then
echo "Forcing autoconf version $ACVERSION"
if ! which autoconf$ACVERSION > /dev/null; then
echo
echo "Error: Could not find autoconf$ACVERSION"
echo " Did you specify a wrong version?"
exit 1
fi
fi
if test "x$AMVERSION" != "x"; then
echo "Forcing automake version $AMVERSION"
if ! which automake$AMVERSION > /dev/null; then
echo
echo "Error: Could not find automake$AMVERSION"
echo " Did you specify a wrong version?"
exit 1
fi
fi
## run autotools
echo "--> libtoolize..."
# this script won't rewrite the files if they already exist. This is a
# PITA when you want to upgrade libtool, thus I'm setting --force
libtoolize --force
# prepare everything
echo "--> aclocal..."
aclocal$AMVERSION -I m4
# applications should provide a config.h for now
echo "--> autoheader..."
autoheader$ACVERSION
echo "--> automake..."
automake$AMVERSION --add-missing
echo "--> autoconf..."
autoconf$ACVERSION
## tell the user what to do next
echo "Now run ./configure to setup dune-common"
Makefile
Makefile.in
.deps
semantic.cache
check-log-store
wmlwrap
\ No newline at end of file
# SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
install(PROGRAMS
dune-add-spdx
dune-ctest
duneproject
dunecontrol
dunepackaging.py
dune-git-whitespace-hook
DESTINATION ${CMAKE_INSTALL_BINDIR})
# $Id$
# put scripts into dist-tarball
EXTRA_DIST = duneproject wmlwrap dunecontrol \
dunemodules.inc mpi-config
# ... and install some
bin_SCRIPTS = duneproject dunemodules.inc dunecontrol mpi-config
include $(top_srcdir)/am/global-rules
#!/bin/bash
#
# patch the include statement into all Makefile.am files
#
set -e
# always start in $top_srcdir
if ! test -f configure.ac; then
echo "Wrong Directory"
echo "run from \$top_srcdir"
exit 1
fi
# list of files to patch
FILES=`find . -name Makefile.am`
# snippet to patch into Makefile.am
SNIP='include $(top_srcdir)/am/sourcescheck'
# create the grep regexp from the snip
REGEXP="^$(echo $SNIP | sed -e 's/[\$\/\(\)]/./g')\$"
# enable / disable verbose mode
VERBOSE=0
for f in $FILES; do
# only patch files that don't have the patch yet
if ! grep -q "$REGEXP" $f; then
echo patching $f
# normalize end of file
while test "$(tail -1 $f)" != ""; do
echo >> $f
done
echo $SNIP >> $f
else
if test x$VERBOSE = x1; then
echo $f already patched
fi
fi
done
#!/bin/sh
set -e
# DB format
#
# <tag> <revision> <host> <mode> <module> <path> <errors> <warnings> <log>
# parameter:
# $(LOG_FILE) $(LOG_DIR) "build" "$$target" "$$path"
host="@host@"
tag="@tag@"
revision="@revision@"
logfile="$1"
logdir="$2"
mode="$3"
module="$4"
path="$5"
errors="$6"
warnings="$7"
test -d $logdir || mkdir $logdir
storelog=`tempfile -d $logdir`
trap "rm -f $storelog" EXIT
if true; then
echo "TAG: $tag"
echo "REVISION: $revision"
echo "HOST: $host"
echo "MODE: $mode"
echo "MODULE: $module"
echo "PATH: $path"
if test "x$errors" != x; then
echo "ERRORS: $errors"
fi
if test "x$warnings" != x; then
echo "WARNINGS: $warnings"
fi
echo "LOG:"
cat $logfile
fi > $storelog
trap - EXIT
#! /usr/bin/env python3
# SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
import argparse
import dataclasses
import errno
import logging
import re
# REUSE-IgnoreStart
parser = argparse.ArgumentParser(
description='add SPDX header to DUNE project modules'
)
parser.add_argument(
'--license', '-l', dest='license',
help='SPDX license name',
default='LicenseRef-GPL-2.0-only-with-DUNE-exception',
)
parser.add_argument(
'--copyright', '-c', dest='copyright',
help='copyright information',
default='Copyright © DUNE Project contributors, see file LICENSE.md in module root',
)
parser.add_argument(
'--like', dest='like',
help='handle files like a file named like this',
),
parser.add_argument(
'--log', dest='log',
help='set log level',
),
parser.add_argument(
'files', nargs='+',
help='files to add copyright and license headers to',
)
@dataclasses.dataclass
class Rule:
pattern: str
prefix: str = ""
suffix: str = ""
line_prefix: str = ""
line_suffix: str = ""
use_license_file: bool = False
skip_lines: re.Pattern = None
def match(self, filename) -> bool:
return bool(re.search(self.pattern, filename))
rules = [
Rule(
pattern=r"\.(?:c|cc|cc\.in|h|hh|hh\.in|ct|ht|t|geo)$|config\.h\.cmake$",
line_prefix="// ",
),
Rule(
pattern=r"\.(?:rst|rst\.in)$",
prefix="::\n",
line_prefix=" ",
suffix="\n",
),
Rule(
pattern=r"\.bib$",
line_prefix="@Comment ",
suffix="\n",
),
Rule(
pattern=r"\.dgf$",
line_prefix="% ",
skip_lines=re.compile("^DGF"),
),
Rule(
pattern=r"\.tex$",
line_prefix="% ",
suffix="\n",
),
Rule(
pattern=r"(?:\.amc|\.cmake|\.cmake\.in|\.gitignore|\.ini|\.pc\.in"
r"|\.pl|\.py|\.py\.in|\.sh|\.toml|\.toml\.in|\.yml"
r"|CMakeLists.txt|Doxylocal|dune.module|MANIFEST\.in)$",
line_prefix="# ",
suffix="\n",
),
Rule(
pattern=r"/doxygen/.*\.txt$",
line_prefix="// ",
suffix="\n",
),
Rule(
pattern=r"(?:\.md|INSTALL)$",
prefix="<!--\n",
suffix="-->\n\n",
),
Rule(
pattern=r"\.(?:cel|eps|fig|pdf|png|svg|vrt)$",
use_license_file=True,
),
Rule(
# gmsh's MSH file format support comments via unknown sections
# ($Comment ... $EndComment), but DUNE does not handle that.
# Reference: https://gmsh.info/doc/texinfo/gmsh.html#MSH-file-format
pattern=r"\.msh",
use_license_file=True,
),
]
skip_lines = re.compile(r'-\*-|vi(?:m)?:|^#!')
class Notice:
def __init__(self, copyright, license):
self.copyright = f'SPDX-FileCopyrightInfo: {copyright}'
self.license = f'SPDX-License-Identifier: {license}'
def match(self, lines) -> bool:
pattern = re.compile(f'(?:{re.escape(self.copyright)}|{re.escape(self.license)})')
return any(pattern.search(line) for line in lines)
def rule_for_file(filename) -> Rule:
for rule in rules:
if rule.match(filename):
return rule
return None
def line_for_notice(lines, rule: Rule) -> int:
for index, line in enumerate(lines):
if not skip_lines.search(line) \
and (rule.skip_lines is None or not rule.skip_lines.search(line)):
return index
return len(lines)
def apply_rule_to_file(filename, rule: Rule, notice: Notice):
if rule.use_license_file:
try:
with open(f"{filename}.license", "xt") as fh:
logging.debug(f"{filename}: create separate .license file")
print(notice.copyright, file=fh)
print(notice.license, file=fh)
except OSError as e:
if e.errno == errno.EEXIST:
logging.info(f"{filename}: separate .license file already exists")
else:
raise
else:
with open(filename, "rt") as fh:
lines = fh.readlines()
if notice.match(lines):
logging.info(f"{filename}: already contains a notice")
return
index = line_for_notice(lines, rule)
logging.debug(f"{filename}: Will insert notice at line {index}")
if rule.suffix:
lines.insert(index, rule.suffix)
lines.insert(index, f"{rule.line_prefix}{notice.license}{rule.line_suffix}\n")
lines.insert(index, f"{rule.line_prefix}{notice.copyright}{rule.line_suffix}\n")
if rule.prefix:
lines.insert(index, rule.prefix)
with open(filename, "wt") as fh:
print(*lines, sep='', end='', file=fh)
if __name__ == '__main__':
args = parser.parse_args()
if args.log:
logging.basicConfig(level=getattr(logging, args.log.upper()))
notice = Notice(args.copyright, args.license)
for filename in args.files:
logging.debug(f"Processing {filename}")
if args.like:
rule = rule_for_file(args.like)
else:
rule = rule_for_file(filename)
if rule is None:
logging.warning(f"{filename}: No rule found for this file. Add a rule or try --like.")
continue
apply_rule_to_file(filename, rule, notice)
# add-spdx() {
# local file line_prefix prefix suffix
# local copying_file="LICENSE.md"
# local license="LicenseRef-GPL-2.0-only-with-DUNE-exception"
# xxlicense="LGPL-2.1-or-later"
# for file in "$@"; do
# prefix=""
# line_prefix=""
# suffix=""
# license_file="${file}"
# case "${file}" in
# *.cc|*.hh|*config.h.cmake|*.cc.in|*.ct|*.ht|*.t) line_prefix="// " ;;
# */doxygen/*.txt) line_prefix="// "; suffix=$'\n' ;;
# *CMakeLists.txt|*.py|*.gitignore|*.yml|*Doxylocal|*.toml|*.pc.in|*dune.module|*.cmake|*.ini) line_prefix="# "; suffix=$'\n' ;;
# *.md|*INSTALL) prefix=$'<!--\n'; suffix=$'\n-->\n' ;;
# *.tex) line_prefix="% "; suffix=$'\n' ;;
# *.svg|*.png|*.eps|*.pdf) license_file="${file}.license"; file="" ;;
# esac
#
# ed ${file} <<EOT
# 0i
# ${prefix}${line_prefix}SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file ${copying_file} in module root
# ${line_prefix}SPDX-License-Identifier: ${license}${suffix}
# .
# w ${license_file}
# q
# EOT
# done
# }
# REUSE-IgnoreEnd