Skip to content

Commit

Permalink
Fix missing etw dll in the final binary (#2534)
Browse files Browse the repository at this point in the history
  • Loading branch information
heyams authored Sep 23, 2022
1 parent bb35191 commit 6bc8309
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable-assemble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
# javadoc task fails sporadically fetching https://docs.oracle.com/javase/8/docs/api/
arguments: assemble -x javadoc ${{ inputs.no-build-cache && '--no-build-cache' || '' }}
arguments: assemble -Dai.etw.native.build=release -x javadoc ${{ inputs.no-build-cache && '--no-build-cache' || '' }}

- name: Upload snapshot
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/pipeline.user.windows.buddy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:
- !!buildcommand
name: 'Assemble'
command: '.scripts/gradle.cmd'
arguments: ':agent:agent:assemble --offline'
arguments: ':agent:agent:assemble -Dai.etw.native.build=release --offline'
artifacts:
- to: 'Artifacts'
include:
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/pipeline.user.windows.official.nonrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build:
- !!buildcommand
name: 'Assemble'
command: '.scripts/gradle.cmd'
arguments: ':agent:agent:assemble --offline'
arguments: ':agent:agent:assemble -Dai.etw.native.build=release --offline'
artifacts:
- to: 'Artifacts'
include:
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/pipeline.user.windows.official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build:
- !!defaultcommand
name: 'Assemble'
command: '.scripts/gradle.cmd'
arguments: 'publishToMavenLocal -DisRelease=true -Pai.etw.native.build=release --offline'
arguments: 'publishToMavenLocal -DisRelease=true -Dai.etw.native.build=release --offline'
- !!buildcommand
name: 'Copy files from maven local repository'
command: '.scripts/copy-from-maven-local.cmd'
Expand Down
31 changes: 15 additions & 16 deletions etw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ plugins {
id("base")
}

clean {
dependsOn(":etw:java:clean")
def buildNative = System.getenv("CI") != null && Os.isFamily(Os.FAMILY_WINDOWS)
if (buildNative) {
dependsOn ":etw:native:clean"
}
}

/**
* Configures the native build variant.
* Values: release|debug
* Default: debug
*/
final def NATIVE_BUILD_VARIANT_PROPERTY = "ai.etw.native.build"

clean {
dependsOn(":etw:java:clean")
def buildNative = System.properties[NATIVE_BUILD_VARIANT_PROPERTY] != null && Os.isFamily(Os.FAMILY_WINDOWS)
if (buildNative) {
dependsOn ":etw:native:clean"
}
}

/**
* Configures the verbosity of debug output.
* This value is ignored if ai.etw.native.build=release
Expand All @@ -31,14 +31,13 @@ subprojects {
ext["NATIVE_BUILD_VARIANT_PROPERTY"] = NATIVE_BUILD_VARIANT_PROPERTY
ext["NATIVE_VERBOSE_OUTPUT_PROPERTY"] = NATIVE_VERBOSE_OUTPUT_PROPERTY

String buildNativeProperty = System.properties[NATIVE_BUILD_VARIANT_PROPERTY]
// if prop does not exist, use isRelease value, otherwise override isRelease value.
if (!project.hasProperty(NATIVE_BUILD_VARIANT_PROPERTY)) {
if (System.getProperty(NATIVE_BUILD_VARIANT_PROPERTY) == null) {
ext[NATIVE_BUILD_VARIANT_PROPERTY] = isRelease ? "release" : "debug"
logger.info "setting ai.etw.native.build for ${project.name}: ${ext[NATIVE_BUILD_VARIANT_PROPERTY]}"
} else {
ext[NATIVE_BUILD_VARIANT_PROPERTY] = System.getProperty(NATIVE_BUILD_VARIANT_PROPERTY)
}
if (buildNativeProperty == null) {
ext[NATIVE_BUILD_VARIANT_PROPERTY] = isRelease ? "release" : "debug"
logger.info "setting ai.etw.native.build for ${project.name}: ${ext[NATIVE_BUILD_VARIANT_PROPERTY]}"
} else {
ext[NATIVE_BUILD_VARIANT_PROPERTY] = buildNativeProperty
}

if (!project.hasProperty(NATIVE_VERBOSE_OUTPUT_PROPERTY)) {
Expand All @@ -47,7 +46,7 @@ subprojects {
}
}

if (project.hasProperty(NATIVE_VERBOSE_OUTPUT_PROPERTY) && project.hasProperty(NATIVE_BUILD_VARIANT_PROPERTY)) {
if (project.hasProperty(NATIVE_VERBOSE_OUTPUT_PROPERTY) && buildNativeProperty != null) {
// verbose=true is not allowed for release builds
if ("true".equalsIgnoreCase(ext[NATIVE_VERBOSE_OUTPUT_PROPERTY]) && "release".equalsIgnoreCase(ext[NATIVE_BUILD_VARIANT_PROPERTY])) {
logger.warn "$NATIVE_VERBOSE_OUTPUT_PROPERTY cannot be true when $NATIVE_BUILD_VARIANT_PROPERTY=relese."
Expand Down
11 changes: 5 additions & 6 deletions etw/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ sourceSets {

archivesBaseName = "applicationinsights-java-etw-provider"

logger.info "project ${project.path} prop: ai.etw.native.build=${project.properties['ai.etw.native.build']}"

def buildNative = System.getenv("CI") != null && Os.isFamily(Os.FAMILY_WINDOWS)
logger.info "project ${project.path} prop: ai.etw.native.build=${System.properties['ai.etw.native.build']}"

def buildNative = System.properties['ai.etw.native.build'] != null && Os.isFamily(Os.FAMILY_WINDOWS)
dependencies {
implementation("org.slf4j:slf4j-api")

if (buildNative) {
jni32 project(path: ":etw:native", configuration: "${project.properties['ai.etw.native.build']}X86RuntimeElements")
jni64 project(path: ":etw:native", configuration: "${project.properties['ai.etw.native.build']}X86-64RuntimeElements")
jni32 project(path: ":etw:native", configuration: "${System.properties['ai.etw.native.build']}X86RuntimeElements")
jni64 project(path: ":etw:native", configuration: "${System.properties['ai.etw.native.build']}X86-64RuntimeElements")
} else {
logger.info "Skipping build of :etw:native. EtwAppender/EtwProvider will not work because library is missing"
}
Expand All @@ -58,7 +57,7 @@ if (hasProperty("ai.etw.native.generateHeaders")) {

if (buildNative) {
tasks.register("processNativeResources", Copy) {
def useReleaseBuild = project.getProperty("ai.etw.native.build").equalsIgnoreCase("release")
def useReleaseBuild = System.properties["ai.etw.native.build"].equalsIgnoreCase("release")
dependsOn project(":etw:native").tasks.named("assemble${useReleaseBuild ? 'Release' : 'Debug'}X86").get()
dependsOn project(":etw:native").tasks.named("assemble${useReleaseBuild ? 'Release' : 'Debug'}X86-64").get()

Expand Down
8 changes: 5 additions & 3 deletions etw/native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ library {
}


logger.info "$NATIVE_BUILD_VARIANT_PROPERTY = ${project.properties[NATIVE_BUILD_VARIANT_PROPERTY]}"
logger.info "$NATIVE_BUILD_VARIANT_PROPERTY = ${System.properties[NATIVE_BUILD_VARIANT_PROPERTY]}"
logger.info "$NATIVE_VERBOSE_OUTPUT_PROPERTY = ${project.properties[NATIVE_VERBOSE_OUTPUT_PROPERTY]}"

// NOTE: these options apply to Visual Studio Build Tools (cl.exe)
Expand All @@ -51,15 +51,17 @@ tasks.withType(CppCompile).configureEach {
compilerArgs.add "/sdl"
compilerArgs.add "/std:c++14"

if (project.hasProperty(NATIVE_BUILD_VARIANT_PROPERTY) && "release".equalsIgnoreCase(project.properties[NATIVE_BUILD_VARIANT_PROPERTY])) {
String buildNative = System.properties[NATIVE_BUILD_VARIANT_PROPERTY]
String outputNative = project.hasProperty(NATIVE_VERBOSE_OUTPUT_PROPERTY)
if (buildNative != null && "release".equalsIgnoreCase(buildNative)) {
logger.info "Configuring ${it} for release build"
macros.put("NDEBUG", null)
compilerArgs.add "/O2" // optimize for speed
compilerArgs.add "/MD" // multithreaded
} else {
logger.info "Configuring ${it} for debug build"
compilerArgs.add "/MDd" // multithreaded, debug mode
if (project.hasProperty(NATIVE_VERBOSE_OUTPUT_PROPERTY) && "true".equalsIgnoreCase(project.properties[NATIVE_VERBOSE_OUTPUT_PROPERTY])) {
if (outputNative != null && "true".equalsIgnoreCase(outputNative)) {
logger.info "Verbose output enabled"
macros.put("AIETW_VERBOSE", null)
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ gradleEnterprise {

rootProject.name = 'applicationinsights-java'

def buildNative = System.getenv("CI") != null && Os.isFamily(Os.FAMILY_WINDOWS)
def buildNative = System.properties["ai.etw.native.build"] != null && Os.isFamily(Os.FAMILY_WINDOWS)
if (buildNative) {
include ':etw:native'
} else {
Expand Down

0 comments on commit 6bc8309

Please sign in to comment.