Browse Source

Merge pull request #15371 from ghalliday/issue26423

HPCC-26423 Allow the remote default git repo to be configured

Reviewed-By: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 3 years ago
parent
commit
3e37cdadce
4 changed files with 24 additions and 9 deletions
  1. 10 1
      ecl/eclcc/eclcc.cpp
  2. 1 0
      ecl/eclcc/eclcc.hpp
  3. 10 7
      ecl/hql/hqlrepository.cpp
  4. 3 1
      ecl/hql/hqlrepository.hpp

+ 10 - 1
ecl/eclcc/eclcc.cpp

@@ -251,6 +251,10 @@ public:
 #ifdef _CONTAINERIZED
         setSecurityOptions();
 #endif
+        const char * defaultGitPrefix = getenv("ECLCC_DEFAULT_GITPREFIX");
+        if (isEmptyString(defaultGitPrefix))
+            defaultGitPrefix = "git+ssh://github.com/";
+        optDefaultGitPrefix.set(defaultGitPrefix);
     }
     ~EclCC()
     {
@@ -372,6 +376,8 @@ protected:
     StringArray deniedPermissions;
     StringAttr optMetaLocation;
     StringBuffer neverSimplifyRegEx;
+    StringAttr optDefaultGitPrefix;
+
     bool defaultAllowed[2];
 
     ClusterType optTargetClusterType = RoxieCluster;
@@ -2166,7 +2172,7 @@ bool EclCC::processFiles()
 
     //Set up the default repository information.  This could be simplified to not use a localRepositoryManager later
     //if eclcc did not have a strange mode for running multiple queries as part of the regression suite testing on windows.
-    repositoryManager.setOptions(eclRepoPath, optFetchRepos, optUpdateRepos, logVerbose);
+    repositoryManager.setOptions(eclRepoPath, optDefaultGitPrefix, optFetchRepos, optUpdateRepos, logVerbose);
     ForEachItemIn(iMapping, repoMappings)
     {
         const char * cur = repoMappings.item(iMapping);
@@ -2641,6 +2647,9 @@ int EclCC::parseCommandLineOptions(int argc, const char* argv[])
         {
             //Ignore any --daemon option supplied to eclccserver which may be passed onto eclcc
         }
+        else if (iter.matchOption(optDefaultGitPrefix, "--defaultGitPrefix"))
+        {
+        }
         else if (iter.matchOption(optDFS, "-dfs") || /*deprecated*/ iter.matchOption(optDFS, "-dali"))
         {
             // Note - we wait until first use before actually connecting to dali

+ 1 - 0
ecl/eclcc/eclcc.hpp

@@ -85,6 +85,7 @@ const char * const helpText[] = {
     "!   -brk <n>      Trigger a break point in eclcc after nth allocation",
 #endif
     "!   -Dname=value  Override the definition of a global attribute 'name'",
+    "!   --defaultGitPrefix <prefix>  The default prefix used to access git repos when not specified in package.json",
     "!   --deny=all    Disallow use of all named features not specifically allowed using --allow",
     "!   --deny=str    Disallow use of named feature",
     "!   --expand <path> Expand the contents of an archive to a directory",

+ 10 - 7
ecl/hql/hqlrepository.cpp

@@ -55,7 +55,7 @@ bool looksLikeGitPackage(const char * urn)
     return false;
 }
 
-static bool splitRepoVersion(StringBuffer & repoUrn, StringBuffer & repo, StringBuffer & version, const char * urn)
+static bool splitRepoVersion(StringBuffer & repoUrn, StringBuffer & repo, StringBuffer & version, const char * urn, const char * defaultGitPrefix)
 {
     const char * cur = urn;
     //Allow either protocol://<server>/<user>/<repo>[#version] or <user>/<repo>[#version]
@@ -73,11 +73,14 @@ static bool splitRepoVersion(StringBuffer & repoUrn, StringBuffer & repo, String
         //cur now points at the user - same as the other syntax
         cur = slash + 1;
     }
-    else if (!isalnum(*urn))
-        return false;
+    else if (isalnum(*urn))
+    {
+        //Use defaultGitPrefix so gitlab can also be used by default. HPCC-26423
+        repoUrn.append(defaultGitPrefix);
+        addPathSepChar(repoUrn);
+    }
     else
-        //MORE: Pass this in as a defaultGitPrefix so gitlab can also be used by default. HPCC-26423
-        repoUrn.append("git+ssh://github.com/");
+        return false;
 
     const char * hash = strchr(cur, '#');
     if (hash)
@@ -552,7 +555,7 @@ void EclRepositoryManager::addRepository(IEclSourceCollection * source, const ch
 void EclRepositoryManager::addMapping(const char * url, const char * path)
 {
     StringBuffer repoUrn, repo, version;
-    if (!splitRepoVersion(repoUrn, repo, version, url))
+    if (!splitRepoVersion(repoUrn, repo, version, url, options.defaultGitPrefix))
         throw makeStringExceptionV(99, "Unsupported repository link format '%s'", url);
     repos.append(*new EclRepositoryMapping(repo, version, path));
 }
@@ -599,7 +602,7 @@ IEclPackage * EclRepositoryManager::resolveDependentRepository(IIdAtom * name, c
     if (!filename)
     {
         StringBuffer repoUrn, repo, version;
-        if (!splitRepoVersion(repoUrn, repo, version, defaultUrl))
+        if (!splitRepoVersion(repoUrn, repo, version, defaultUrl, options.defaultGitPrefix))
             throw makeStringExceptionV(99, "Unsupported repository link format '%s'", defaultUrl);
         if (isEmptyString(version))
             throw makeStringExceptionV(99, "Expected a version number in the url '%s'", defaultUrl);

+ 3 - 1
ecl/hql/hqlrepository.hpp

@@ -55,9 +55,10 @@ public:
 
     void processArchive(IPropertyTree * archiveTree);
     IEclPackage * resolveDependentRepository(IIdAtom * name, const char * defaultUrl, bool requireSHA);
-    void setOptions(const char * _eclRepoPath, bool _fetchRepos, bool _updateRepos, bool _verbose)
+    void setOptions(const char * _eclRepoPath, const char * _defaultGitPrefix, bool _fetchRepos, bool _updateRepos, bool _verbose)
     {
         options.eclRepoPath.set(_eclRepoPath);
+        options.defaultGitPrefix.set(_defaultGitPrefix);
         options.fetchRepos = _fetchRepos;
         options.updateRepos = _updateRepos;
         options.optVerbose = _verbose;
@@ -80,6 +81,7 @@ private:
     //Include all options in a nested struct to make it easy to ensure they are cloned
     struct {
         StringAttr eclRepoPath;
+        StringAttr defaultGitPrefix;
         bool fetchRepos = false;
         bool updateRepos = false;
         bool optVerbose = false;