Skip to content

Commit

Permalink
chore(config): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chicoxyzzy committed Apr 18, 2023
1 parent 8bebd54 commit 6edce55
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 82 deletions.
3 changes: 1 addition & 2 deletions bin/generate-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,9 @@ export function transform (filename, dest, md) {
'fs/promises.js',
'ipc.js',
'os.js',
'path/path.js',
'peer.js',
'path/path.js',
'process.js',
// 'test/index.js', // add docs for this module
'window.js'
].forEach(file => transform(file, JS_INTERFACE_DIR, 'README.md'))

Expand Down
131 changes: 56 additions & 75 deletions src/cli/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,19 @@ String getSocketHome () {

String getAndroidHome() {
static auto androidHome = getEnv("ANDROID_HOME");
static const bool SSC_DEBUG = (
getEnv("SSC_DEBUG").size() > 0 ||
getEnv("DEBUG").size() > 0
);

if (androidHome.size() > 0)
if (androidHome.size() > 0) {
return androidHome;

if (androidHome.size() == 0) {
androidHome = settings["android_" + platform.os + "_home"];
}

if (androidHome.size() == 0) {
androidHome = settings["android_home"];
}

if (androidHome.size() == 0) {
if (!platform.win) {
auto cmd = String(
"dirname $(dirname $(readlink $(which sdkmanager 2>/dev/null) 2>/dev/null) 2>/dev/null) 2>/dev/null"
);
if (!platform.win) {
auto cmd = String(
"dirname $(dirname $(readlink $(which sdkmanager 2>/dev/null) 2>/dev/null) 2>/dev/null) 2>/dev/null"
);

auto r = exec(cmd);
auto r = exec(cmd);

if (r.exitCode == 0) {
androidHome = trim(r.output);
}
if (r.exitCode == 0) {
androidHome = trim(r.output);
}
}

Expand All @@ -212,6 +198,11 @@ String getAndroidHome() {
setenv("ANDROID_HOME", androidHome.c_str(), 1);
#endif

static const bool SSC_DEBUG = (
getEnv("SSC_DEBUG").size() > 0 ||
getEnv("DEBUG").size() > 0
);

if (SSC_DEBUG) {
log("WARNING: 'ANDROID_HOME' is set to '" + androidHome + "'");
}
Expand Down Expand Up @@ -1269,6 +1260,7 @@ int main (const int argc, const char* argv[]) {

String suffix = "";

// internal
if (flagDebugMode) {
settings["apple_instruments"] = "true";
suffix += "-dev";
Expand All @@ -1277,7 +1269,6 @@ int main (const int argc, const char* argv[]) {
}

settings["debug"] = flagDebugMode;
settings["build_suffix"] = suffix;

std::replace(settings["build_name"].begin(), settings["build_name"].end(), ' ', '_');
settings["build_name"] += suffix;
Expand Down Expand Up @@ -1839,8 +1830,6 @@ int main (const int argc, const char* argv[]) {

// used in multiple if blocks, need to declare here
auto androidEnableStandardNdkBuild = settings["android_enable_standard_ndk_build"] == "true";
auto androidSkipGradle = settings["android_skip_gradle"] == "true";
auto androidBuildSocketRuntime = settings["android_build_socket_runtime"] != "false";

if (flagBuildForAndroid) {
auto bundle_identifier = settings["meta_bundle_identifier"];
Expand Down Expand Up @@ -1913,8 +1902,6 @@ int main (const int argc, const char* argv[]) {
// Windows doesn't support 'yes'
log(("Check licenses and run again: \n" + licenseAccept + "\n").c_str());
}

settings["android_sdk_manager_path"] = sdkmanager.str();

String gradlePath = getEnv("GRADLE_HOME").size() > 0 ? getEnv("GRADLE_HOME") + slash + "bin" + slash : "";

Expand Down Expand Up @@ -2086,6 +2073,7 @@ int main (const int argc, const char* argv[]) {
}
}

// set internal variables used by templating system to generate build.gradle
if (androidEnableStandardNdkBuild) {
settings["android_default_config_external_native_build"].assign(
" externalNativeBuild {\n"
Expand Down Expand Up @@ -2432,6 +2420,7 @@ int main (const int argc, const char* argv[]) {
settings["build_name"] /
settings["build_name"];

// internal settings
settings["linux_executable_path"] = linuxExecPath.string();
settings["linux_icon_path"] = (
Path("/usr") /
Expand All @@ -2445,10 +2434,6 @@ int main (const int argc, const char* argv[]) {

writeFile(pathManifestFile / (settings["build_name"] + ".desktop"), tmpl(gDestkopManifest, settings));

if (settings.count("deb_name") == 0) {
settings["deb_name"] = settings["build_name"];
}

writeFile(pathControlFile / "control", tmpl(gDebianManifest, settings));

auto pathToIconSrc = (targetPath / settings["linux_icon"]).string();
Expand Down Expand Up @@ -2542,6 +2527,7 @@ int main (const int argc, const char* argv[]) {
"AppxManifest.xml"
};

// internal, used in the manifest
if (settings["meta_version"].size() > 0) {
auto version = settings["meta_version"];
auto winversion = split(version, '-')[0];
Expand All @@ -2551,7 +2537,8 @@ int main (const int argc, const char* argv[]) {
settings["win_version"] = "0.0.0.0";
}

settings["exe"] = executable.string();
// internal, a path to win executable, used in the manifest
settings["win_exe"] = executable.string();

writeFile(p, tmpl(gWindowsAppManifest, settings));

Expand Down Expand Up @@ -2850,6 +2837,7 @@ int main (const int argc, const char* argv[]) {
: "generic/platform=iOS";
String deviceType;

// TODO: should be "iPhone Distribution: <name/provisioning specifier>"?
if (settings["ios_codesign_identity"].size() == 0) {
settings["ios_codesign_identity"] = "iPhone Distribution";
}
Expand Down Expand Up @@ -2937,7 +2925,6 @@ int main (const int argc, const char* argv[]) {
auto app = paths.platformSpecificOutputPath / "app";
auto androidHome = getAndroidHome();

StringStream sdkmanager;
StringStream packages;
StringStream gradlew;
String ndkVersion = "25.0.8775105";
Expand All @@ -2948,8 +2935,6 @@ int main (const int argc, const char* argv[]) {
<< "ANDROID_HOME=" << androidHome << " ";
}

sdkmanager << settings["android_sdk_manager_path"];

packages
<< " "
<< quote << "ndk;" << ndkVersion << quote << " "
Expand Down Expand Up @@ -3036,27 +3021,25 @@ int main (const int argc, const char* argv[]) {
}
}

if (androidBuildSocketRuntime) {
fs::create_directories(jniLibs);

ndkBuildArgs
<< ndkBuild.str()
<< " -j"
<< " NDK_PROJECT_PATH=" << _main
<< " NDK_APPLICATION_MK=" << app_mk
<< (flagDebugMode ? " NDK_DEBUG=1" : "")
<< " APP_PLATFORM=" << androidPlatform
<< " NDK_LIBS_OUT=" << jniLibs
;

if (!(debugEnv || verboseEnv)) ndkBuildArgs << " >" << (!platform.win ? "/dev/null" : "NUL") << " 2>&1";

if (debugEnv || verboseEnv) log(ndkBuildArgs.str());
if (std::system(ndkBuildArgs.str().c_str()) != 0) {
log(ndkBuildArgs.str());
log("ERROR: ndk build failed.");
exit(1);
}
fs::create_directories(jniLibs);

ndkBuildArgs
<< ndkBuild.str()
<< " -j"
<< " NDK_PROJECT_PATH=" << _main
<< " NDK_APPLICATION_MK=" << app_mk
<< (flagDebugMode ? " NDK_DEBUG=1" : "")
<< " APP_PLATFORM=" << androidPlatform
<< " NDK_LIBS_OUT=" << jniLibs
;

if (!(debugEnv || verboseEnv)) ndkBuildArgs << " >" << (!platform.win ? "/dev/null" : "NUL") << " 2>&1";

if (debugEnv || verboseEnv) log(ndkBuildArgs.str());
if (std::system(ndkBuildArgs.str().c_str()) != 0) {
log(ndkBuildArgs.str());
log("ERROR: ndk build failed.");
exit(1);
}
}
}
Expand All @@ -3074,28 +3057,26 @@ int main (const int argc, const char* argv[]) {
exit(0);
}

if (!androidSkipGradle) {
String bundle = flagDebugMode ?
localDirPrefix + "gradlew :app:bundleDebug --warning-mode all" :
localDirPrefix + "gradlew :app:bundle";
String bundle = flagDebugMode ?
localDirPrefix + "gradlew :app:bundleDebug --warning-mode all" :
localDirPrefix + "gradlew :app:bundle";

if (debugEnv || verboseEnv) log(bundle);
if (std::system(bundle.c_str()) != 0) {
log("ERROR: failed to invoke " + bundle + " command.");
exit(1);
}
if (debugEnv || verboseEnv) log(bundle);
if (std::system(bundle.c_str()) != 0) {
log("ERROR: failed to invoke " + bundle + " command.");
exit(1);
}

// clear stream
gradlew.str("");
gradlew
<< localDirPrefix
<< "gradlew assemble";
// clear stream
gradlew.str("");
gradlew
<< localDirPrefix
<< "gradlew assemble";

if (debugEnv || verboseEnv) log(gradlew.str());
if (std::system(gradlew.str().c_str()) != 0) {
log("ERROR: failed to invoke `gradlew assemble` command");
exit(1);
}
if (debugEnv || verboseEnv) log(gradlew.str());
if (std::system(gradlew.str().c_str()) != 0) {
log("ERROR: failed to invoke `gradlew assemble` command");
exit(1);
}

if (flagBuildForAndroidEmulator) {
Expand Down
13 changes: 8 additions & 5 deletions src/cli/templates.hh
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Comment={{meta_description}}
Categories={{linux_categories}};
)INI";
constexpr auto gDebianManifest = R"DEB(Package: {{deb_name}}
constexpr auto gDebianManifest = R"DEB(Package: {{build_name}}
Version: {{meta_version}}
Architecture: amd64
Maintainer: {{meta_maintainer}}
Expand Down Expand Up @@ -389,7 +389,7 @@ constexpr auto gWindowsAppManifest = R"XML(<?xml version="1.0" encoding="utf-8"?
<Application
Id="{{build_name}}"
EntryPoint="Windows.FullTrustApplication"
Executable="{{exe}}"
Executable="{{win_exe}}"
>
<uap:VisualElements DisplayName="{{meta_title}}"
Square150x150Logo="{{win_logo}}"
Expand All @@ -403,10 +403,10 @@ constexpr auto gWindowsAppManifest = R"XML(<?xml version="1.0" encoding="utf-8"?
<uap3:Extension
Category="windows.appExecutionAlias"
EntryPoint="Windows.FullTrustApplication"
Executable="{{exe}}"
Executable="{{win_exe}}"
>
<uap3:AppExecutionAlias>
<desktop:ExecutionAlias Alias="{{exe}}" />
<desktop:ExecutionAlias Alias="{{win_exe}}" />
</uap3:AppExecutionAlias>
</uap3:Extension>
</Extensions>
Expand All @@ -415,7 +415,7 @@ constexpr auto gWindowsAppManifest = R"XML(<?xml version="1.0" encoding="utf-8"?
</Applications>
<Extensions>
<desktop2:Extension Category="windows.firewallRules">
<desktop2:FirewallRules Executable="{{exe}}">
<desktop2:FirewallRules Executable="{{win_exe}}">
<desktop2:Rule
Direction="in"
IPProtocol="TCP"
Expand Down Expand Up @@ -1427,6 +1427,9 @@ version = 1.0.0
; TODO description needed
main_activity = ""
; TODO description needed
; home = ""
[ios]
Expand Down

0 comments on commit 6edce55

Please sign in to comment.