-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[K/N] Expose program name in runtime #5281
base: master
Are you sure you want to change the base?
Changes from 1 commit
1ff362a
05d57ee
f73045e
fb67427
2703f15
3b66b6b
285dd67
69e660f
a69b027
6d07cf2
2fcf1f0
3c933a7
802c8e7
64ffcfc
2d44f5f
06b0d67
27d7688
fba8ce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class) | ||
|
||
import kotlin.test.* | ||
import kotlin.native.Platform | ||
|
||
fun main(args: Array<String>) { | ||
// Remove path and extension (.kexe or .exe) | ||
val programFileName = Platform.programName.substringAfterLast("/").substringBeforeLast(".") | ||
|
||
assertEquals("program_name", programFileName) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More tests are necessary. For example, the original issue mentions a nice use case:
So checking a case with symbolic link would also be useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added test for that by calling |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ using namespace kotlin; | |
//--- Setup args --------------------------------------------------------------// | ||
|
||
OBJ_GETTER(setupArgs, int argc, const char** argv) { | ||
kotlin::programName = argv[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// The count is one less, because we skip argv[0] which is the binary name. | ||
ObjHeader* result = AllocArrayInstance(theArrayTypeInfo, argc - 1, OBJ_RESULT); | ||
ArrayHeader* array = result->array(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
#include "Porting.h" | ||
#include "Memory.h" | ||
#include "KString.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems unused. |
||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
|
@@ -50,6 +51,8 @@ namespace kotlin { | |
// Returns `true` if initialized. | ||
bool initializeGlobalRuntimeIfNeeded() noexcept; | ||
|
||
extern const char* programName; | ||
|
||
} | ||
|
||
#endif // RUNTIME_RUNTIME_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,12 @@ public object Platform { | |
public val isFreezingEnabled: Boolean | ||
get() = Platform_isFreezingEnabled() | ||
|
||
/** | ||
* Representation of the name used to invoke the program executable. | ||
*/ | ||
public val programName: String | ||
get() = Platform_getProgramName() | ||
SvyatoslavScherbina marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @qurbonzoda could you please review the stdlib change? |
||
|
||
/** | ||
* If the memory leak checker is activated, by default `true` in debug mode, `false` in release. | ||
* When memory leak checker is activated, and leak is detected during last Kotlin context | ||
|
@@ -161,6 +167,9 @@ private external fun Platform_isDebugBinary(): Boolean | |
@GCUnsafeCall("Konan_Platform_isFreezingEnabled") | ||
private external fun Platform_isFreezingEnabled(): Boolean | ||
|
||
@GCUnsafeCall("Konan_Platform_getProgramName") | ||
private external fun Platform_getProgramName(): String | ||
|
||
@GCUnsafeCall("Konan_Platform_getMemoryLeakChecker") | ||
private external fun Platform_getMemoryLeakChecker(): Boolean | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file represents the legacy test infrastructure that we are actively trying to get rid of.
Please create a proper test class in
https://github.com/JetBrains/kotlin/tree/master/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ported the testcase to the new infrastructure.