From 1ceedd433c800aae36aa58bf28a59ba0332da42a Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Sat, 13 Mar 2021 22:11:11 +0000
Subject: [PATCH] Adding MAD-X package

- MAD-X accelerator simulation.
- https://github.com/MethodicalAcceleratorDesign/MAD-X
- Started with a copy of ACTS' package
---
 .gitlab-ci.yml                 | 10 ++++
 containers/builder/spack.yaml  |  1 +
 gitlab-ci/docker/Makefile      | 10 ++--
 spack/packages/madx/README.md  |  1 +
 spack/packages/madx/package.py | 83 ++++++++++++++++++++++++++++++++++
 5 files changed, 100 insertions(+), 5 deletions(-)
 create mode 100644 spack/packages/madx/README.md
 create mode 100644 spack/packages/madx/package.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c6afaada9..964163fc1 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -40,6 +40,16 @@ init:
     paths:
       - build_and_deploy.yml
 
+## Quick debug build for new spack packages
+#run:quick_build:
+#  image: eicweb.phy.anl.gov:4567/containers/eic_container/eic_builder:latest
+#  stage: build
+#  script:
+#    - rm -r /opt/spack/np-spack && cp -r spack /opt/spack/np-spack
+#    - source /opt/spack/share/spack/setup-env.sh
+#    - spack env activate /opt/spack-environment
+#    - spack add madx && spack install
+
 ## Dispatch if we ran the previous stage
 run:default:
   stage: build
diff --git a/containers/builder/spack.yaml b/containers/builder/spack.yaml
index f90271e8e..d40f4248c 100644
--- a/containers/builder/spack.yaml
+++ b/containers/builder/spack.yaml
@@ -1,5 +1,6 @@
 spack:
   specs:
+    - madx@5.06.1
     - cmake@3.18.1
     - fmt@7.1.2 cxxstd=17
     - spdlog@1.5.0
diff --git a/gitlab-ci/docker/Makefile b/gitlab-ci/docker/Makefile
index 1d3521f89..876327160 100644
--- a/gitlab-ci/docker/Makefile
+++ b/gitlab-ci/docker/Makefile
@@ -55,25 +55,25 @@ publish-stable: login
 	@echo 'publish $(STABLE) to $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME)'
 	docker tag $(APP_NAME):$(VERSION) $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):$(STABLE)
 	docker push $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):$(STABLE)
-	docker rmi $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):$(STABLE)
+	docker rmi $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):$(STABLE) || true
 
 publish-latest: login 
-	@echo 'publish latest to $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME)'
+	echo 'publish latest to $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME)'
 	docker tag $(APP_NAME):$(VERSION) $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):latest
 	docker push $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):latest
-	docker rmi $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):latest
+	docker rmi $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):latest || true
 
 publish-version: login 
 	@echo 'publish $(STABLE) to $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME)'
 	docker tag $(APP_NAME):$(VERSION) $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):$(VERSION)
 	docker push $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):$(VERSION)
-	docker rmi $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):$(VERSION)
+	docker rmi $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):$(VERSION) || true
 
 publish-unstable: login 
 	@echo 'publish unstable to $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME)'
 	docker tag $(APP_NAME):$(VERSION)-unstable $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):unstable
 	docker push $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):unstable
-	docker rmi $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):unstable
+	docker rmi $(REG_NAME)/$(GL_REG_GROUP)/$(APP_NAME):unstable || true
 
 version: ## Output the current version
 	@echo $(VERSION)
diff --git a/spack/packages/madx/README.md b/spack/packages/madx/README.md
new file mode 100644
index 000000000..6ef86b4cd
--- /dev/null
+++ b/spack/packages/madx/README.md
@@ -0,0 +1 @@
+https://github.com/MethodicalAcceleratorDesign/MAD-X.git
diff --git a/spack/packages/madx/package.py b/spack/packages/madx/package.py
new file mode 100644
index 000000000..78d98350b
--- /dev/null
+++ b/spack/packages/madx/package.py
@@ -0,0 +1,83 @@
+# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class Madx(CMakePackage):
+    """
+    
+    """
+
+    homepage = "https://github.com/MethodicalAcceleratorDesign/MAD-X"
+    git      = "https://github.com/MethodicalAcceleratorDesign/MAD-X.git"
+    maintainers = ['tpersson']
+
+    tags = ['hep']
+
+    # Supported MAD-X versions
+    version('master', branch='master')
+    version('5.06.1', commit='f3764bceefb802f6b2a3c35d7d961adf6718d377')
+
+    #variant('benchmarks', default=False, description='Build the performance benchmarks')
+    #variant('examples', default=False, description='Build the examples')
+    #variant('integration_tests', default=False, description='Build the integration tests')
+    #variant('unit_tests', default=False, description='Build the unit tests')
+
+    #variant('autodiff', default=False, description='Build the auto-differentiation plugin')
+    #variant('dd4hep', default=False, description='Build the DD4hep plugin')
+    #variant('digitization', default=False, description='Build the geometric digitization plugin')
+    #variant('fatras', default=False, description='Build the FAst TRAcking Simulation package')
+    #variant('identification', default=False, description='Build the Identification plugin')
+    #variant('json', default=False, description='Build the Json plugin')
+    #variant('legacy', default=False, description='Build the Legacy package')
+    ## FIXME: Cannot build ONNX plugin as Spack doesn't have an ONNX runtime
+    ## FIXME: Cannot build SyCL plugin yet as Spack doesn't have SyCL support
+    #variant('tgeo', default=False, description='Build the TGeo plugin')
+
+    # Variants that only affect Acts examples for now
+    #variant('geant4', default=False, description='Build the Geant4-based examples')
+    #variant('hepmc3', default=False, description='Build the HepMC3-based examples')
+    #variant('pythia8', default=False, description='Build the Pythia8-based examples')
+
+    depends_on("libx11")
+
+    # Build dependencies
+    # FIXME: Use spack's autodiff package once there is one
+    #depends_on('boost @1.62:1.69.99 +program_options +test', when='@:0.10.3')
+    #depends_on('boost @1.69: +filesystem +program_options +test', when='@0.10.4:')
+    #depends_on('cmake @3.11:', type='build')
+    #depends_on('dd4hep @1.10:', when='+dd4hep')
+    #depends_on('dd4hep @1.10: +geant4', when='+dd4hep +geant4')
+    #depends_on('eigen @3.2.9:', type='build')
+    #depends_on('geant4', when='+geant4')
+    #depends_on('hepmc3@3.1:', when='+hepmc3')
+    #depends_on('heppdt', when='+hepmc3')
+    #depends_on('intel-tbb', when='+examples')
+    #depends_on('nlohmann-json @3.2.0:', when='@0.14: +json')
+    #depends_on('pythia8', when='+pythia8')
+    #depends_on('root @6.10: cxxstd=14', when='+tgeo @:0.8.0')
+    #depends_on('root @6.10: cxxstd=17', when='+tgeo @0.8.1:')
+
+    ## Some variant combinations do not make sense
+    #conflicts('+autodiff', when='@:1.01')
+    #conflicts('+benchmarks', when='@:0.15')
+    #conflicts('+dd4hep', when='-tgeo')
+    #conflicts('+examples', when='@:0.22')
+    #conflicts('+examples', when='-digitization')
+    #conflicts('+examples', when='-fatras')
+    #conflicts('+examples', when='-identification')
+    #conflicts('+examples', when='-json')
+    #conflicts('+examples', when='-tgeo')
+    #conflicts('+fatras', when='@:0.15')
+    #conflicts('+geant4', when='@:0.22')
+    #conflicts('+geant4', when='-examples')
+    #conflicts('+hepmc3', when='@:0.22')
+    #conflicts('+hepmc3', when='-examples')
+    #conflicts('+pythia8', when='@:0.22')
+    #conflicts('+pythia8', when='-examples')
+    #conflicts('+tgeo', when='-identification')
+    #conflicts('%gcc@:7', when='@0.23:')
+
-- 
GitLab