Allow spack create to automatically detect octave build system
This commit is contained in:
		| @@ -59,7 +59,7 @@ def get_checksums(versions, urls, **kwargs): | |||||||
|             with Stage(url, keep=keep_stage) as stage: |             with Stage(url, keep=keep_stage) as stage: | ||||||
|                 stage.fetch() |                 stage.fetch() | ||||||
|                 if i == 0 and first_stage_function: |                 if i == 0 and first_stage_function: | ||||||
|                     first_stage_function(stage) |                     first_stage_function(stage, url) | ||||||
|  |  | ||||||
|                 hashes.append((version, |                 hashes.append((version, | ||||||
|                                spack.util.crypto.checksum(hashlib.md5, stage.archive_file))) |                                spack.util.crypto.checksum(hashlib.md5, stage.archive_file))) | ||||||
|   | |||||||
| @@ -103,54 +103,19 @@ def install(self, spec, prefix): | |||||||
| ${install} | ${install} | ||||||
| """) | """) | ||||||
|  |  | ||||||
|  |  | ||||||
| def make_version_calls(ver_hash_tuples): |  | ||||||
|     """Adds a version() call to the package for each version found.""" |  | ||||||
|     max_len = max(len(str(v)) for v, h in ver_hash_tuples) |  | ||||||
|     format = "    version(%%-%ds, '%%s')" % (max_len + 2) |  | ||||||
|     return '\n'.join(format % ("'%s'" % v, h) for v, h in ver_hash_tuples) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def setup_parser(subparser): |  | ||||||
|     subparser.add_argument('url', nargs='?', help="url of package archive") |  | ||||||
|     subparser.add_argument( |  | ||||||
|         '--keep-stage', action='store_true', |  | ||||||
|         help="Don't clean up staging area when command completes.") |  | ||||||
|     subparser.add_argument( |  | ||||||
|         '-n', '--name', dest='alternate_name', default=None, metavar='NAME', |  | ||||||
|         help="Override the autodetected name for the created package.") |  | ||||||
|     subparser.add_argument( |  | ||||||
|         '-r', '--repo', default=None, |  | ||||||
|         help="Path to a repository where the package should be created.") |  | ||||||
|     subparser.add_argument( |  | ||||||
|         '-N', '--namespace', |  | ||||||
|         help="Specify a namespace for the package. Must be the namespace of " |  | ||||||
|         "a repository registered with Spack.") |  | ||||||
|     subparser.add_argument( |  | ||||||
|         '-f', '--force', action='store_true', dest='force', |  | ||||||
|         help="Overwrite any existing package file with the same name.") |  | ||||||
|  |  | ||||||
|     setup_parser.subparser = subparser |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class ConfigureGuesser(object): |  | ||||||
|     def __call__(self, stage): |  | ||||||
|         """Try to guess the type of build system used by the project. |  | ||||||
|         Set any necessary build dependencies or extensions. |  | ||||||
|         Set the appropriate default installation instructions.""" |  | ||||||
|  |  | ||||||
| # Build dependencies and extensions | # Build dependencies and extensions | ||||||
|         dependenciesDict = { | dependencies_dict = { | ||||||
|     'autotools': "# depends_on('foo')", |     'autotools': "# depends_on('foo')", | ||||||
|             'cmake':     "depends_on('cmake', type='build')", |     'cmake':     "depends_on('cmake')", | ||||||
|             'scons':     "depends_on('scons', type='build')", |     'scons':     "depends_on('scons')", | ||||||
|             'python':    "extends('python', type=nolink)", |     'python':    "extends('python')", | ||||||
|     'R':         "extends('R')", |     'R':         "extends('R')", | ||||||
|  |     'octave':    "extends('octave')", | ||||||
|     'unknown':   "# depends_on('foo')" |     'unknown':   "# depends_on('foo')" | ||||||
| } | } | ||||||
|  |  | ||||||
| # Default installation instructions | # Default installation instructions | ||||||
|         installDict = { | install_dict = { | ||||||
|     'autotools': """\ |     'autotools': """\ | ||||||
|         # FIXME: Modify the configure line to suit your build system here. |         # FIXME: Modify the configure line to suit your build system here. | ||||||
|         configure('--prefix={0}'.format(prefix)) |         configure('--prefix={0}'.format(prefix)) | ||||||
| @@ -182,12 +147,62 @@ def __call__(self, stage): | |||||||
|         R('CMD', 'INSTALL', '--library={0}'.format(self.module.r_lib_dir), |         R('CMD', 'INSTALL', '--library={0}'.format(self.module.r_lib_dir), | ||||||
|           self.stage.source_path)""", |           self.stage.source_path)""", | ||||||
|  |  | ||||||
|  |     'octave': """\ | ||||||
|  |         # FIXME: Add logic to build and install here. | ||||||
|  |         octave('--quiet', '--norc', | ||||||
|  |                '--built-in-docstrings-file=/dev/null', | ||||||
|  |                '--texi-macros-file=/dev/null', | ||||||
|  |                '--eval', 'pkg prefix {0}; pkg install {1}'.format( | ||||||
|  |                    prefix, self.stage.archive_file))""", | ||||||
|  |  | ||||||
|     'unknown': """\ |     'unknown': """\ | ||||||
|         # FIXME: Unknown build system |         # FIXME: Unknown build system | ||||||
|         make() |         make() | ||||||
|         make('install')""" |         make('install')""" | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def make_version_calls(ver_hash_tuples): | ||||||
|  |     """Adds a version() call to the package for each version found.""" | ||||||
|  |     max_len = max(len(str(v)) for v, h in ver_hash_tuples) | ||||||
|  |     format = "    version(%%-%ds, '%%s')" % (max_len + 2) | ||||||
|  |     return '\n'.join(format % ("'%s'" % v, h) for v, h in ver_hash_tuples) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def setup_parser(subparser): | ||||||
|  |     subparser.add_argument('url', nargs='?', help="url of package archive") | ||||||
|  |     subparser.add_argument( | ||||||
|  |         '--keep-stage', action='store_true', | ||||||
|  |         help="Don't clean up staging area when command completes.") | ||||||
|  |     subparser.add_argument( | ||||||
|  |         '-n', '--name', dest='alternate_name', default=None, metavar='NAME', | ||||||
|  |         help="Override the autodetected name for the created package.") | ||||||
|  |     subparser.add_argument( | ||||||
|  |         '-r', '--repo', default=None, | ||||||
|  |         help="Path to a repository where the package should be created.") | ||||||
|  |     subparser.add_argument( | ||||||
|  |         '-N', '--namespace', | ||||||
|  |         help="Specify a namespace for the package. Must be the namespace of " | ||||||
|  |         "a repository registered with Spack.") | ||||||
|  |     subparser.add_argument( | ||||||
|  |         '-f', '--force', action='store_true', dest='force', | ||||||
|  |         help="Overwrite any existing package file with the same name.") | ||||||
|  |  | ||||||
|  |     setup_parser.subparser = subparser | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class BuildSystemGuesser(object): | ||||||
|  |     def __call__(self, stage, url): | ||||||
|  |         """Try to guess the type of build system used by a project based on | ||||||
|  |         the contents of its archive or the URL it was downloaded from.""" | ||||||
|  |  | ||||||
|  |         # Most octave extensions are hosted on Octave-Forge: | ||||||
|  |         #     http://octave.sourceforge.net/index.html | ||||||
|  |         # They all have the same base URL. | ||||||
|  |         if 'downloads.sourceforge.net/octave/' in url: | ||||||
|  |             self.build_system = 'octave' | ||||||
|  |             return | ||||||
|  |  | ||||||
|         # A list of clues that give us an idea of the build system a package |         # A list of clues that give us an idea of the build system a package | ||||||
|         # uses. If the regular expression matches a file contained in the |         # uses. If the regular expression matches a file contained in the | ||||||
|         # archive, the corresponding build system is assumed. |         # archive, the corresponding build system is assumed. | ||||||
| @@ -224,12 +239,6 @@ def __call__(self, stage): | |||||||
|  |  | ||||||
|         self.build_system = build_system |         self.build_system = build_system | ||||||
|  |  | ||||||
|         # Set any necessary build dependencies or extensions. |  | ||||||
|         self.dependencies = dependenciesDict[build_system] |  | ||||||
|  |  | ||||||
|         # Set the appropriate default installation instructions |  | ||||||
|         self.install = installDict[build_system] |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def guess_name_and_version(url, args): | def guess_name_and_version(url, args): | ||||||
|     # Try to deduce name and version of the new package from the URL |     # Try to deduce name and version of the new package from the URL | ||||||
| @@ -334,8 +343,8 @@ def create(parser, args): | |||||||
|     # Fetch tarballs (prompting user if necessary) |     # Fetch tarballs (prompting user if necessary) | ||||||
|     versions, urls = fetch_tarballs(url, name, version) |     versions, urls = fetch_tarballs(url, name, version) | ||||||
|  |  | ||||||
|     # Try to guess what configure system is used. |     # Try to guess what build system is used. | ||||||
|     guesser = ConfigureGuesser() |     guesser = BuildSystemGuesser() | ||||||
|     ver_hash_tuples = spack.cmd.checksum.get_checksums( |     ver_hash_tuples = spack.cmd.checksum.get_checksums( | ||||||
|         versions, urls, |         versions, urls, | ||||||
|         first_stage_function=guesser, |         first_stage_function=guesser, | ||||||
| @@ -344,13 +353,13 @@ def create(parser, args): | |||||||
|     if not ver_hash_tuples: |     if not ver_hash_tuples: | ||||||
|         tty.die("Could not fetch any tarballs for %s" % name) |         tty.die("Could not fetch any tarballs for %s" % name) | ||||||
|  |  | ||||||
|     # Prepend 'py-' to python package names, by convention. |     # Add prefix to package name if it is an extension. | ||||||
|     if guesser.build_system == 'python': |     if guesser.build_system == 'python': | ||||||
|         name = 'py-%s' % name |         name = 'py-{0}'.format(name) | ||||||
|  |  | ||||||
|     # Prepend 'r-' to R package names, by convention. |  | ||||||
|     if guesser.build_system == 'R': |     if guesser.build_system == 'R': | ||||||
|         name = 'r-%s' % name |         name = 'r-{0}'.format(name) | ||||||
|  |     if guesser.build_system == 'octave': | ||||||
|  |         name = 'octave-{0}'.format(name) | ||||||
|  |  | ||||||
|     # Create a directory for the new package. |     # Create a directory for the new package. | ||||||
|     pkg_path = repo.filename_for_package_name(name) |     pkg_path = repo.filename_for_package_name(name) | ||||||
| @@ -367,8 +376,8 @@ def create(parser, args): | |||||||
|                 class_name=mod_to_class(name), |                 class_name=mod_to_class(name), | ||||||
|                 url=url, |                 url=url, | ||||||
|                 versions=make_version_calls(ver_hash_tuples), |                 versions=make_version_calls(ver_hash_tuples), | ||||||
|                 dependencies=guesser.dependencies, |                 dependencies=dependencies_dict[guesser.build_system], | ||||||
|                 install=guesser.install)) |                 install=install_dict[guesser.build_system])) | ||||||
|  |  | ||||||
|     # If everything checks out, go ahead and edit. |     # If everything checks out, go ahead and edit. | ||||||
|     spack.editor(pkg_path) |     spack.editor(pkg_path) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Adam J. Stewart
					Adam J. Stewart