diff --git a/orderfile/README.md b/orderfile/README.md new file mode 100644 index 000000000..8fb0474aa --- /dev/null +++ b/orderfile/README.md @@ -0,0 +1,100 @@ +# Order file demo + +Order files are text files containing symbols representing functions names. +Linkers (lld) uses order files to layout functions in a specific order. These +binaries with ordered symbols will reduce page faults and improve a program's +launch time due to the efficient loading of symbols during a program’s +cold-start. + +## Files + +- app/src/main/cpp/orderfile.cpp: The source code for the orderfile library that + is used by the Kotlin app. +- app/src/main/cpp/CMakeLists.txt: The CMakeLists either sets the orderfile + library as generating profiles or loading the orderfile. +- app/src/main/java/MainActivity.kt: The Kotlin app source code. + +## Profile Steps + +1. For simplicity, we have setup the `CMakeLists.txt` and you just need make + sure `set(GENERATE_PROFILES ON)` is not commented. You need to pass any + optimization flag except `-O0`. The mapping file is not generated and the + profile instrumentation does not work without an optimization flag. +1. Run the app on Android Studio. You can either run it on a physical or virtual + device. You will see "Hello World" on the screen. +1. To pull the data from the device, you'll need to move it from an app-writable + directory to a shell readable directory for adb pull. We also need to + transfer the output into hexadecimal format. + +``` +adb shell "run-as com.example.orderfiledemo sh -c 'cat /data/user/0/com.example.orderfiledemo/cache/demo.output.order' | cat > /data/local/tmp/demo.output.order" +adb pull /data/local/tmp/demo.output.order . + +# Convert to hexdeciaml format on Linux, Mac, or ChromeOS +hexdump -C demo.output.order > demo.prof + +# Convert to hexdecimal format on Windows +certutil -f -encodeHex demo.output.order demo.prof +``` + +4. Once you get both mapping file and profile file, you can use + [this script](https://android.googlesource.com/toolchain/pgo-profiles/+/refs/heads/main/scripts/create_orderfile.py) + to create the order file: + +``` +python3 create_orderfile.py --profile-file demo.prof --mapping-file mapping.txt --output app/src/main/cpp/demo.orderfile +``` + +## Load Steps + +1. For load, you need to uncomment + `set(USE_PROFILE "${CMAKE_SOURCE_DIR}/demo.orderfile")` and make sure + `set(GENERATE_PROFILES ON)` is commented. + +1. If you want to validate the shared library's layout is different, you need to + find `liborderfiledemo.so` and run `nm` + +``` +nm -n liborderfiledemo.so +``` + +## Difference between Java and Kotlin App + +The main difference between a Java app and a Kotlin app is the syntax. You can +easily change this Kotlin example into a Java example. + +- Load Library + +``` +# Kotlin +companion object { + init { + System.loadLibrary("orderfiledemo") + } +} + +# Java +static { + System.loadLibrary("orderfiledemo"); +} +``` + +- Recognize an external method + +``` +# Kotlin +external fun runWorkload(tempDir: String) + +# Java +private native void runWorkload(String tempDir); +``` + +- Get the cache directory + +```agsl +# Kotlin +runWorkload(applicationContext.cacheDir.toString()) + +# Java +runWorkload(getcacheDir().toString()) +``` diff --git a/orderfile/app/.gitignore b/orderfile/app/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/orderfile/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/orderfile/app/build.gradle b/orderfile/app/build.gradle new file mode 100644 index 000000000..67a66fde5 --- /dev/null +++ b/orderfile/app/build.gradle @@ -0,0 +1,60 @@ +plugins { + id 'com.android.application' + id 'kotlin-android' +} + +android { + compileSdk 31 + + defaultConfig { + applicationId "com.example.orderfiledemo" + minSdk 21 + targetSdk 31 + versionCode 1 + versionName "1.0" + ndkVersion '25.2.9519653' + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + cppFlags '' + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + externalNativeBuild { + cmake { + path file('src/main/cpp/CMakeLists.txt') + version '3.22.1' + } + } + buildFeatures { + viewBinding true + } + namespace 'com.example.orderfiledemo' + ndkVersion '25.2.9519653' +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} diff --git a/orderfile/app/proguard-rules.pro b/orderfile/app/proguard-rules.pro new file mode 100644 index 000000000..f1b424510 --- /dev/null +++ b/orderfile/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/orderfile/app/src/androidTest/java/com/example/orderfiledemo/ExampleInstrumentedTest.kt b/orderfile/app/src/androidTest/java/com/example/orderfiledemo/ExampleInstrumentedTest.kt new file mode 100644 index 000000000..e1c097197 --- /dev/null +++ b/orderfile/app/src/androidTest/java/com/example/orderfiledemo/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.orderfiledemo + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.orderfiledemo", appContext.packageName) + } +} diff --git a/orderfile/app/src/main/AndroidManifest.xml b/orderfile/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..80d99f8d7 --- /dev/null +++ b/orderfile/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/orderfile/app/src/main/cpp/CMakeLists.txt b/orderfile/app/src/main/cpp/CMakeLists.txt new file mode 100644 index 000000000..763868625 --- /dev/null +++ b/orderfile/app/src/main/cpp/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.22.1) +project(OrderfileDemo CXX) + +# We have setup build variables that you can just comment or uncomment to use. +# Make sure to have only one build variable uncommented at a time. +# If you want to generate profiles and mapping file, make sure GENERATE_PROFILES is uncommented. +# If you want to use your generated order file to layout symbols, uncomment USE_PROFILE. + + +set(GENERATE_PROFILES ON) +#set(USE_PROFILE "${CMAKE_SOURCE_DIR}/demo.orderfile") + +add_library(orderfiledemo SHARED orderfile.cpp) +target_link_libraries(orderfiledemo log) + +if(GENERATE_PROFILES) + # Generating profiles requires any optimization flag aside from -O0. + # The mapping file will not generate and the profile instrumentation does not work without an optimization flag. + target_compile_options(orderfiledemo PRIVATE -forder-file-instrumentation -O1 -mllvm -orderfile-write-mapping=mapping.txt ) + target_link_options(orderfiledemo PRIVATE -forder-file-instrumentation ) + target_compile_definitions(orderfiledemo PRIVATE GENERATE_PROFILES) +elseif(USE_PROFILE) + target_compile_options(orderfiledemo PRIVATE -Wl,--symbol-ordering-file=${USE_PROFILE} -Wl,--no-warn-symbol-ordering ) + target_link_options(orderfiledemo PRIVATE -Wl,--symbol-ordering-file=${USE_PROFILE} -Wl,--no-warn-symbol-ordering ) +endif() \ No newline at end of file diff --git a/orderfile/app/src/main/cpp/orderfile.cpp b/orderfile/app/src/main/cpp/orderfile.cpp new file mode 100644 index 000000000..a8e5c83ce --- /dev/null +++ b/orderfile/app/src/main/cpp/orderfile.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include + +const char kLogTag[] = "orderfiledemo"; + +#ifdef GENERATE_PROFILES +extern "C" int __llvm_profile_set_filename(const char *); +extern "C" int __llvm_profile_initialize_file(void); +extern "C" int __llvm_orderfile_dump(void); +#endif + +void DumpProfileDataIfNeeded(const char *temp_dir) { +#ifdef GENERATE_PROFILES + char profile_location[PATH_MAX] = {}; + snprintf(profile_location, sizeof(profile_location), "%s/demo.output", + temp_dir); + if (__llvm_profile_set_filename(profile_location) == -1) { + __android_log_print(ANDROID_LOG_ERROR, kLogTag, + "__llvm_profile_set_filename(\"%s\") failed: %s", + profile_location, strerror(errno)); + return; + } + + if (__llvm_profile_initialize_file() == -1) { + __android_log_print(ANDROID_LOG_ERROR, kLogTag, + "__llvm_profile_initialize_file failed: %s", + strerror(errno)); + return; + } + + if (__llvm_orderfile_dump() == -1) { + __android_log_print(ANDROID_LOG_ERROR, kLogTag, + "__llvm_orderfile_dump() failed: %s", strerror(errno)); + return; + } + __android_log_print(ANDROID_LOG_DEBUG, kLogTag, "Wrote profile data to %s", + profile_location); +#else + __android_log_print(ANDROID_LOG_DEBUG, kLogTag, + "Did not write profile data because the app was not " + "built for profile generation"); +#endif +} + +extern "C" JNIEXPORT void JNICALL +Java_com_example_orderfiledemo_MainActivity_runWorkload(JNIEnv *env, + jobject /* this */, + jstring temp_dir) { + DumpProfileDataIfNeeded(env->GetStringUTFChars(temp_dir, 0)); +} diff --git a/orderfile/app/src/main/java/com/example/orderfiledemo/MainActivity.kt b/orderfile/app/src/main/java/com/example/orderfiledemo/MainActivity.kt new file mode 100644 index 000000000..2523b6c1b --- /dev/null +++ b/orderfile/app/src/main/java/com/example/orderfiledemo/MainActivity.kt @@ -0,0 +1,32 @@ +package com.example.orderfiledemo + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import com.example.orderfiledemo .databinding.ActivityMainBinding + +class MainActivity : AppCompatActivity() { + + private lateinit var binding: ActivityMainBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + runWorkload(applicationContext.cacheDir.toString()) + binding.sampleText.text = "Hello, world!" + } + + /** + * A native method that is implemented by the 'orderfiledemo' native library, + * which is packaged with this application. + */ + external fun runWorkload(tempDir: String) + + companion object { + // Used to load the 'orderfiledemo' library on application startup. + init { + System.loadLibrary("orderfiledemo") + } + } +} diff --git a/orderfile/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/orderfile/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 000000000..7706ab9e6 --- /dev/null +++ b/orderfile/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + diff --git a/orderfile/app/src/main/res/drawable/ic_launcher_background.xml b/orderfile/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 000000000..07d5da9cb --- /dev/null +++ b/orderfile/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/orderfile/app/src/main/res/layout/activity_main.xml b/orderfile/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000..3d42e01a6 --- /dev/null +++ b/orderfile/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/orderfile/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/orderfile/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 000000000..8e05188f8 --- /dev/null +++ b/orderfile/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/orderfile/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/orderfile/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 000000000..8e05188f8 --- /dev/null +++ b/orderfile/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/orderfile/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/orderfile/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 000000000..c209e78ec Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/orderfile/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/orderfile/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 000000000..b2dfe3d1b Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/orderfile/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/orderfile/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 000000000..4f0f1d64e Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/orderfile/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/orderfile/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 000000000..62b611da0 Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/orderfile/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/orderfile/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 000000000..948a3070f Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/orderfile/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/orderfile/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..1b9a6956b Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/orderfile/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/orderfile/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 000000000..28d4b77f9 Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/orderfile/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/orderfile/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..9287f5083 Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/orderfile/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/orderfile/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 000000000..aa7d6427e Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/orderfile/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/orderfile/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..9126ae37c Binary files /dev/null and b/orderfile/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/orderfile/app/src/main/res/values-night/themes.xml b/orderfile/app/src/main/res/values-night/themes.xml new file mode 100644 index 000000000..62ec3d150 --- /dev/null +++ b/orderfile/app/src/main/res/values-night/themes.xml @@ -0,0 +1,16 @@ + + + + diff --git a/orderfile/app/src/main/res/values/colors.xml b/orderfile/app/src/main/res/values/colors.xml new file mode 100644 index 000000000..b3ea3f9f4 --- /dev/null +++ b/orderfile/app/src/main/res/values/colors.xml @@ -0,0 +1,24 @@ + + + + #FFBB86FC + + + #FF6200EE + + + #FF3700B3 + + + #FF03DAC5 + + + #FF018786 + + + #FF000000 + + + #FFFFFFFF + + diff --git a/orderfile/app/src/main/res/values/strings.xml b/orderfile/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..2c88bdf15 --- /dev/null +++ b/orderfile/app/src/main/res/values/strings.xml @@ -0,0 +1,5 @@ + + + Orderfile Demo + + diff --git a/orderfile/app/src/main/res/values/themes.xml b/orderfile/app/src/main/res/values/themes.xml new file mode 100644 index 000000000..97ca3c640 --- /dev/null +++ b/orderfile/app/src/main/res/values/themes.xml @@ -0,0 +1,30 @@ + + + + diff --git a/orderfile/build.gradle b/orderfile/build.gradle new file mode 100644 index 000000000..1c4b10809 --- /dev/null +++ b/orderfile/build.gradle @@ -0,0 +1,18 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:8.1.0' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/orderfile/gradle.properties b/orderfile/gradle.properties new file mode 100644 index 000000000..ab7874755 --- /dev/null +++ b/orderfile/gradle.properties @@ -0,0 +1,25 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false +org.gradle.unsafe.configuration-cache=true diff --git a/orderfile/gradle/wrapper/gradle-wrapper.jar b/orderfile/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..7454180f2 Binary files /dev/null and b/orderfile/gradle/wrapper/gradle-wrapper.jar differ diff --git a/orderfile/gradle/wrapper/gradle-wrapper.properties b/orderfile/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..da1db5f04 --- /dev/null +++ b/orderfile/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/orderfile/gradlew b/orderfile/gradlew new file mode 100755 index 000000000..1b6c78733 --- /dev/null +++ b/orderfile/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/orderfile/gradlew.bat b/orderfile/gradlew.bat new file mode 100644 index 000000000..107acd32c --- /dev/null +++ b/orderfile/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/orderfile/settings.gradle b/orderfile/settings.gradle new file mode 100644 index 000000000..761d7c1d6 --- /dev/null +++ b/orderfile/settings.gradle @@ -0,0 +1,10 @@ +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + jcenter() // Warning: this repository is going to shut down soon + } +} +rootProject.name = "Orderfile Demo" +include ':app'