-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bb136e
commit eee2b3a
Showing
11 changed files
with
1,089 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
pkgs/development/tools/build-managers/bazel/bazel_8/darwin_hacks/BlazeModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
9 changes: 9 additions & 0 deletions
9
pkgs/development/tools/build-managers/bazel/bazel_8/darwin_hacks/SleepPreventionModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
15 changes: 15 additions & 0 deletions
15
pkgs/development/tools/build-managers/bazel/bazel_8/darwin_hacks/SystemSuspensionModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
75 changes: 75 additions & 0 deletions
75
pkgs/development/tools/build-managers/bazel/bazel_8/darwin_hacks/default.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
''; | ||
}; | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
pkgs/development/tools/build-managers/bazel/bazel_8/darwin_sleep.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ¬ifyPortRef, SleepCallBack, ¬ifierObject); | ||
- 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. |
Oops, something went wrong.