diff --git a/docs/language-profilers.md b/docs/language-profilers.md index 24eb957..935949d 100644 --- a/docs/language-profilers.md +++ b/docs/language-profilers.md @@ -27,7 +27,10 @@ looks for `rc-profiler-typescript`, then `runtimeconditions-typescript-profiler` `rc-profiler-java`, or `runtimeconditions-python-profiler`, on `PATH`; `RC_TYPESCRIPT_PROFILER`, `RC_JAVA_PROFILER`, or `RC_PYTHON_PROFILER` can name an absolute path instead. It runs the add-on only if `--version --json` lists the core profile schema -`rc` targets (0.4.0). The add-on's output and exit status pass through. +`rc` targets (0.4.0). The add-on's output and exit status pass through. When `rc` +invokes an add-on, it sets `RC_COMMAND_PREFIX` in its environment (for example +`rc profile typescript`), so the add-on's usage text and diagnostics can suggest +commands the user can copy directly. The Java launcher chooses the JDK, not `rc`: `RC_JAVA_HOME`, then `JAVA_HOME`, then the runtime bundled in its system package, then `java` on `PATH`. It needs JDK 17 or newer and diff --git a/internal/cli/plugins.go b/internal/cli/plugins.go index 41b155d..d35757d 100644 --- a/internal/cli/plugins.go +++ b/internal/cli/plugins.go @@ -78,8 +78,9 @@ func newLanguageCommand(language plugins.Language, deps Dependencies) *cobra.Com return fmt.Errorf("the %s profiler %s at %s supports core profile schema %s, but this rc targets %s; install a matching version with: %s", language.Display, info.Version, found.Path, strings.Join(info.CoreSchemas, ", "), coreSchemaVersion, language.InstallHint) } + env := append(os.Environ(), "RC_COMMAND_PREFIX="+cmd.CommandPath()) code, err := deps.Runner.Run(ctx, process.Spec{ - Path: found.Path, Args: args, + Path: found.Path, Args: args, Env: env, Stdin: cmd.InOrStdin(), Stdout: cmd.OutOrStdout(), Stderr: cmd.ErrOrStderr(), }) if err != nil { diff --git a/internal/cli/plugins_test.go b/internal/cli/plugins_test.go index 495e554..41f2e7d 100644 --- a/internal/cli/plugins_test.go +++ b/internal/cli/plugins_test.go @@ -74,6 +74,9 @@ func TestAddOnReceivesItsArgumentsUnchangedAndItsOutputPassesThrough(t *testing. if len(runner.calls) != 1 || runner.calls[0].Path != "/usr/bin/rc-profiler-typescript" || !slices.Equal(runner.calls[0].Args, args) { t.Fatalf("calls %+v", runner.calls) } + if !slices.Contains(runner.calls[0].Env, "RC_COMMAND_PREFIX=rc profile typescript") { + t.Fatalf("expected RC_COMMAND_PREFIX in env, got: %v", runner.calls[0].Env) + } } func TestAddOnHelpAndVersionFlagsReachTheAddOn(t *testing.T) { @@ -240,6 +243,9 @@ func TestJavaAddOnReceivesItsArgumentsUnchangedAndItsOutputPassesThrough(t *test if len(runner.calls) != 1 || runner.calls[0].Path != "/usr/bin/rc-profiler-java" || !slices.Equal(runner.calls[0].Args, args) { t.Fatalf("calls: %+v", runner.calls) } + if !slices.Contains(runner.calls[0].Env, "RC_COMMAND_PREFIX=rc profile java") { + t.Fatalf("expected RC_COMMAND_PREFIX in env, got: %v", runner.calls[0].Env) + } } func TestJavaAddOnThatIsNotInstalledSaysHowToGetIt(t *testing.T) { @@ -272,6 +278,9 @@ func TestPythonAddOnReceivesItsArgumentsUnchangedAndItsOutputPassesThrough(t *te if len(runner.calls) != 1 || runner.calls[0].Path != "/usr/bin/runtimeconditions-python-profiler" || !slices.Equal(runner.calls[0].Args, args) { t.Fatalf("calls: %+v", runner.calls) } + if !slices.Contains(runner.calls[0].Env, "RC_COMMAND_PREFIX=rc profile python") { + t.Fatalf("expected RC_COMMAND_PREFIX in env, got: %v", runner.calls[0].Env) + } } func TestPythonAddOnThatIsNotInstalledSaysHowToGetIt(t *testing.T) {