Skip to content

Commit

Permalink
Added new option to enable or disable task compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulgurance committed Jan 15, 2025
1 parent e5ae904 commit c62b14c
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ISM/CommandLine.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2101,11 +2101,14 @@ module ISM
showTaskCompilationTitleMessage

generateTasksFile(tasks)
buildTasksFile

if Ism.settings.binaryTaskMode
buildTasksFile
end

showCalculationDoneMessage

runTasksFile(logEnabled: true, softwareList: neededSoftwares)
runTasksFile(asBinary: Ism.settings.binaryTaskMode, logEnabled: true, softwareList: neededSoftwares)

rescue error
printSystemCallErrorNotification(error)
Expand All @@ -2115,7 +2118,7 @@ module ISM
def buildTasksFile
processResult = IO::Memory.new

Process.run("CRYSTAL_WORKERS=#{Ism.settings.systemMakeOptions[2..-1]} crystal build --release --progress #{ISM::Default::Filename::Task}.cr -o #{@settings.rootPath}#{ISM::Default::Path::RuntimeDataDirectory}#{ISM::Default::Filename::Task} -f json",
Process.run("CRYSTAL_WORKERS=#{Ism.settings.systemMakeOptions[2..-1]} crystal build --release #{ISM::Default::Filename::Task}.cr -o #{@settings.rootPath}#{ISM::Default::Path::RuntimeDataDirectory}#{ISM::Default::Filename::Task} -f json",
error: processResult,
shell: true,
chdir: "#{@settings.rootPath}#{ISM::Default::Path::RuntimeDataDirectory}") do |process|
Expand All @@ -2141,13 +2144,15 @@ module ISM
exitProgram
end

def runTasksFile(logEnabled = false, softwareList = Array(ISM::SoftwareInformation).new)
def runTasksFile(asBinary = true, logEnabled = false, softwareList = Array(ISM::SoftwareInformation).new)

command = (asBinary ? "./#{ISM::Default::Filename::Task}" : "crystal #{ISM::Default::Filename::Task}.cr")

logIOMemory = IO::Memory.new

logWriter = logEnabled ? IO::MultiWriter.new(STDOUT,logIOMemory) : Process::Redirect::Inherit

process = Process.run( "./#{ISM::Default::Filename::Task}",
process = Process.run( command: command,
output: logWriter,
error: logWriter,
shell: true,
Expand Down
14 changes: 14 additions & 0 deletions ISM/CommandLineSettings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module ISM

#Generic parameters
property secureMode : Bool
property binaryTaskMode : Bool
property installByChroot : Bool
property rootPath : String
property defaultMirror : String
Expand Down Expand Up @@ -60,6 +61,7 @@ module ISM

def initialize( #Generic parameters
@secureMode = ISM::Default::CommandLineSettings::SecureMode,
@binaryTaskMode = ISM::Default::CommandLineSettings::BinaryTaskMode,
@installByChroot = ISM::Default::CommandLineSettings::InstallByChroot,
@rootPath = ISM::Default::CommandLineSettings::RootPath,
@defaultMirror = ISM::Default::CommandLineSettings::DefaultMirror,
Expand Down Expand Up @@ -148,6 +150,7 @@ module ISM

#Generic parameters
secureMode : Bool,
binaryTaskMode : Bool,
installByChroot : Bool,
rootPath : String,
defaultMirror : String,
Expand Down Expand Up @@ -208,6 +211,7 @@ module ISM

settings = {#Generic parameters
"secureMode" => secureMode,
"binaryTaskMode" => binaryTaskMode,
"installByChroot" => installByChroot,
"rootPath" => rootPath,
"defaultMirror" => defaultMirror,
Expand Down Expand Up @@ -275,6 +279,7 @@ module ISM
@rootPath+ISM::Default::CommandLineSettings::SettingsFilePath,
#Generic parameters
ISM::Default::CommandLineSettings::SecureMode,
ISM::Default::CommandLineSettings::BinaryTaskMode,
ISM::Default::CommandLineSettings::InstallByChroot,
ISM::Default::CommandLineSettings::RootPath,
@defaultMirror,
Expand Down Expand Up @@ -338,6 +343,7 @@ module ISM

#Generic parameters
@secureMode,
@binaryTaskMode,
@installByChroot,
@rootPath,
@defaultMirror,
Expand Down Expand Up @@ -701,6 +707,14 @@ module ISM
Ism.exitProgram
end

def setBinaryTaskMode(@binaryTaskMode)
writeSystemConfiguration

rescue error
Ism.printSystemCallErrorNotification(error)
Ism.exitProgram
end

def setInstallByChroot(@installByChroot)
writeSystemConfiguration

Expand Down
1 change: 1 addition & 0 deletions ISM/Default/CommandLineSettings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module ISM

#Generic parameters
SecureMode = true
BinaryTaskMode = true
InstallByChroot = false
RootPath = "/"
DefaultMirror = "Uk"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module ISM

module Default

module Option

module SettingsDisableBinaryTaskMode

ShortText = "-dbtm"
LongText = "disablebinarytaskmode"
Description = "Disable compilation for ism tasks. Task will be interpreted and will start directly, but speed process will be slower."
SetText = "Disable binary task mode"

end

end

end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module ISM

module Default

module Option

module SettingsEnableBinaryTaskMode

ShortText = "-ebtm"
LongText = "enablebinarytaskmode"
Description = "Enable compilation for ism tasks. Improve highly task speed, at cost of compilation time."
SetText = "Enable binary task mode"

end

end

end

end
2 changes: 2 additions & 0 deletions ISM/Default/Option/Settings/Settings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module ISM
#Global options
ISM::Option::SettingsEnableSecureMode.new,
ISM::Option::SettingsDisableSecureMode.new,
ISM::Option::SettingsEnableBinaryTaskMode.new,
ISM::Option::SettingsDisableBinaryTaskMode.new,
ISM::Option::SettingsEnableInstallByChroot.new,
ISM::Option::SettingsDisableInstallByChroot.new,
ISM::Option::SettingsSetRootPath.new,
Expand Down
28 changes: 28 additions & 0 deletions ISM/Option/Settings/DisableBinaryTaskMode/DisableBinaryTaskMode.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module ISM

module Option

class SettingsDisableBinaryTaskMode < ISM::CommandLineOption

def initialize
super( ISM::Default::Option::SettingsDisableBinaryTaskMode::ShortText,
ISM::Default::Option::SettingsDisableBinaryTaskMode::LongText,
ISM::Default::Option::SettingsDisableBinaryTaskMode::Description)
end

def start
if ARGV.size == 2
if !Ism.ranAsSuperUser
Ism.printNeedSuperUserAccessNotification
else
Ism.settings.setBinaryTaskMode(false)
Ism.printProcessNotification(ISM::Default::Option::SettingsDisableBinaryTaskMode::SetText)
end
end
end

end

end

end
28 changes: 28 additions & 0 deletions ISM/Option/Settings/EnableBinaryTaskMode/EnableBinaryTaskMode.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module ISM

module Option

class SettingsEnableBinaryTaskMode < ISM::CommandLineOption

def initialize
super( ISM::Default::Option::SettingsEnableBinaryTaskMode::ShortText,
ISM::Default::Option::SettingsEnableBinaryTaskMode::LongText,
ISM::Default::Option::SettingsEnableBinaryTaskMode::Description)
end

def start
if ARGV.size == 2
if !Ism.ranAsSuperUser
Ism.printNeedSuperUserAccessNotification
else
Ism.settings.setBinaryTaskMode(true)
Ism.printProcessNotification(ISM::Default::Option::SettingsEnableBinaryTaskMode::SetText)
end
end
end

end

end

end
4 changes: 4 additions & 0 deletions RequiredLibraries.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ require "./ISM/Default/Option/Settings/Settings"
require "./ISM/Default/Option/Settings/Show/Show"
require "./ISM/Default/Option/Settings/EnableSecureMode/EnableSecureMode"
require "./ISM/Default/Option/Settings/DisableSecureMode/DisableSecureMode"
require "./ISM/Default/Option/Settings/EnableBinaryTaskMode/EnableBinaryTaskMode"
require "./ISM/Default/Option/Settings/DisableBinaryTaskMode/DisableBinaryTaskMode"
require "./ISM/Default/Option/Settings/EnableInstallByChroot/EnableInstallByChroot"
require "./ISM/Default/Option/Settings/DisableInstallByChroot/DisableInstallByChroot"
require "./ISM/Default/Option/Settings/SetRootPath/SetRootPath"
Expand Down Expand Up @@ -121,6 +123,8 @@ require "./ISM/Option/Settings/Settings"
require "./ISM/Option/Settings/Show/Show"
require "./ISM/Option/Settings/EnableSecureMode/EnableSecureMode"
require "./ISM/Option/Settings/DisableSecureMode/DisableSecureMode"
require "./ISM/Option/Settings/EnableBinaryTaskMode/EnableBinaryTaskMode"
require "./ISM/Option/Settings/DisableBinaryTaskMode/DisableBinaryTaskMode"
require "./ISM/Option/Settings/EnableInstallByChroot/EnableInstallByChroot"
require "./ISM/Option/Settings/DisableInstallByChroot/DisableInstallByChroot"
require "./ISM/Option/Settings/SetRootPath/SetRootPath"
Expand Down

0 comments on commit c62b14c

Please sign in to comment.