From 9a5054c63e6ab9afa1a1610b6aa420e180a0621e Mon Sep 17 00:00:00 2001
From: Gilles Duboscq <gilles.m.duboscq@oracle.com>
Date: Sun, 8 Apr 2018 23:28:26 +0200
Subject: [PATCH] Avoid using template distributions

---
 mx.fastr/mx_fastr.py       |  5 +++
 mx.fastr/mx_fastr_dists.py | 77 +++++++++++++++++++++++++++++++++++++-
 mx.fastr/suite.py          | 76 +------------------------------------
 3 files changed, 81 insertions(+), 77 deletions(-)

diff --git a/mx.fastr/mx_fastr.py b/mx.fastr/mx_fastr.py
index 4281149ab5..5567fc9e49 100644
--- a/mx.fastr/mx_fastr.py
+++ b/mx.fastr/mx_fastr.py
@@ -580,6 +580,7 @@ def nativebuild(args):
             os.remove(jniboot_done)
         return mx.build(['--no-java'])
 
+
 def mx_post_parse_cmd_line(opts):
     mx_fastr_dists.mx_post_parse_cmd_line(opts)
     if mx.suite("sulong", fatalIfMissing=False) and not _fastr_suite.isBinarySuite():
@@ -588,6 +589,10 @@ def mx_post_parse_cmd_line(opts):
         rec = mx.project('com.oracle.truffle.r.native.recommended')
         rec.buildDependencies += [mx.distribution('SULONG')]
 
+
+mx_register_dynamic_suite_constituents = mx_fastr_dists.mx_register_dynamic_suite_constituents
+
+
 mx_unittest.add_config_participant(_unittest_config_participant)
 
 _commands = {
diff --git a/mx.fastr/mx_fastr_dists.py b/mx.fastr/mx_fastr_dists.py
index 18514fa1d6..95b5b3ff45 100644
--- a/mx.fastr/mx_fastr_dists.py
+++ b/mx.fastr/mx_fastr_dists.py
@@ -198,13 +198,86 @@ class FastRArchiveParticipant:
 
 
 def mx_post_parse_cmd_line(opts):
-    mx.instantiateDistribution('FASTR_RELEASE<rffi>', dict(rffi=mx.get_env('FASTR_RFFI', '')))
-
     for dist in mx_fastr._fastr_suite.dists:
         if isinstance(dist, mx.JARDistribution):
             dist.set_archiveparticipant(FastRArchiveParticipant(dist))
 
 
+def mx_register_dynamic_suite_constituents(register_project, register_distribution):
+    rffi = mx.get_env('FASTR_RFFI', '')
+    fastr_release_distribution = mx.JARDistribution(suite=mx_fastr._fastr_suite,
+                                                    name="FASTR_RELEASE" + rffi,
+                                                    subDir=None,
+                                                    path="mxbuild/dists/<os>/<arch>/{rffi}/fastr-release.jar".format(rffi=rffi),
+                                                    sourcesPath=None,
+                                                    deps=["com.oracle.truffle.r.release"],
+                                                    mainClass=None,
+                                                    excludedLibs=[],
+                                                    distDependencies=[],
+                                                    javaCompliance=None,
+                                                    platformDependent=True,
+                                                    theLicense=None)
+    fastr_release_distribution.description = "a binary release of FastR"
+
+    fastr_graalvm_release = mx.NativeTARDistribution(suite=mx_fastr._fastr_suite,
+                                                     name="FASTR_GRAALVM_RELEASE" + rffi,
+                                                     deps=["com.oracle.truffle.r.release"],
+                                                     path=None,
+                                                     excludedLibs=[],
+                                                     platformDependent=True,
+                                                     theLicense=None,
+                                                     relpath=True,
+                                                     output=None)
+
+    register_distribution(fastr_release_distribution)
+    register_distribution(fastr_graalvm_release)
+
+    if mx.get_env('FASTR_RELEASE') == 'true':
+        fastr_graalvm_release_support = mx.LayoutTARDistribution(suite=mx_fastr._fastr_suite,
+                                                                 name="FASTR_GRAALVM_SUPPORT" + rffi,
+                                                                 deps=[],
+                                                                 layout={
+                                                                     "./": [
+                                                                         {
+                                                                             "source_type": "extracted-dependency",
+                                                                             "dependency": "FASTR_GRAALVM_RELEASE" + rffi,
+                                                                             "path": "*",
+                                                                             "exclude": [
+                                                                                 "COPYRIGHT",
+                                                                                 "LICENSE",
+                                                                                 "README.md",
+                                                                                 "bin/Rscript",
+                                                                                 "bin/fastr_jars",
+                                                                                 "bin/exec/R",
+                                                                             ],
+                                                                         },
+                                                                         {
+                                                                             "source_type": "extracted-dependency",
+                                                                             "dependency": "FASTR_GRAALVM_RELEASE" + rffi,
+                                                                             "path": "bin/fastr_jars/*",
+                                                                             "exclude": [
+                                                                                 "bin/fastr_jars/fastr.jar",
+                                                                                 "bin/fastr_jars/truffle*",
+                                                                                 "bin/fastr_jars/graal-sdk*",
+                                                                             ],
+                                                                         },
+                                                                         "dependency:fastr:GNUR",
+                                                                     ],
+                                                                     "COPYRIGHT_FASTR": "extracted-dependency:fastr:FASTR_GRAALVM_RELEASE{rffi}/COPYRIGHT".format(rffi=rffi),
+                                                                     "LICENSE_FASTR": "extracted-dependency:fastr:FASTR_GRAALVM_RELEASE{rffi}/LICENSE".format(rffi=rffi),
+                                                                     "README_FASTR": "extracted-dependency:fastr:FASTR_GRAALVM_RELEASE{rffi}/README.md".format(rffi=rffi),
+                                                                     "bin/Rscript": "file:com.oracle.truffle.r.release/src/Rscript_legacy",
+                                                                     "bin/exec/R": "file:com.oracle.truffle.r.release/src/R_legacy",
+                                                                     "R-3.4.0.tar.gz" : "dependency:fastr:GNUR",
+                                                                     "legacy/": "dependency:fastr:FASTR_LEGACY_LAUNCHER",
+                                                                 },
+                                                                 path=None,
+                                                                 platformDependent=True,
+                                                                 theLicense=None)
+        fastr_graalvm_release_support.description = "FastR support distribution for the GraalVM"
+        register_distribution(fastr_graalvm_release_support)
+
+
 mx_sdk.register_component(mx_sdk.GraalVmLanguage(
     name='FastR',
     id='R',
diff --git a/mx.fastr/suite.py b/mx.fastr/suite.py
index 9b90506a2c..549a95db16 100644
--- a/mx.fastr/suite.py
+++ b/mx.fastr/suite.py
@@ -435,80 +435,6 @@ suite = {
       "maven" : False
     },
 
-    "FASTR_RELEASE<rffi>": {
-      "description" : "a binary release of FastR",
-      "dependencies" : ["com.oracle.truffle.r.release"],
-      "os_arch" : {
-        "linux" : {
-          "amd64" : {
-            "path" : "mxbuild/dists/linux/amd64/<rffi>/fastr-release.jar",
-          },
-          "sparcv9" : {
-            "path" : "mxbuild/dists/linux/sparcv9/<rffi>/fastr-release.jar",
-          },
-        },
-        "darwin" : {
-          "amd64" : {
-            "path" : "mxbuild/dists/darwin/amd64/<rffi>/fastr-release.jar",
-          },
-        },
-        "solaris" : {
-          "amd64" : {
-            "path" : "mxbuild/dists/solaris/amd64/<rffi>/fastr-release.jar",
-          },
-          "sparcv9" : {
-            "path" : "mxbuild/dists/solaris/sparcv9/<rffi>/fastr-release.jar",
-          },
-        },
-      },
-    },
-
-    "FASTR_GRAALVM_RELEASE": {
-      "native" : True,
-      "platformDependent" : True,
-      "relpath" : True,
-      "description" : "a binary release of FastR",
-      "dependencies" : ["com.oracle.truffle.r.release"],
-    },
-
-    "FASTR_GRAALVM_SUPPORT" : {
-      "native" : True,
-      "platformDependent" : True,
-      "description" : "FastR support distribution for the GraalVM",
-      "layout" : {
-        "./" : [
-          {
-            "source_type" : "extracted-dependency",
-            "dependency" : "FASTR_GRAALVM_RELEASE",
-            "path" : "*",
-            "exclude" : [
-              "COPYRIGHT",
-              "LICENSE",
-              "README.md",
-              "bin/Rscript",
-              "bin/fastr_jars",
-              "bin/exec/R",
-            ],
-          },
-          {
-            "source_type" : "extracted-dependency",
-            "dependency" : "FASTR_GRAALVM_RELEASE",
-            "path" : "bin/fastr_jars/*",
-            "exclude" : [
-              "bin/fastr_jars/fastr.jar",
-              "bin/fastr_jars/truffle*",
-              "bin/fastr_jars/graal-sdk*",
-            ],
-          },
-        ],
-        "COPYRIGHT_FASTR" : "extracted-dependency:fastr:FASTR_GRAALVM_RELEASE/COPYRIGHT",
-        "LICENSE_FASTR" : "extracted-dependency:fastr:FASTR_GRAALVM_RELEASE/LICENSE",
-        "README_FASTR" : "extracted-dependency:fastr:FASTR_GRAALVM_RELEASE/README.md",
-        "bin/Rscript" : "file:com.oracle.truffle.r.release/src/Rscript_legacy",
-        "bin/exec/R" : "file:com.oracle.truffle.r.release/src/R_legacy",
-        "R-3.4.0.tar.gz" : "dependency:fastr:GNUR",
-        "legacy/" : "dependency:fastr:FASTR_LEGACY_LAUNCHER",
-      },
-    }
+    # see mx_fastr_dists.mx_register_dynamic_suite_constituents for the definitions of some RFFI-dependent distributions
   },
 }
-- 
GitLab