Skip to content
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

Refactor build scripts #962

Merged
merged 14 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move architecture check to function. Remove currentOS variable.
  • Loading branch information
VDovidaytis-HORIS committed Dec 8, 2023
commit 07a9f1a6ff4d07d125841330ec6993230f020a8d
50 changes: 24 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ allprojects {
}
}

project.ext.currentOs = DefaultNativePlatform.getCurrentOperatingSystem()

// Read build settings from commandline parameters (for build_release.py script):
def readSettingsFromParameters() {
def settings = [
Expand Down Expand Up @@ -85,13 +83,30 @@ def readSettingsFromYaml() {
throw new GradleException("Couldn't read build_settings.yml")
}
def settings = new Yaml().load(build_settings_file.newInputStream())
if (!project.currentOs.windows) {
assert settings.architecture != null // Skip architecture property for Windows systems.
if (!DefaultNativePlatform.getCurrentOperatingSystem().windows) {
assert settings.architecture != null // Windows only 64bit version can be builе, so the arch parameter is not needed and may not be set.
}

if (settings.enable_python_package) {
assert settings.python.bin_path != null
assert settings.python.include_path != null

if (!DefaultNativePlatform.getCurrentOperatingSystem().windows) {
def getArchOutput = new ByteArrayOutputStream()
exec {
commandLine "${settings.python.bin_path}/python",
"-c",
"import platform; print(platform.machine())"
standardOutput = getArchOutput
}
def currentPythonArch = getArchOutput.toString().trim()

if (currentPythonArch != settings.architecture) {
throw new IllegalArgumentException("Project and Python architectures don't match!\n" +
" - Value, from your 'build_settings.yml' file: ${settings.architecture}\n" +
" - Your Python architecture: ${currentPythonArch}\n" +
"Check your 'build_settings.yml' file.")
}
}
}
return settings
}
Expand All @@ -104,23 +119,6 @@ if (project.hasProperty("build_release")) {
project.ext.buildSettings = readSettingsFromYaml() as LinkedHashMap
}

// Check architecture parameter, if python-package has been enabled (skipped for Windows):
if (project.buildSettings.enable_python_package && !project.currentOs.windows) {
def getArchOutput = new ByteArrayOutputStream()
exec {
commandLine "${project.buildSettings.python.bin_path}/python",
"-c",
"import platform; print(platform.machine())"
standardOutput = getArchOutput
}
def currentPythonArch = getArchOutput.toString().trim()

if (currentPythonArch != project.buildSettings.architecture) {
throw new Exception("Project and Python architectures don't match!\n" +
"You have enabled python-package and your architecture value from project settings doesn't match\n" +
"your Python architecture. Check these settings in your 'build_settings.yml' file.")
}
}

// Maven publication settings
// define local Maven Repository path:
Expand Down Expand Up @@ -170,23 +168,23 @@ subprojects {
apply plugin: "org.jetbrains.kotlin.multiplatform"

kotlin {
if (project.currentOs.macOsX & project.buildSettings.architecture == "x86_64") {
if (DefaultNativePlatform.getCurrentOperatingSystem().macOsX & project.buildSettings.architecture == "x86_64") {
macosX64()
} else if (project.currentOs.macOsX & project.buildSettings.architecture == "arm64") {
} else if (DefaultNativePlatform.getCurrentOperatingSystem().macOsX & project.buildSettings.architecture == "arm64") {
if (project.hasProperty("build_release")) {
macosX64()
macosArm64()
} else {
macosArm64()
}
} else if (project.currentOs.linux) {
} else if (DefaultNativePlatform.getCurrentOperatingSystem().linux) {
if (project.hasProperty("build_release")) {
linuxX64()
linuxArm64()
} else if (project.buildSettings.architecture == "x86_64") {
linuxX64()
}
} else if (project.currentOs.windows) {
} else if (DefaultNativePlatform.getCurrentOperatingSystem().windows) {
mingwX64()
} else {
throw new Exception("Unsupported platform! Check project settings.")
Expand Down
11 changes: 6 additions & 5 deletions python-extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ plugins {
id "org.jetbrains.kotlin.multiplatform"
}

import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

kotlin {

if (project.buildSettings.enable_python_package) {

def target
if (project.currentOs.macOsX & project.buildSettings.architecture == "x86_64") {
if (DefaultNativePlatform.getCurrentOperatingSystem().macOsX & project.buildSettings.architecture == "x86_64") {
target = macosX64("native")
} else if (project.currentOs.macOsX & project.buildSettings.architecture == "arm64") {
} else if (DefaultNativePlatform.getCurrentOperatingSystem().macOsX & project.buildSettings.architecture == "arm64") {
target = macosArm64("native")
} else if (project.currentOs.linux & project.buildSettings.architecture == "x86_64") {
} else if (DefaultNativePlatform.getCurrentOperatingSystem().linux & project.buildSettings.architecture == "x86_64") {
target = linuxX64("native")
} else if (project.currentOs.linux & project.buildSettings.architecture == "arm64") {
} else if (DefaultNativePlatform.getCurrentOperatingSystem().linux & project.buildSettings.architecture == "arm64") {
target = linuxArm64("native")
} else if (project.currentOs.windows) {
} else if (DefaultNativePlatform.getCurrentOperatingSystem().windows) {
target = mingwX64("native")
} else {
throw new Exception("Unsupported platform! Check project settings.")
Expand Down