# The C code is generated, compile it to an executable
fun compile_c_code(compile_dir: String)
do
var makename = makefile_name
var makeflags = self.toolcontext.opt_make_flags.value
if makeflags == null then makeflags = ""
var command = "make -B -C {compile_dir} -f {makename} -j 4 {makeflags}"
self.toolcontext.info(command, 2)
var res
if self.toolcontext.verbose_level >= 3 then
res = sys.system("{command} 2>&1")
else if is_windows then
res = sys.system("{command} 2>&1 >nul")
else
res = sys.system("{command} 2>&1 >/dev/null")
end
if res != 0 then
toolcontext.error(null, "Compilation Error: `make` failed with error code: {res}. The command was `{command}`.")
end
end
src/compiler/abstract_compiler.nit:576,2--598,4
redef fun compile_c_code(compile_dir)
do
var android_project_root = android_project_root.as(not null)
var release = toolcontext.opt_release.value
# Compile C and Java code into an APK file
var verb = if release then "assembleRelease" else "assembleDebug"
var args = [gradlew_dir/"gradlew", verb, "-p", android_project_root]
if toolcontext.opt_verbose.value <= 1 then args.add "-q"
toolcontext.exec_and_check(args, "Android project error")
# Move the APK to the target
var outname = outfile(compiler.mainmodule)
if release then
var apk_path = "{android_project_root}/app/build/outputs/apk/release/app-release-unsigned.apk"
# Sign APK
var keystore_path= "KEYSTORE".environ
var key_alias= "KEY_ALIAS".environ
var tsa_server= "TSA_SERVER".environ
if key_alias.is_empty then
toolcontext.warning(null, "key-alias",
"Warning: the environment variable `KEY_ALIAS` is not set, the APK file will not be signed.")
# Just move the unsigned APK to outname
args = ["mv", apk_path, outname]
toolcontext.exec_and_check(args, "Android project error")
return
end
# We have a key_alias, try to sign the APK
args = ["jarsigner", "-sigalg", "MD5withRSA", "-digestalg", "SHA1", apk_path, key_alias]
## Use a custom keystore
if not keystore_path.is_empty then args.add_all(["-keystore", keystore_path])
## Use a TSA server
if not tsa_server.is_empty then args.add_all(["-tsa", tsa_server])
toolcontext.exec_and_check(args, "Android project error")
# Clean output file
if outname.to_path.exists then outname.to_path.delete
# Align APK
args = ["zipalign", "4", apk_path, outname]
toolcontext.exec_and_check(args, "Android project error")
else
# Move to the expected output path
args = ["mv", "{android_project_root}/app/build/outputs/apk/debug/app-debug.apk", outname]
toolcontext.exec_and_check(args, "Android project error")
end
end
src/platform/android.nit:478,2--531,4
redef fun compile_c_code(compile_dir)
do
var project_name = app_project.short_name
var release = toolcontext.opt_release.value
var outfile = outfile(compiler.mainmodule)
# Compile with `xcodebuild`
#
# TODO support more than the iPhone and the simulator.
var compile_mode = if release then "Release" else "Debug"
var args = ["sh", "-c", "cd {ios_project_root}; " +
"xcodebuild -quiet -target '{project_name}' " +
"-destination 'platform=iOS Simulator,name=iPhone' " +
"-configuration {compile_mode} " +
"ONLY_ACTIVE_ARCH=NO "+
"-sdk iphonesimulator build"]
toolcontext.exec_and_check(args, "iOS project error")
# Move compiled app to destination
if outfile.file_exists then
var error = outfile.rmdir
if error != null then
print_error error
exit 1
end
end
args = ["mv", "{ios_project_root}/build/{compile_mode}-iphonesimulator/{project_name}.app", outfile]
toolcontext.exec_and_check(args, "iOS project error")
end
src/platform/ios.nit:199,2--228,4