Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated creating and updating scala_x_x.bzl repository files #1608

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

lm1nrt
Copy link
Contributor

@lm1nrt lm1nrt commented Sep 3, 2024

Description

  • Updated SHA's, dependencies, artifacts for all of the scala_x_x.bzl repository files with transitive dependencies compliance
  • Added a script that simplifies creating and updating scala_x_x.bzl repository files.

It's not the ideal version, but I believe it can be improved by adding support for more Scala artifacts.

Motivation

Updating and creating new versions for scala_x_x.bzl files is time-consuming, and it's a kind of work that is not performed regularly due to its specifics.

@lm1nrt lm1nrt changed the title testing new convention of file Automated version update Sep 3, 2024
@lm1nrt lm1nrt force-pushed the michal-lenart/automated-version-update branch from c703f8e to 3248e01 Compare September 10, 2024 09:44
scala_major = ".".join(scala_version.split(".")[:2])
scala_test_major = "3" if scala_major >= "3.0" else scala_major
scala_fmt_major = "2.13" if scala_major >= "3.0" else scala_major
kind_projector_version = "0.13.2" if scala_major < "2.13" else "0.13.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some versions are not compatible/doesn't exist in certain Scala version


def get_maven_coordinates(artifact) -> MavenCoordinates:
splitted = artifact.split(':')
version = splitted[2] if splitted[2][0].isnumeric() else splitted[3]
Copy link
Contributor Author

@lm1nrt lm1nrt Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version location in maven coordinates isn't strict, so there are cases that the version is under the x+1 index after splitting it by ':'

data = json.load(file)
return get_mavens_coordinates_from_json(dependency["directDependencies"]) if any((dependency := d)["coord"] == artifact for d in data["dependencies"]) else []

def get_label(coordinate) -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 5 patterns of labels, which are related to the structure of certain group and artifact due to custom naming.

temp = {}

for a in artifacts:
label = get_label(a.coordinates).replace('scala3_', 'scala_').replace('scala_tasty_core', 'scala_scala_tasty_core')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's related to custom naming convention of certain labels, TBD in the future to simplify it.

def is_that_trailing_coma(content, char, indice) -> bool:
return content[indice] == char and content[indice+1] != ',' and content[indice+1] != ':' and content[indice+1] != '@' and not content[indice+1].isalnum()

def get_with_trailing_commas(content) -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After mapping to the dict, there are no trailing commas, so this is a workaround to adjust file to .bzl files / starlark convention and CI-checks failures.

path = os.getcwd().replace('/scripts', '/third_party/repositories')
file = Path(f'{path}/{'scala_' + "_".join(version.split(".")[:2]) + '.bzl'}')

if not file.exists():
Copy link
Contributor Author

@lm1nrt lm1nrt Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If file doesn't exist, the script is copying the content from last file in directory (default sort) and updating it. So it won't work when someone is creating e.g. scala_2_10.bzl (since the heuristic is copying the content from scala_3_5.bzl in this example).

data.write(line)

with file.open('r+') as data:
excluded_artifacts = ["org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are artifacts versions that cause CI-check failures after update and exceptions in logs.

original_artifact_dict[label]["artifact"] = artifact
original_artifact_dict[label]["sha256"] = sha
if deps:
dependencies = [d for d in deps if d[1:] in labels and "runtime" not in d and "runtime" not in artifact]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not modifying the runtime dependencies due to CI-checks failure.

@lm1nrt lm1nrt changed the title Automated version update Automated creating and updating repository file Sep 20, 2024
@lm1nrt lm1nrt changed the title Automated creating and updating repository file Automated creating and updating scala_x_x.bzl repository file Sep 20, 2024
@lm1nrt lm1nrt changed the title Automated creating and updating scala_x_x.bzl repository file Automated creating and updating scala_x_x.bzl repository files Sep 20, 2024

def map_to_resolved_artifacts(output) -> List[ResolvedArtifact]:
resolved_artifacts = []
subprocess.call(f'cs fetch {' '.join(output)} --json-output-file out.json', shell=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creates local file to get the directDependencies for fetched artifacts

@@ -2,68 +2,144 @@ scala_version = "2.11.12"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now scala_version variable is needed due to repositories.bzl file and other usages, so it can be changed in the future.

@lm1nrt lm1nrt marked this pull request as ready for review September 20, 2024 13:42
@lukaszwawrzyk
Copy link

@liucijus @simuons Could you take a look at this PR? It is a first step to improve maven dependency management in rules_scala. It will allow to bump patch versions of scala and add new minor versions faster. Eventually we would like to organize dependencies more, to keep naming consistent, have clear understanding which deps belong into which resolution tree, etc. and have more frequent updates of other dependencies too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants