Skip to content

Commit

Permalink
bazel_8: init at 8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
boltzmannrain committed Dec 12, 2024
1 parent 9bb136e commit eee2b3a
Show file tree
Hide file tree
Showing 11 changed files with 1,089 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.google.devtools.build.lib.runtime;

// We only need to capture enough details from Bazel source code
// to make our modules compile and be binary-compatible.
// This BlazeModule won't be injected into Bazel classpath.
public abstract class BlazeModule {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.google.devtools.build.lib.platform;

import com.google.devtools.build.lib.runtime.BlazeModule;

// This class can fail in Nix sandbox on Darwin so we replace
// it with a stub version
public final class SleepPreventionModule extends BlazeModule {
// do nothing
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.google.devtools.build.lib.platform;

import com.google.devtools.build.lib.runtime.BlazeModule;

// This class can fail in Nix sandbox on Darwin so we replace
// it with a stub version
public final class SystemSuspensionModule extends BlazeModule {
// do nothing

// this method is part of module interface
synchronized void suspendCallback(int reason) {
// do nothing
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
stdenv,
buildJdk,
runJdk,
version,
writeScript,
}:
let
fakeBazelModules = stdenv.mkDerivation {
pname = "fakeBazelModules";
inherit version;
dontUnpack = true;
buildPhase = "
# Java file name needs to match class name so we need to copy
cp ${./BlazeModule.java} ./BlazeModule.java
cp ${./SystemSuspensionModule.java} ./SystemSuspensionModule.java
cp ${./SleepPreventionModule.java} ./SleepPreventionModule.java
# compile all sources
${buildJdk}/bin/javac -d . BlazeModule.java SystemSuspensionModule.java SleepPreventionModule.java
# don't package BlazeModule.class as we want to use real base class, but a stub compatible version was needed to make
# fake modules compile
${buildJdk}/bin/jar cf output.jar ./com/google/devtools/build/lib/platform/{SystemSuspension,SleepPrevention}Module.class
";
installPhase = ''
runHook preInstall
mkdir -p $out/
install -Dm755 output.jar $out/output.jar
runHook postInstall
'';

};
# bin/java wrapper that injects fake modules into classpath
jvmInterceptSh = writeScript "java" ''
#!/usr/bin/env bash
# replaces
# .. -jar foo.jar ..
# with
# .. -cp ..overrides..:foo.jar MainClass ..
# to inject fake modules classes into Bazel
for (( i=2; i <= "$#"; i++ )); do
if [[ "''${!i}" == "-jar" ]]; then
prev=$(( i - 1 ))
jar=$(( i + 1 ))
MAIN_CLASS=$(unzip -qc "''${!jar}" META-INF/MANIFEST.MF | grep "^Main-Class: " | cut -d " " -f 2- | tr -d "\r")
next=$(( jar + 1 ))
exec "${runJdk}/bin/java" "''${@:1:prev}" -cp "${fakeBazelModules}/output.jar:''${!jar}" "$MAIN_CLASS" "''${@:next}"
fi
done
echo "Failed to find -jar argument in: $@" >&2
exit 1
'';
in
{
jvmIntercept = stdenv.mkDerivation {
pname = "jvmIntercept";
inherit version;
dontUnpack = true;
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install -Dm755 ${jvmInterceptSh} $out/bin/java
runHook postInstall
'';
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
diff --git a/src/main/native/darwin/sleep_prevention_jni.cc b/src/main/native/darwin/sleep_prevention_jni.cc
index 67c35b201e..e50a58320e 100644
--- a/src/main/native/darwin/sleep_prevention_jni.cc
+++ b/src/main/native/darwin/sleep_prevention_jni.cc
@@ -33,31 +33,13 @@ static int g_sleep_state_stack = 0;
static IOPMAssertionID g_sleep_state_assertion = kIOPMNullAssertionID;

int portable_push_disable_sleep() {
- std::lock_guard<std::mutex> lock(g_sleep_state_mutex);
- BAZEL_CHECK_GE(g_sleep_state_stack, 0);
- if (g_sleep_state_stack == 0) {
- BAZEL_CHECK_EQ(g_sleep_state_assertion, kIOPMNullAssertionID);
- CFStringRef reasonForActivity = CFSTR("build.bazel");
- IOReturn success = IOPMAssertionCreateWithName(
- kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, reasonForActivity,
- &g_sleep_state_assertion);
- BAZEL_CHECK_EQ(success, kIOReturnSuccess);
- }
- g_sleep_state_stack += 1;
- return 0;
+ // Unreliable, disable for now
+ return -1;
}

int portable_pop_disable_sleep() {
- std::lock_guard<std::mutex> lock(g_sleep_state_mutex);
- BAZEL_CHECK_GT(g_sleep_state_stack, 0);
- g_sleep_state_stack -= 1;
- if (g_sleep_state_stack == 0) {
- BAZEL_CHECK_NE(g_sleep_state_assertion, kIOPMNullAssertionID);
- IOReturn success = IOPMAssertionRelease(g_sleep_state_assertion);
- BAZEL_CHECK_EQ(success, kIOReturnSuccess);
- g_sleep_state_assertion = kIOPMNullAssertionID;
- }
- return 0;
+ // Unreliable, disable for now
+ return -1;
}

} // namespace blaze_jni
diff --git a/src/main/native/darwin/system_suspension_monitor_jni.cc b/src/main/native/darwin/system_suspension_monitor_jni.cc
index 3483aa7935..51782986ec 100644
--- a/src/main/native/darwin/system_suspension_monitor_jni.cc
+++ b/src/main/native/darwin/system_suspension_monitor_jni.cc
@@ -83,10 +83,7 @@ void portable_start_suspend_monitoring() {
// Register to receive system sleep notifications.
// Testing needs to be done manually. Use the logging to verify
// that sleeps are being caught here.
- suspend_state.connect_port = IORegisterForSystemPower(
- &suspend_state, &notifyPortRef, SleepCallBack, &notifierObject);
- BAZEL_CHECK_NE(suspend_state.connect_port, MACH_PORT_NULL);
- IONotificationPortSetDispatchQueue(notifyPortRef, queue);
+ // XXX: Unreliable, disable for now

// Register to deal with SIGCONT.
// We register for SIGCONT because we can't catch SIGSTOP.
Loading

0 comments on commit eee2b3a

Please sign in to comment.