diff --git a/java/build-android.gradle b/java/build-android.gradle index 1410b5388d..d5839f9f27 100644 --- a/java/build-android.gradle +++ b/java/build-android.gradle @@ -8,25 +8,39 @@ def publishDir = System.properties['publishDir'] def minSdkVer = System.properties['minSdkVer'] def targetSdkVer = System.properties['targetSdkVer'] boolean enableTrainingApis = (System.properties['ENABLE_TRAINING_APIS'] ?: "0") == "1" +def releaseVersionSuffix = System.properties['releaseVersionSuffix'] ?: "" // Expected format for qnnVersion: major.minor.patch (e.g., 2.26.0) // QNN package version does not follow Semantic Versioning (SemVer) format. // For non qnn builds, qnnVersion will be null def qnnVersion = System.properties['qnnVersion'] -// Since Android requires a higher numbers indicating more recent versions -// This function assume ORT version number will be in formart of A.B.C such as 1.7.0 -// We generate version code A[0{0,1}]B[0{0,1}]C, -// for example '1.7.0' -> 10700, '1.6.15' -> 10615 -def getVersionCode(String version){ - String[] codes = version.split('\\.'); +// Since Android requires higher numbers indicating more recent versions +// This function assumes ORT version number will be in the format of A.B.C[-rc/beta/alpha.D] such as 1.20.0 or 1.20.0-rc.1 +// We generate version code A[0{0,1}]B[0{0,1}]C[0{0,1}]{1,2,3,4}D[01-99] +// for example '1.20.0' -> 12000400, '1.20.0-rc.1 ' -> 12000301 +// '1.20.0-beta.1' -> 12000201, '1.20.0-alpha.1' -> 12000101 +def getVersionCode(String version) { + String[] versionAndRelSufx = version.split('-') + String[] codes = versionAndRelSufx[0].split('\\.') // This will have problem if we have 3 digit [sub]version number, such as 1.7.199 // but it is highly unlikely to happen - String versionCodeStr = String.format("%d%02d%02d", codes[0] as int, codes[1] as int, codes[2] as int); - return versionCodeStr as int; + String versionCodeStr = String.format("%d%02d%02d", codes[0] as int, codes[1] as int, codes[2] as int) + + if (versionAndRelSufx.length > 1) { + String suffixType = versionAndRelSufx[1].split('\\.')[0] + String suffixNumber = versionAndRelSufx[1].split('\\.')[1] + def suffixMap = ['alpha': '1', 'beta': '2', 'rc': '3'] + versionCodeStr += suffixMap[suffixType] + String.format("%02d", suffixNumber as int) + } else { + versionCodeStr += "400" // For a normal release version without suffix, get the highest version code + } + println "Version code for $version is $versionCodeStr" + return versionCodeStr as int } project.buildDir = buildDir -project.version = rootProject.file('../VERSION_NUMBER').text.trim() +def project_version = rootProject.file('../VERSION_NUMBER').text.trim() +project.version = releaseVersionSuffix ? "${project_version}${releaseVersionSuffix}" : project_version project.group = "com.microsoft.onnxruntime" def tmpArtifactId = enableTrainingApis ? project.name + "-training" : project.name diff --git a/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh b/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh index 690fd55e38..964b730c10 100755 --- a/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh +++ b/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh @@ -48,15 +48,15 @@ fi eval $COMMAND # Copy the built artifacts to give folder for publishing -BASE_PATH=/build/aar_out/${BUILD_CONFIG}/com/microsoft/onnxruntime/${PACKAGE_NAME}/${ORT_VERSION} -cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}-javadoc.jar /home/onnxruntimedev/.artifacts -cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}-sources.jar /home/onnxruntimedev/.artifacts -cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}.aar /home/onnxruntimedev/.artifacts -cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}.pom /home/onnxruntimedev/.artifacts +BASE_PATH=/build/aar_out/${BUILD_CONFIG}/com/microsoft/onnxruntime/${PACKAGE_NAME}/${ORT_VERSION}${RELEASE_VERSION_SUFFIX} +cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}${RELEASE_VERSION_SUFFIX}-javadoc.jar /home/onnxruntimedev/.artifacts +cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}${RELEASE_VERSION_SUFFIX}-sources.jar /home/onnxruntimedev/.artifacts +cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}${RELEASE_VERSION_SUFFIX}.aar /home/onnxruntimedev/.artifacts +cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}${RELEASE_VERSION_SUFFIX}.pom /home/onnxruntimedev/.artifacts # Copy executables if necessary if [ "$PUBLISH_EXECUTABLES" == "1" ]; then pushd /build/intermediates/executables/${BUILD_CONFIG} - tar -czvf /home/onnxruntimedev/.artifacts/${PACKAGE_NAME}-${ORT_VERSION}-executables.tgz * + tar -czvf /home/onnxruntimedev/.artifacts/${PACKAGE_NAME}-${ORT_VERSION}${RELEASE_VERSION_SUFFIX}-executables.tgz * popd fi diff --git a/tools/ci_build/github/android/build_aar_package.py b/tools/ci_build/github/android/build_aar_package.py index d6cac4e21b..19f66245a4 100644 --- a/tools/ci_build/github/android/build_aar_package.py +++ b/tools/ci_build/github/android/build_aar_package.py @@ -177,6 +177,7 @@ def _build_aar(args): if "--enable_training_apis" in build_settings["build_params"] else "-DENABLE_TRAINING_APIS=0" ), + "-DreleaseVersionSuffix=" + os.getenv("RELEASE_VERSION_SUFFIX", ""), ] # Add qnn specific parameters diff --git a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml index fe83a91b2f..e162365c40 100644 --- a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml +++ b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml @@ -14,6 +14,11 @@ parameters: type: string default: 'onnxruntime-android' +- name: ReleaseVersionSuffix + displayName: Release Version Suffix + type: string + default: '' + jobs: - job: Final_AAR_Testing_Android_${{ parameters.job_name_suffix }} workspace: @@ -57,7 +62,7 @@ jobs: cp -av $(Build.SourcesDirectory)/java/src/test/android ./ cd ./android mkdir -p app/libs - cp $(Build.BinariesDirectory)/final-android-aar/${{parameters.packageName}}-$(OnnxRuntimeVersion).aar app/libs/onnxruntime-android.aar + cp $(Build.BinariesDirectory)/final-android-aar/${{parameters.packageName}}-$(OnnxRuntimeVersion)${{parameters.ReleaseVersionSuffix}}.aar app/libs/onnxruntime-android.aar $(Build.SourcesDirectory)/java/gradlew --no-daemon clean connectedDebugAndroidTest --stacktrace displayName: Run E2E test using Emulator workingDirectory: $(Build.BinariesDirectory) diff --git a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml index f6ec87c754..51e47fde74 100644 --- a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml +++ b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml @@ -43,6 +43,11 @@ parameters: displayName: Use GPG to sign the jars type: boolean +- name: ReleaseVersionSuffix + displayName: Release Version Suffix + type: string + default: '' + jobs: - job: Android_Java_API_AAR_Packaging_${{ parameters.job_name_suffix }} timeoutInMinutes: 120 @@ -114,6 +119,7 @@ jobs: -e ORT_VERSION=$(OnnxRuntimeVersion) \ -e PUBLISH_EXECUTABLES=${{parameters.publish_executables}} \ -e PACKAGE_NAME=${{parameters.packageName}} \ + -e RELEASE_VERSION_SUFFIX=${{parameters.ReleaseVersionSuffix}} \ onnxruntimecpubuild \ /bin/bash /onnxruntime_src/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh $USE_QNN workingDirectory: $(Build.SourcesDirectory) diff --git a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml index ee91b33c47..1dae18d2c1 100644 --- a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml @@ -62,7 +62,9 @@ stages: DoEsrp: ${{ parameters.DoEsrp }} - stage: Android_Java_API_AAR_Packaging_Full - dependsOn: [] + dependsOn: Setup # Setup stage defined in set_packaging_variables_stage.yml creates the ReleaseVersionSuffix variable + variables: + ReleaseVersionSuffix: $[stageDependencies.Setup.Set_Variables.outputs['Set_Release_Version_Suffix.ReleaseVersionSuffix']] jobs: - template: android-java-api-aar.yml parameters: @@ -73,14 +75,18 @@ stages: publish_executables: '1' enable_code_sign: ${{ parameters.DoEsrp }} packageName: 'onnxruntime-android' + ReleaseVersionSuffix: $(ReleaseVersionSuffix) - template: android-java-api-aar-test.yml parameters: artifactName: 'onnxruntime-android-full-aar' job_name_suffix: 'Full' + ReleaseVersionSuffix: $(ReleaseVersionSuffix) - stage: Android_Java_API_AAR_Packaging_QNN - dependsOn: [] + dependsOn: Setup # Setup stage defined in set_packaging_variables_stage.yml creates the ReleaseVersionSuffix variable + variables: + ReleaseVersionSuffix: $[stageDependencies.Setup.Set_Variables.outputs['Set_Release_Version_Suffix.ReleaseVersionSuffix']] jobs: - template: android-java-api-aar.yml parameters: @@ -91,6 +97,7 @@ stages: publish_executables: '0' enable_code_sign: ${{ parameters.DoEsrp }} packageName: 'onnxruntime-android-qnn' + ReleaseVersionSuffix: $(ReleaseVersionSuffix) #TODO: Add test job for QNN Android AAR - stage: iOS_Full_xcframework