From 8079af7ed688fcbddbce19aaaf443b14e0ba1167 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 8 May 2023 10:28:10 +0200 Subject: [PATCH] Swift: add autobuild failure diagnostics --- .../create_database_utils.py | 31 +- .../diagnostics_test_utils.py | 64 +++ .../osx-only/autobuilder/failure/.gitignore | 1 + .../autobuilder/failure/diagnostics.expected | 17 + .../hello-failure.xcodeproj/project.pbxproj | 364 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../osx-only/autobuilder/failure/test.py | 5 + swift/integration-tests/runner.py | 2 + swift/logging/SwiftLogging.h | 8 +- swift/xcode-autobuilder/BUILD.bazel | 4 + swift/xcode-autobuilder/XcodeBuildLogging.h | 17 + swift/xcode-autobuilder/XcodeBuildRunner.cpp | 17 +- 13 files changed, 528 insertions(+), 17 deletions(-) create mode 100644 swift/integration-tests/diagnostics_test_utils.py create mode 100644 swift/integration-tests/osx-only/autobuilder/failure/.gitignore create mode 100644 swift/integration-tests/osx-only/autobuilder/failure/diagnostics.expected create mode 100644 swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.pbxproj create mode 100644 swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 swift/integration-tests/osx-only/autobuilder/failure/test.py create mode 100644 swift/xcode-autobuilder/XcodeBuildLogging.h diff --git a/swift/integration-tests/create_database_utils.py b/swift/integration-tests/create_database_utils.py index 38822fd70b4..8627f97a686 100644 --- a/swift/integration-tests/create_database_utils.py +++ b/swift/integration-tests/create_database_utils.py @@ -1,15 +1,34 @@ """ -recreation of internal `create_database_utils.py` to run the tests locally, with minimal -and swift-specialized functionality +Simplified version of internal `create_database_utils.py` used to run the tests locally, with +minimal and swift-specialized functionality +TODO unify integration testing code across the public and private repositories """ import subprocess import pathlib import sys +import shutil -def run_codeql_database_create(cmds, lang, keep_trap=True): +def runSuccessfully(cmd): + res = subprocess.run(cmd) + if res.returncode: + print("FAILED", file=sys.stderr) + print(" ", *cmd, f"(exit code {res.returncode})", file=sys.stderr) + sys.exit(res.returncode) + +def runUnsuccessfully(cmd): + res = subprocess.run(cmd) + if res.returncode == 0: + print("FAILED", file=sys.stderr) + print(" ", *cmd, f"(exit code 0, expected to fail)", file=sys.stderr) + sys.exit(1) + + +def run_codeql_database_create(cmds, lang, keep_trap=True, db=None, runFunction=runSuccessfully): + """ db parameter is here solely for compatibility with the internal test runner """ assert lang == 'swift' codeql_root = pathlib.Path(__file__).parents[2] + shutil.rmtree("db", ignore_errors=True) cmd = [ "codeql", "database", "create", "-s", ".", "-l", "swift", "--internal-use-lua-tracing", f"--search-path={codeql_root}", "--no-cleanup", @@ -19,8 +38,4 @@ def run_codeql_database_create(cmds, lang, keep_trap=True): for c in cmds: cmd += ["-c", c] cmd.append("db") - res = subprocess.run(cmd) - if res.returncode: - print("FAILED", file=sys.stderr) - print(" ", *cmd, file=sys.stderr) - sys.exit(res.returncode) + runFunction(cmd) diff --git a/swift/integration-tests/diagnostics_test_utils.py b/swift/integration-tests/diagnostics_test_utils.py new file mode 100644 index 00000000000..aa6f8df7488 --- /dev/null +++ b/swift/integration-tests/diagnostics_test_utils.py @@ -0,0 +1,64 @@ +""" +Simplified POSIX only version of internal `diagnostics_test_utils.py` used to run the tests locally +TODO unify integration testing code across the public and private repositories +""" + +import json +import pathlib +import subprocess +import os +import difflib +import sys + + +def _normalize_actual(test_dir, database_dir): + proc = subprocess.run(['codeql', 'database', 'export-diagnostics', '--format', 'raw', '--', database_dir], + stdout=subprocess.PIPE, universal_newlines=True, check=True, text=True) + data = proc.stdout.replace(str(test_dir.absolute()), "") + data = json.loads(data) + data[:] = [e for e in data if not e["source"]["id"].startswith("cli/")] + for e in data: + e.pop("timestamp") + return _normalize_json(data) + + +def _normalize_expected(test_dir): + with open(test_dir / "diagnostics.expected") as expected: + text = expected.read() + return _normalize_json(_load_concatenated_json(text)) + + +def _load_concatenated_json(text): + text = text.lstrip() + entries = [] + decoder = json.JSONDecoder() + while text: + obj, index = decoder.raw_decode(text) + entries.append(obj) + text = text[index:].lstrip() + return entries + + +def _normalize_json(data): + entries = [json.dumps(e, sort_keys=True, indent=2) for e in data] + entries.sort() + entries.append("") + return "\n".join(entries) + + +def check_diagnostics(test_dir=".", test_db="db"): + test_dir = pathlib.Path(test_dir) + test_db = pathlib.Path(test_db) + actual = _normalize_actual(test_dir, test_db) + if os.environ.get("CODEQL_INTEGRATION_TEST_LEARN") == "true": + with open(test_dir / "diagnostics.expected", "w") as expected: + expected.write(actual) + return + expected = _normalize_expected(test_dir) + if actual != expected: + with open(test_dir / "diagnostics.actual", "w") as actual_out: + actual_out.write(actual) + actual = actual.splitlines(keepends=True) + expected = expected.splitlines(keepends=True) + print("".join(difflib.unified_diff(actual, expected, fromfile="diagnostics.actual", tofile="diagnostics.expected")), file=sys.stderr) + sys.exit(1) diff --git a/swift/integration-tests/osx-only/autobuilder/failure/.gitignore b/swift/integration-tests/osx-only/autobuilder/failure/.gitignore new file mode 100644 index 00000000000..796b96d1c40 --- /dev/null +++ b/swift/integration-tests/osx-only/autobuilder/failure/.gitignore @@ -0,0 +1 @@ +/build diff --git a/swift/integration-tests/osx-only/autobuilder/failure/diagnostics.expected b/swift/integration-tests/osx-only/autobuilder/failure/diagnostics.expected new file mode 100644 index 00000000000..737e28baae1 --- /dev/null +++ b/swift/integration-tests/osx-only/autobuilder/failure/diagnostics.expected @@ -0,0 +1,17 @@ +{ + "helpLinks": [ + "https://docs.github.com/en/enterprise-server/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning" + ], + "plaintextMessage": "The detected build command failed (tried /usr/bin/xcodebuild build -project /hello-failure.xcodeproj -target hello-failure CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO).\n\nSet up a manual build command.", + "severity": "error", + "source": { + "extractorName": "swift", + "id": "swift/autobuilder/build-command-failed", + "name": "Detected build command failed" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": true, + "telemetry": true + } +} diff --git a/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.pbxproj b/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.pbxproj new file mode 100644 index 00000000000..a7b0ee2cf7c --- /dev/null +++ b/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.pbxproj @@ -0,0 +1,364 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 5700ECA72A09043B006BF37C /* hello_failureApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5700ECA62A09043B006BF37C /* hello_failureApp.swift */; }; + 5700ECA92A09043B006BF37C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5700ECA82A09043B006BF37C /* ContentView.swift */; }; + 5700ECAB2A09043C006BF37C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5700ECAA2A09043C006BF37C /* Assets.xcassets */; }; + 5700ECAE2A09043C006BF37C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5700ECAD2A09043C006BF37C /* Preview Assets.xcassets */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 5700ECA32A09043B006BF37C /* hello-failure.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "hello-failure.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 5700ECA62A09043B006BF37C /* hello_failureApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = hello_failureApp.swift; sourceTree = ""; }; + 5700ECA82A09043B006BF37C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 5700ECAA2A09043C006BF37C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 5700ECAD2A09043C006BF37C /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 5700ECA02A09043B006BF37C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 5700EC9A2A09043B006BF37C = { + isa = PBXGroup; + children = ( + 5700ECA52A09043B006BF37C /* hello-failure */, + 5700ECA42A09043B006BF37C /* Products */, + ); + sourceTree = ""; + }; + 5700ECA42A09043B006BF37C /* Products */ = { + isa = PBXGroup; + children = ( + 5700ECA32A09043B006BF37C /* hello-failure.app */, + ); + name = Products; + sourceTree = ""; + }; + 5700ECA52A09043B006BF37C /* hello-failure */ = { + isa = PBXGroup; + children = ( + 5700ECA62A09043B006BF37C /* hello_failureApp.swift */, + 5700ECA82A09043B006BF37C /* ContentView.swift */, + 5700ECAA2A09043C006BF37C /* Assets.xcassets */, + 5700ECAC2A09043C006BF37C /* Preview Content */, + ); + path = "hello-failure"; + sourceTree = ""; + }; + 5700ECAC2A09043C006BF37C /* Preview Content */ = { + isa = PBXGroup; + children = ( + 5700ECAD2A09043C006BF37C /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 5700ECA22A09043B006BF37C /* hello-failure */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5700ECB12A09043C006BF37C /* Build configuration list for PBXNativeTarget "hello-failure" */; + buildPhases = ( + 5700ECB42A090460006BF37C /* ShellScript */, + 5700EC9F2A09043B006BF37C /* Sources */, + 5700ECA02A09043B006BF37C /* Frameworks */, + 5700ECA12A09043B006BF37C /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "hello-failure"; + productName = "hello-failure"; + productReference = 5700ECA32A09043B006BF37C /* hello-failure.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 5700EC9B2A09043B006BF37C /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1430; + LastUpgradeCheck = 1430; + TargetAttributes = { + 5700ECA22A09043B006BF37C = { + CreatedOnToolsVersion = 14.3; + }; + }; + }; + buildConfigurationList = 5700EC9E2A09043B006BF37C /* Build configuration list for PBXProject "hello-failure" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 5700EC9A2A09043B006BF37C; + productRefGroup = 5700ECA42A09043B006BF37C /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 5700ECA22A09043B006BF37C /* hello-failure */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 5700ECA12A09043B006BF37C /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5700ECAE2A09043C006BF37C /* Preview Assets.xcassets in Resources */, + 5700ECAB2A09043C006BF37C /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 5700ECB42A090460006BF37C /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "false\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 5700EC9F2A09043B006BF37C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5700ECA92A09043B006BF37C /* ContentView.swift in Sources */, + 5700ECA72A09043B006BF37C /* hello_failureApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 5700ECAF2A09043C006BF37C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 5700ECB02A09043C006BF37C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.4; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 5700ECB22A09043C006BF37C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"hello-failure/Preview Content\""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.example.hello-failure"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 5700ECB32A09043C006BF37C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"hello-failure/Preview Content\""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.example.hello-failure"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 5700EC9E2A09043B006BF37C /* Build configuration list for PBXProject "hello-failure" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5700ECAF2A09043C006BF37C /* Debug */, + 5700ECB02A09043C006BF37C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5700ECB12A09043C006BF37C /* Build configuration list for PBXNativeTarget "hello-failure" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5700ECB22A09043C006BF37C /* Debug */, + 5700ECB32A09043C006BF37C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 5700EC9B2A09043B006BF37C /* Project object */; +} diff --git a/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000000..919434a6254 --- /dev/null +++ b/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000000..18d981003d6 --- /dev/null +++ b/swift/integration-tests/osx-only/autobuilder/failure/hello-failure.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/swift/integration-tests/osx-only/autobuilder/failure/test.py b/swift/integration-tests/osx-only/autobuilder/failure/test.py new file mode 100644 index 00000000000..37aaa3ce344 --- /dev/null +++ b/swift/integration-tests/osx-only/autobuilder/failure/test.py @@ -0,0 +1,5 @@ +from create_database_utils import * +from diagnostics_test_utils import * + +run_codeql_database_create([], lang='swift', keep_trap=True, db=None, runFunction=runUnsuccessfully) +check_diagnostics() diff --git a/swift/integration-tests/runner.py b/swift/integration-tests/runner.py index 6abeaa050a5..bf65781cdb2 100755 --- a/swift/integration-tests/runner.py +++ b/swift/integration-tests/runner.py @@ -43,6 +43,8 @@ def skipped(test): def main(opts): test_dirs = opts.test_dir or [this_dir] tests = [t for d in test_dirs for t in d.rglob("test.py") if not skipped(t)] + if opts.learn: + os.environ["CODEQL_INTEGRATION_TEST_LEARN"] = "true" if not tests: print("No tests found", file=sys.stderr) diff --git a/swift/logging/SwiftLogging.h b/swift/logging/SwiftLogging.h index cf756c9e5a0..4a24996ad6e 100644 --- a/swift/logging/SwiftLogging.h +++ b/swift/logging/SwiftLogging.h @@ -49,10 +49,10 @@ #define DIAGNOSE_CRITICAL(ID, ...) DIAGNOSE_WITH_LEVEL(critical, ID, __VA_ARGS__) #define DIAGNOSE_ERROR(ID, ...) DIAGNOSE_WITH_LEVEL(error, ID, __VA_ARGS__) -#define DIAGNOSE_WITH_LEVEL(LEVEL, ID, ...) \ - do { \ - codeql::SwiftDiagnosticsSource::inscribe<&codeql_diagnostics::ID>(); \ - LOG_WITH_LEVEL_AND_CATEGORY(LEVEL, ID, __VA_ARGS__); \ +#define DIAGNOSE_WITH_LEVEL(LEVEL, ID, ...) \ + do { \ + codeql::SwiftDiagnosticsSource::ensureRegistered<&codeql_diagnostics::ID>(); \ + LOG_WITH_LEVEL_AND_CATEGORY(LEVEL, ID, __VA_ARGS__); \ } while (false) // avoid calling into binlog's original macros diff --git a/swift/xcode-autobuilder/BUILD.bazel b/swift/xcode-autobuilder/BUILD.bazel index 116d11cbfab..d497666f3e2 100644 --- a/swift/xcode-autobuilder/BUILD.bazel +++ b/swift/xcode-autobuilder/BUILD.bazel @@ -13,6 +13,10 @@ swift_cc_binary( "-framework CoreFoundation", ], target_compatible_with = ["@platforms//os:macos"], + deps = [ + "@absl//absl/strings", + "//swift/logging", + ], ) generate_cmake( diff --git a/swift/xcode-autobuilder/XcodeBuildLogging.h b/swift/xcode-autobuilder/XcodeBuildLogging.h new file mode 100644 index 00000000000..8dfc3111c4d --- /dev/null +++ b/swift/xcode-autobuilder/XcodeBuildLogging.h @@ -0,0 +1,17 @@ +#pragma once + +#include "swift/logging/SwiftLogging.h" + +namespace codeql { +constexpr const std::string_view programName = "autobuilder"; +} + +namespace codeql_diagnostics { +constexpr codeql::SwiftDiagnosticsSource build_command_failed{ + "build_command_failed", + "Detected build command failed", + "Set up a manual build command", + "https://docs.github.com/en/enterprise-server/code-security/code-scanning/" + "automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning", +}; +} // namespace codeql_diagnostics diff --git a/swift/xcode-autobuilder/XcodeBuildRunner.cpp b/swift/xcode-autobuilder/XcodeBuildRunner.cpp index cbc99592d24..4c20440c3b9 100644 --- a/swift/xcode-autobuilder/XcodeBuildRunner.cpp +++ b/swift/xcode-autobuilder/XcodeBuildRunner.cpp @@ -3,6 +3,14 @@ #include #include #include +#include "absl/strings/str_join.h" + +#include "swift/xcode-autobuilder/XcodeBuildLogging.h" + +static codeql::Logger& logger() { + static codeql::Logger ret{"build"}; + return ret; +} static int waitpid_status(pid_t child) { int status; @@ -52,13 +60,12 @@ void buildTarget(Target& target, bool dryRun) { argv.push_back("CODE_SIGNING_ALLOWED=NO"); if (dryRun) { - for (auto& arg : argv) { - std::cout << arg + " "; - } - std::cout << "\n"; + std::cout << absl::StrJoin(argv, " ") << "\n"; } else { if (!exec(argv)) { - std::cerr << "Build failed\n"; + DIAGNOSE_ERROR(build_command_failed, "The detected build command failed (tried {})", + absl::StrJoin(argv, " ")); + codeql::Log::flush(); exit(1); } }