diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9ecdb9634a72..ee04c39847e4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -492,7 +492,7 @@ jobs: - name: Generate Website run: | - ./project/scripts/genDocs -doc-snapshot + ./project/scripts/genDocs - name: Deploy Website uses: peaceiris/actions-gh-pages@v3 diff --git a/project/Build.scala b/project/Build.scala index 794488d9b1ce..8e7805f143aa 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1219,6 +1219,9 @@ object Build { val generateSelfDocumentation = taskKey[Unit]("Generate example documentation") // Note: the two tasks below should be one, but a bug in Tasty prevents that val generateScalaDocumentation = inputKey[Unit]("Generate documentation for dotty lib") + val getJarsForScaladoc = taskKey[Seq[String]]("Get jars for scaladoc") + val getDocRootForScaladoc = taskKey[Path]("Get doc root content file for scaladol") + val copyTheScaladocInputs = inputKey[Unit]("Copy sources to be provided to the scaladoc") val generateTestcasesDocumentation = taskKey[Unit]("Generate documentation for testcases, usefull for debugging tests") lazy val `scaladoc-testcases` = project.in(file("scaladoc-testcases")). @@ -1320,46 +1323,65 @@ object Build { "scaladoc", "scaladoc/output/self", VersionUtil.gitHash ) }.value, + generateScalaDocumentation := Def.inputTaskDyn { val extraArgs = spaceDelimited("[output]").parsed val dest = file(extraArgs.headOption.getOrElse("scaladoc/output/scala3")).getAbsoluteFile + val roots = extraArgs.lift(1).map(Seq(_)).getOrElse(getJarsForScaladoc.value) + val docRootFile = extraArgs.lift(2).getOrElse(getDocRootForScaladoc.value) val majorVersion = (LocalProject("scala3-library-bootstrapped") / scalaBinaryVersion).value + val isDefined = extraArgs.isDefinedAt(2) + if (roots.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") } + else Def.task { + if (!isDefined) { + IO.write(dest / "versions" / "latest-nightly-base", majorVersion) + + // This file is used by GitHub Pages when the page is available in a custom domain + IO.write(dest / "CNAME", "dotty.epfl.ch") + } + }.dependsOn(generateDocumentation( + roots, "Scala 3", dest.getAbsolutePath, "master", + Seq( + "-comment-syntax", "wiki", + "-siteroot", "docs", + s"-source-links:docs=github://lampepfl/dotty/master#docs", + "-doc-root-content", docRootFile.toString, + "-Ydocument-synthetic-types", + "-versions-dictionary-url", "http://127.0.0.1:5500/docs/_site/versions.json" + ), usingScript = false + )) + }.evaluated, + getJarsForScaladoc := Def.task { val dottyJars: Seq[java.io.File] = Seq( (`stdlib-bootstrapped`/Compile/products).value, (`scala3-interfaces`/Compile/products).value, (`tasty-core-bootstrapped`/Compile/products).value, ).flatten + dottyJars.map(_.getAbsolutePath) + }.value, - val roots = dottyJars.map(_.getAbsolutePath) - + getDocRootForScaladoc := Def.task { val managedSources = (`stdlib-bootstrapped`/Compile/sourceManaged).value / "scala-library-src" val projectRoot = (ThisBuild/baseDirectory).value.toPath val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize()) - val docRootFile = stdLibRoot.resolve("rootdoc.txt") - - val dottyManagesSources = - (`stdlib-bootstrapped`/Compile/sourceManaged).value / "dotty-library-src" - - val dottyLibRoot = projectRoot.relativize(dottyManagesSources.toPath.normalize()) + stdLibRoot.resolve("rootdoc.txt") + }.value, - if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") } - else Def.task{ - IO.write(dest / "versions" / "latest-nightly-base", majorVersion) + copyTheScaladocInputs := Def.inputTask { + val extraArgs = spaceDelimited("[output]").parsed + val dest = extraArgs.lift(0).getOrElse("output") + val ref = extraArgs.lift(1).getOrElse("0.0.0") + val jars = getJarsForScaladoc.value.foreach { jar => + val file = new File(jar) + val d = new File(s"$dest/$ref") + sbt.IO.copyDirectory(file, d) + } - // This file is used by GitHub Pages when the page is available in a custom domain - IO.write(dest / "CNAME", "dotty.epfl.ch") - }.dependsOn(generateDocumentation( - roots, "Scala 3", dest.getAbsolutePath, "master", - Seq( - "-comment-syntax", "wiki", - "-siteroot", "docs", - s"-source-links:docs=github://lampepfl/dotty/master#docs", - "-doc-root-content", docRootFile.toString, - "-Ydocument-synthetic-types" - ), usingScript = false - )) + val path = getDocRootForScaladoc.value + val d = new File(s"$dest/$ref.txt") + sbt.IO.copyFile(path.toFile, d) }.evaluated, generateTestcasesDocumentation := Def.taskDyn { diff --git a/project/scripts/docs/docs.csv b/project/scripts/docs/docs.csv new file mode 100644 index 000000000000..4b86fab214dd --- /dev/null +++ b/project/scripts/docs/docs.csv @@ -0,0 +1 @@ +3.0.X,4de0df4bc4a diff --git a/project/scripts/docs/docs.sh b/project/scripts/docs/docs.sh new file mode 100755 index 000000000000..0e231a159855 --- /dev/null +++ b/project/scripts/docs/docs.sh @@ -0,0 +1,18 @@ +#!/bin/bash +INPUT=./project/scripts/docs/docs.csv +OLDIFS=$IFS +IFS=',' +[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } + +echo '{"versions":{' + +while read label ref +do + # echo "\"$label\": \"https://dotty.epfl.ch/$ref/docs/index.html\",", + echo "\"$label\": \"http://127.0.0.1:5500/docs/_site/$ref/docs/index.html\"," +done < $INPUT +IFS=$OLDIFS +# echo '"Nightly": "https://dotty.epfl.ch/docs/index.html",' +echo '"Nightly": "http://127.0.0.1:5500/docs/_site/docs/index.html"' +echo '}}' + diff --git a/project/scripts/genDocs b/project/scripts/genDocs index aa061d59b613..75df7d9e5d91 100755 --- a/project/scripts/genDocs +++ b/project/scripts/genDocs @@ -4,35 +4,75 @@ set -e shopt -s extglob # needed for rm everything but x echo "Working directory: $PWD" -GENDOC_EXTRA_ARGS=$@ GIT_HEAD=$(git rev-parse HEAD) # save current head for commit message in gh-pages PREVIOUS_SNAPSHOTS_DIR="$PWD/../prev_snapshots" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)" SITE_OUT_DIR="$PWD/docs/_site" +# Load the csv data into memory + +INPUT=./project/scripts/docs/docs.csv +[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } +CSV_FILE=$(<"$INPUT") + + ### Obtain the previous versions of the website ### if [ -d "$PREVIOUS_SNAPSHOTS_DIR" ]; then rm -rf "$PREVIOUS_SNAPSHOTS_DIR" fi mkdir -pv "$PREVIOUS_SNAPSHOTS_DIR" -git remote add doc-remote "https://github.com/lampepfl/dotty-website.git" +# git remote add doc-remote "https://github.com/lampepfl/dotty-website.git" git fetch doc-remote gh-pages git checkout gh-pages (cp -vr [03].*/ "$PREVIOUS_SNAPSHOTS_DIR"; true) # Don't fail if no `3.*` found to copy -git checkout "$GIT_HEAD" -### Generate the current snapshot of the website ### -# this command will generate docs in $PWD/docs/_site + +### Gather tasty files for new scaladoc different versions + SBT="$SCRIPT_DIR/sbt" + +# We iterate over csv to checkout for different versions and generate their jars respectively. + +OLDIFS=$IFS +IFS=',' + +OUTPUT_DIR="output" # output for cumulutative tasty files for previous versions for + + +# Firstly iterate over each version and generato sources +while read label ref +do + git checkout "$ref" + "$SBT" "scaladoc/copyTheScaladocInputs $OUTPUT_DIR $ref" +done <<< $CSV_FILE + +git checkout "$GIT_HEAD" + +# Let's start with generating latest docs for nightly "$SBT" "scaladoc/generateScalaDocumentation docs/_site" -# make sure that the previous command actually succeeded +# make sure that sbt command actually succeeded if [ ! -d "$SITE_OUT_DIR" ]; then echo "Output directory did not exist: $SITE_OUT_DIR" 1>&2 exit 1 fi +# Iterate once again and generate scaladoc for additional older versions +while read label ref +do + # Generate the website + # this command will generate docs in $PWD/docs/_site/$ref + "$SBT" "scaladoc/generateScalaDocumentation docs/_site/$ref $OUTPUT_DIR $ref" +done <<< $CSV_FILE + +IFS=$OLDIFS + +# Generate json file + +touch "docs/_site/versions.json" +sh ./project/scripts/docs/docs.sh > "docs/_site/versions.json" + ### Move previous versions' snapshots to _site ### mv -v "$PREVIOUS_SNAPSHOTS_DIR"/* "$SITE_OUT_DIR" rm -rf "$PREVIOUS_SNAPSHOTS_DIR"