Skip to content

Commit

Permalink
[GR-52605] Extract a batch of build system contents into separate sub…
Browse files Browse the repository at this point in the history
…package

PullRequest: mx/1703
  • Loading branch information
rudihorn committed Mar 18, 2024
2 parents ebb7774 + afe367a commit 69e693f
Show file tree
Hide file tree
Showing 30 changed files with 2,144 additions and 1,269 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,15 @@ systems, and to `B` for all other systems.

It is only possible to specify one of either the `os`, `arch` or `os_arch`
options for any project.

### Type hints

Code in MX should make a best effort case to include typing information wherever
it would otherwise not immediately be clear. Typing information should be
compatible with the currently supported Python version. Typing information for
built-in types can be taken from the `typing` package. Where required,
`__future__` may be imported from the `annotations` package.

Helpful links:
* [PEP 484 - Type Hints](https://peps.python.org/pep-0484/)
* [Support for type hints](https://docs.python.org/3.8/library/typing.html)
13 changes: 8 additions & 5 deletions src/mx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,35 @@
# mx exports its own open symbol which redefines a builtin
from ._impl.mx import * # pylint: disable=redefined-builtin

# import the symbols that have been moved already
from ._impl.legacy import *

# For some reason these private symbols are used externally
from ._impl.support.processes import _addSubprocess, _removeSubprocess
from ._impl.mx import (
_mx_path,
_opts,
_replaceResultsVar,
_addSubprocess,
_cache_dir,
_check_global_structures,
_chunk_files_for_command_line,
_encode,
_entries_to_classpath,
_get_dependency_path,
_missing_dep_message,
_mx_home,
_mx_suite,
_needsUpdate,
_removeSubprocess,
# Only used by tests
_primary_suite_init,
)

from mx._legacy.oldnames import redirect as _redirect

from ._impl import legacy as _legacy
import mx._impl.mx as _orig

__all__ = _orig.__all__
__all__ = []
__all__ += _legacy.__all__
__all__ += _orig.__all__

# Unlike all the modules in oldnames, this module is used for both the legacy
# access and access in the package system to the `mx` module because there is
Expand Down
Empty file added src/mx/_impl/build/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions src/mx/_impl/build/args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# ----------------------------------------------------------------------------------------------------
#
# Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# ----------------------------------------------------------------------------------------------------
#

from argparse import Namespace
from dataclasses import dataclass
from typing import Optional

@dataclass(repr = False)
class ArgsNamespace(Namespace):
verbose: bool = False
very_verbose: bool = False
warn: bool = True
quiet: bool = False
answer: Optional[str] = None
"""Answer all questions with 'y' or 'n'"""
java_dbg_port: Optional[int] = None
clean: bool = False
33 changes: 33 additions & 0 deletions src/mx/_impl/build/daemon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ----------------------------------------------------------------------------------------------------
#
# Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# ----------------------------------------------------------------------------------------------------
#

class Daemon:
"""
Daemons are background processes used during the build process and
should be terminated once the build is finished.
"""
def shutdown(self) -> None:
pass
34 changes: 34 additions & 0 deletions src/mx/_impl/build/suite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# ----------------------------------------------------------------------------------------------------
#
# Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# ----------------------------------------------------------------------------------------------------
#

__all__ = [
"Dependency",
"SuiteConstituent",
]

from .dependency import Dependency
from .constituent import SuiteConstituent
110 changes: 110 additions & 0 deletions src/mx/_impl/build/suite/constituent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#
# ----------------------------------------------------------------------------------------------------
#
# Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# ----------------------------------------------------------------------------------------------------
#

from __future__ import annotations
from abc import ABCMeta
import os.path
from typing import Any, Optional

from ...support.comparable import ComparisonResult, compare, Comparable

# TODO: Replace with actual type
Suite = Any

class SuiteConstituent(Comparable, metaclass=ABCMeta):
name: str
suite: Suite
build_time: int
"""Expected build time in minutes (Used to schedule parallel jobs efficiently)"""

internal: bool
"""Should this constituent be visible outside its suite"""

def __init__(self, suite: Suite, name: str, build_time: int = 1):
self.name = name
self.suite = suite
self.build_time = build_time
self.internal = False

def origin(self) -> Optional[tuple[Suite, int]]:
"""
Gets a 2-tuple (file, line) describing the source file where this constituent
is defined or None if the location cannot be determined.
"""
suitepy = self.suite.suite_py()
if os.path.exists(suitepy):
import tokenize
with open(suitepy) as fp:
candidate = None
for t in tokenize.generate_tokens(fp.readline):
_, tval, (srow, _), _, _ = t
if candidate is None:
if tval in ('"' + self.name + '"', "'" + self.name + "'"):
candidate = srow
else:
if tval == ':':
return (suitepy, srow)
else:
candidate = None

def __abort_context__(self) -> str:
"""
Gets a description of where this constituent was defined in terms of source file
and line number. If no such description can be generated, None is returned.
"""
loc = self.origin()
if loc:
path, lineNo = loc
return f' File "{path}", line {lineNo} in definition of {self.name}'
return f' {self.name}'

def _comparison_key(self) -> tuple[str, Suite]:
return self.name, self.suite

def __cmp__(self, other) -> ComparisonResult:
if not isinstance(other, self.__class__):
return NotImplemented
return compare(self._comparison_key(), other._comparison_key())

def __eq__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
return self._comparison_key() == other._comparison_key()

def __ne__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
return self._comparison_key() != other._comparison_key()

def __hash__(self):
return hash(self._comparison_key())

def __str__(self):
return self.name

def __repr__(self):
return self.name
Loading

0 comments on commit 69e693f

Please sign in to comment.