12 # testing locally post build:
13 # ./result/bin/semgrep scan --metrics=off --config 'r/generic.unicode.security.bidi.contains-bidirectional-characters'
16 common = import ./common.nix { inherit lib; };
17 semgrepBinPath = lib.makeBinPath [ semgrep-core ];
19 buildPythonPackage rec {
21 inherit (common) version;
22 src = fetchFromGitHub {
26 hash = common.srcHash;
29 # prepare a subset of the submodules as we only need a handful
30 # and there are many many submodules total
31 postPatch = (lib.concatStringsSep "\n" (lib.mapAttrsToList
35 # remove git submodule placeholder
38 ln -s ${submodule}/ ${path}
41 passthru.submodulesSubset)) + ''
45 # tell cli/setup.py to not copy semgrep-core into the result
46 # this means we can share a copy of semgrep-core and avoid an issue where it
47 # copies the binary but doesn't retain the executable bit
48 SEMGREP_SKIP_BIN = true;
55 propagatedBuildInputs = with pythonPackages; [
79 nativeCheckInputs = [ git pytestCheckHook ] ++ (with pythonPackages; [
89 "tests/default/e2e-pro"
90 "tests/default/e2e-pysemgrep"
97 "test_parse_exclude_rules_auto"
98 # many child tests require networking to download files
99 "TestConfigLoaderForProducts"
100 # doesn't start flaky plugin correctly
101 "test_debug_performance"
105 # tests need a home directory
106 export HOME="$(mktemp -d)"
108 # tests need access to `semgrep-core`
109 export OLD_PATH="$PATH"
110 export PATH="$PATH:${semgrepBinPath}"
113 # replace old semgrep with wrapped one
115 ln -s $out/bin/semgrep ./bin/semgrep
119 export PATH="$OLD_PATH"
123 # since we stop cli/setup.py from finding semgrep-core and copying it into
124 # the result we need to provide it on the PATH
126 makeWrapperArgs+=(--prefix PATH : ${semgrepBinPath})
130 chmod +x $out/bin/{,py}semgrep
134 inherit common semgrep-core;
135 submodulesSubset = lib.mapAttrs (k: args: fetchFromGitHub args) common.submodules;
136 updateScript = ./update.sh;
139 meta = common.meta // {
140 description = common.meta.description + " - cli";
141 inherit (semgrep-core.meta) platforms;