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

Quick fix for script #795

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions nix/pkgs/mill-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ let
mill
] ++ (args.nativeBuildInputs or [ ]);

impureEnvVars = [ "JAVA_OPTS" ];
impureEnvVars = [ "https_proxy" "JAVA_OPTS" ];

buildPhase = ''
runHook preBuild

export JAVA_OPTS="-Duser.home=$TMPDIR $JAVA_OPTS"

if [[ -z "$https_proxy" && ! "proxyHost" =~ "$JAVA_OPTS" ]]; then
_https_proxy="''${https_proxy#http://}"
_https_proxy="''${_https_proxy#https://}"
_https_proxy_parts=(''${_https_proxy//:/ })
_host=''${_https_proxy_parts[0]}
_port=''${_https_proxy_parts[1]}
export JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=$_host -Dhttp.proxyPort=$_port -Dhttps.proxyHost=$_host -Dhttps.proxyPort=$_port"
fi

# Use "https://repo1.maven.org/maven2/" only to keep dependencies integrity
export COURSIER_REPOSITORIES="central"

Expand All @@ -32,7 +42,10 @@ let
# And we don't want to wait too long for a dependencies task, so here is the solution:
# "checkFormat" the "build.sc" file so that mill will download scalafmt for us,
# and we don't need to wait too long for formatting.
mill -i mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll buildSources
if ! mill -i mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll buildSources; then
echo "[ERROR] build.sc is misformatted, please run 'mill -i mill.scalalib.scalafmt.ScalafmtModule/reformatAll buildSources'" >&2
exit 1
fi

runHook postBuild
'';
Expand Down
11 changes: 7 additions & 4 deletions script/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import mill.scalalib.TestModule.Utest
import mill.util.Jvm
import coursier.maven.MavenRepository

trait ScriptModule extends ScalaModule {
// Required for scalafmt to recognize which file to format
def buildSources = T.sources(os.pwd / "build.sc")

trait ScriptModule extends ScalaModule with ScalafmtModule {
val scala3 = "3.3.3"
val mainargs = ivy"com.lihaoyi::mainargs:0.5.0"
val oslib = ivy"com.lihaoyi::os-lib:0.10.0"
val upickle = ivy"com.lihaoyi::upickle:3.3.1"

def scalaVersion = scala3
def scalacOptions = Seq("-new-syntax", "-deprecation")
override def ivyDeps = Agg(mainargs, oslib, upickle)
def scalaVersion = scala3
def scalacOptions = Seq("-new-syntax", "-deprecation")
override def ivyDeps = Agg(mainargs, oslib, upickle)
}

object emu extends ScriptModule {}
Expand Down
3 changes: 1 addition & 2 deletions script/ci/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ object Main:
"## Cycle Update\n"
)

if urgReportFilePath.nonEmpty then
os.write(os.Path(urgReportFilePath.get, os.pwd), "# Coverage report\n")
if urgReportFilePath.nonEmpty then os.write(os.Path(urgReportFilePath.get, os.pwd), "# Coverage report\n")

os.walk(os.pwd / ".github" / caseDir)
.filter(_.last == "default.json")
Expand Down
15 changes: 14 additions & 1 deletion script/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let
fileset = unions [
scriptSrc
./build.sc
./.scalafmt.conf
];
};

Expand All @@ -28,9 +29,10 @@ let
root = ./.;
fileset = unions [
./build.sc
./.scalafmt.conf
];
};
millDepsHash = "sha256-QQ5gCbvovC55t9MmfCNTvNFdD6FcNqmLmfhT9qJhQQc=";
millDepsHash = "sha256-y8tAFwctiU6ehghuf7KP73DuWCGCnAAdIXOIPwT+QOo=";
};

passthru.withLsp = self.overrideAttrs (old: {
Expand Down Expand Up @@ -58,15 +60,26 @@ let
];

buildPhase = ''
runHook preBuild

echo "Checking format"
mill -i ${moduleName}.checkFormat

echo "Building JAR"
mill -i ${moduleName}.assembly
echo "Running native-image"
native-image --no-fallback -jar out/${moduleName}/assembly.dest/out.jar "$name.elf"

runHook postBuild
'';

installPhase = ''
runHook preInstall

mkdir -p "$out"/bin
cp "$name.elf" "$out"/bin/"${outName}"

runHook postInstall
'';

meta.mainProgram = toString outName;
Expand Down
8 changes: 6 additions & 2 deletions script/emu/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ object Main:
name = "dry-run",
doc = "Print the final emulator command line and exit"
) dryRun: Flag = Flag(false),
@arg(
name = "timeout",
doc = "Specify maximum cycle count limit"
) timeout: Option[Int] = None,
leftOver: Leftover[String]
): Unit =
if leftOver.value.isEmpty then Logger.fatal("No test case name")
Expand Down Expand Up @@ -204,6 +208,7 @@ object Main:
emulator.toString(),
s"+t1_elf_file=${caseElfPath}"
)
++ optionals(timeout.isDefined, Seq(s"+t1_timeout=${timeout.getOrElse("unreachable")}"))
++ optionals(isTrace, Seq(s"+t1_wave_path=${outputPath / "wave.fsdb"}"))
++ optionals(isCover, Seq(s"-cm assert"))
++ optionals(!leftOverArguments.isEmpty, leftOverArguments)
Expand Down Expand Up @@ -266,8 +271,7 @@ object Main:
os.move(os.pwd / "cm.vdb", outputPath / "cm.vdb", replaceExisting = true)
os.move(os.pwd / "cm.log", outputPath / "cm.log", replaceExisting = true)
Logger.info(s"Coverage database saved under ${outputPath}/cm.vdb")
else
Logger.error("No cm.vdb cm.log found")
else if !finalEmuType.get.startsWith("verilator-emu") then Logger.error("No cm.vdb cm.log found")

if os.exists(os.pwd / "perf.json") then
os.move(os.pwd / "perf.json", outputPath / "perf.json", replaceExisting = true)
Expand Down
Loading