{"record":{"id":"7aac2a5915e8066a","repo":"nodejs/node","slug":"could-not-automatically-locate-src-directory-thi","errorCode":null,"errorMessage":"Could not automatically locate src directory.  This isa temporary Chromium feature that will be removed.  Use--depth as a workaround.","messagePattern":"Could not automatically locate src directory\\.  This isa temporary Chromium feature that will be removed\\.  Use--depth as a workaround\\.","errorType":"exception","errorClass":"GypError","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/gyp/__init__.py","lineNumber":592,"sourceCode":"    # found will be treated as though it were the path used for --depth.\n    if not options.depth:\n        for build_file in build_files:\n            build_file_dir = os.path.abspath(os.path.dirname(build_file))\n            build_file_dir_components = build_file_dir.split(os.path.sep)\n            components_len = len(build_file_dir_components)\n            for index in range(components_len - 1, -1, -1):\n                if build_file_dir_components[index] == \"src\":\n                    options.depth = os.path.sep.join(build_file_dir_components)\n                    break\n                del build_file_dir_components[index]\n\n            # If the inner loop found something, break without advancing to another\n            # build file.\n            if options.depth:\n                break\n\n        if not options.depth:\n            raise GypError(\n                \"Could not automatically locate src directory.  This is\"\n                \"a temporary Chromium feature that will be removed.  Use\"\n                \"--depth as a workaround.\"\n            )\n\n    # If toplevel-dir is not set, we assume that depth is the root of our source\n    # tree.\n    if not options.toplevel_dir:\n        options.toplevel_dir = options.depth\n\n    # -D on the command line sets variable defaults - D isn't just for define,\n    # it's for default.  Perhaps there should be a way to force (-F?) a\n    # variable's value so that it can't be overridden by anything else.\n    cmdline_default_variables = {}\n    defines = []\n    if options.use_environment:\n        defines += ShlexEnv(\"GYP_DEFINES\")\n    if options.defines:","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/gyp/__init__.py#L574-L610","documentation":"GypError('Could not automatically locate src directory...') is raised when --depth was not supplied and gyp's Chromium-specific heuristic fails: it walks each build file's absolute path components looking for a directory literally named 'src', and none is found. The 'depth' is used as the source-tree root for relative target paths. The message itself notes this is a legacy Chromium feature and recommends --depth.","triggerScenarios":"Running gyp without --depth on a build file whose path contains no 'src' component; checking out only a subtree of a Chromium-style repo; renaming the top-level source directory away from 'src'.","commonSituations":"Non-Chromium projects that nonetheless use gyp and don't have a 'src' dir; shallow clones that omit the conventional layout; vendoring a gyp project under a differently named root.","solutions":["Pass --depth=<path-to-source-root> explicitly on the gyp command line.","Ensure the build file lives under a directory chain containing a 'src' component, or rename your root to 'src'.","Set options.depth in your wrapper script before calling gyp.main."],"exampleFix":"# before\npython gyp project.gyp\n\n# after\npython gyp --depth=. project.gyp","handlingStrategy":"validation","validationCode":"import os\ndef resolve_depth(build_file):\n    parts = os.path.abspath(os.path.dirname(build_file)).split(os.path.sep)\n    if 'src' in parts:\n        return os.path.sep.join(parts[:parts.index('src') + 1])\n    return os.getcwd()  # explicit fallback instead of relying on heuristic\ndepth = resolve_depth(build_file)","typeGuard":"def path_has_src_component(build_file: str) -> bool:\n    import os\n    return 'src' in os.path.abspath(build_file).split(os.path.sep)","tryCatchPattern":"try:\n    gyp_main(args)\nexcept GypError as e:\n    if 'src directory' in str(e):\n        args = ['--depth=' + os.getcwd()] + args  # supply depth, retry\n        raise","preventionTips":["Always pass --depth explicitly; do not rely on the Chromium 'src' heuristic.","For non-Chromium projects, --depth=. is usually correct.","Name the source root 'src' if you want the heuristic to work."],"tags":["gyp","cli","depth","chromium","build-file","config"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}