Skip to content

Commit 6d2a00c

Browse files
committed
feat: Add PHP language support
1 parent 802c465 commit 6d2a00c

File tree

2,394 files changed

+48726
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,394 files changed

+48726
-0
lines changed

php/.codeqlmanifest.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"provide": [
3+
"ql/*/qlpack.yml"
4+
],
5+
"versionPolicies": {
6+
"default": {
7+
"requireChangeNotes": true,
8+
"committedPrereleaseSuffix": "dev",
9+
"committedVersion": "nextPatchRelease"
10+
}
11+
}
12+
}

php/Makefile

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
.PHONY: all build clean test install help extractor dbscheme ql-library check fmt lint doc
2+
3+
# Detect OS and architecture
4+
UNAME_S := $(shell uname -s)
5+
UNAME_M := $(shell uname -m)
6+
7+
ifeq ($(UNAME_S),Linux)
8+
EXE :=
9+
DYLIB_EXT := so
10+
OS := linux
11+
else ifeq ($(UNAME_S),Darwin)
12+
EXE :=
13+
DYLIB_EXT := dylib
14+
OS := macos
15+
else ifeq ($(OS),Windows_NT)
16+
EXE := .exe
17+
DYLIB_EXT := dll
18+
OS := windows
19+
endif
20+
21+
# Paths
22+
EXTRACTOR_DIR := extractor
23+
QL_LIB_DIR := ql/lib
24+
QL_SRC_DIR := ql/src
25+
BUILD_DIR := build
26+
TARGET_DIR := $(EXTRACTOR_DIR)/target
27+
CARGO := cargo
28+
CODEQL := codeql
29+
30+
# Targets
31+
EXTRACTOR_BIN := $(TARGET_DIR)/release/codeql-extractor-php$(EXE)
32+
DBSCHEME_FILE := $(QL_LIB_DIR)/php.dbscheme
33+
TREE_SITTER_QL := $(QL_LIB_DIR)/codeql/php/ast/internal/TreeSitter.qll
34+
35+
# Default target
36+
all: help
37+
38+
## help: Show this help message
39+
help:
40+
@echo "PHP Language Support for CodeQL - Makefile"
41+
@echo ""
42+
@echo "Targets:"
43+
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
44+
@echo ""
45+
@echo "Examples:"
46+
@echo " make build Build the extractor"
47+
@echo " make clean Remove build artifacts"
48+
@echo " make test Run all tests"
49+
@echo " make install Install extractor and libraries"
50+
51+
## build: Build extractor, database schema, and QL library
52+
build: extractor dbscheme ql-library
53+
@echo "✓ Build complete"
54+
55+
## extractor: Build the PHP extractor (Rust binary)
56+
extractor: $(EXTRACTOR_BIN)
57+
@echo "✓ Extractor built: $(EXTRACTOR_BIN)"
58+
59+
$(EXTRACTOR_BIN): $(EXTRACTOR_DIR)/src/*.rs $(EXTRACTOR_DIR)/Cargo.toml
60+
@echo "Building PHP extractor..."
61+
cd $(EXTRACTOR_DIR) && $(CARGO) build --release
62+
@echo "✓ Extractor binary ready"
63+
64+
## dbscheme: Generate database schema from tree-sitter grammar
65+
dbscheme: $(DBSCHEME_FILE)
66+
@echo "✓ Database schema generated: $(DBSCHEME_FILE)"
67+
68+
$(DBSCHEME_FILE): $(EXTRACTOR_BIN)
69+
@echo "Generating database schema..."
70+
@mkdir -p $(dir $(DBSCHEME_FILE))
71+
$(EXTRACTOR_BIN) generate \
72+
--dbscheme $(DBSCHEME_FILE) \
73+
--library $(TREE_SITTER_QL)
74+
@echo "✓ Schema generation complete"
75+
76+
## ql-library: Generate QL library from tree-sitter grammar
77+
ql-library: $(TREE_SITTER_QL)
78+
@echo "✓ QL library generated: $(TREE_SITTER_QL)"
79+
80+
$(TREE_SITTER_QL): $(EXTRACTOR_BIN) $(DBSCHEME_FILE)
81+
@echo "QL library already generated with schema"
82+
@echo "✓ QL library ready"
83+
84+
## check: Check code without building
85+
check:
86+
@echo "Checking code..."
87+
cd $(EXTRACTOR_DIR) && $(CARGO) check
88+
@echo "✓ Code check passed"
89+
90+
## fmt: Format Rust code
91+
fmt:
92+
@echo "Formatting code..."
93+
cd $(EXTRACTOR_DIR) && $(CARGO) fmt
94+
@echo "✓ Code formatted"
95+
96+
## lint: Run clippy linter
97+
lint:
98+
@echo "Running clippy..."
99+
cd $(EXTRACTOR_DIR) && $(CARGO) clippy --all-targets --all-features -- -D warnings
100+
@echo "✓ Linting complete"
101+
102+
## doc: Generate documentation
103+
doc:
104+
@echo "Generating documentation..."
105+
cd $(EXTRACTOR_DIR) && $(CARGO) doc --no-deps --open
106+
@echo "✓ Documentation generated"
107+
108+
## test: Run all tests
109+
test: unit-tests query-tests
110+
@echo "✓ All tests passed"
111+
112+
## unit-tests: Run Rust unit tests
113+
unit-tests:
114+
@echo "Running Rust unit tests..."
115+
cd $(EXTRACTOR_DIR) && $(CARGO) test --release
116+
@echo "✓ Unit tests passed"
117+
118+
## query-tests: Run CodeQL query tests
119+
query-tests: build
120+
@echo "Running CodeQL query tests..."
121+
@if command -v codeql >/dev/null 2>&1; then \
122+
$(CODEQL) test run $(QL_SRC_DIR)/queries/security --verbose; \
123+
echo "✓ Query tests passed"; \
124+
else \
125+
echo "⚠ CodeQL CLI not found, skipping query tests"; \
126+
fi
127+
128+
## install: Install extractor and register libraries
129+
install: build
130+
@echo "Installing extractor..."
131+
@mkdir -p $(HOME)/.codeql/extractors/php/
132+
@cp $(EXTRACTOR_BIN) $(HOME)/.codeql/extractors/php/
133+
@cp codeql-extractor.yml $(HOME)/.codeql/extractors/php/
134+
@echo "✓ Extractor installed to $(HOME)/.codeql/extractors/php/"
135+
@echo ""
136+
@echo "QL Libraries:"
137+
@echo " - Library pack: $(QL_LIB_DIR)/qlpack.yml"
138+
@echo " - Query pack: $(QL_SRC_DIR)/qlpack.yml"
139+
@echo ""
140+
@echo "To use with CodeQL, set CODEQL_PYTHONPATH:"
141+
@echo " export CODEQL_PYTHONPATH=$$(pwd)/$(QL_LIB_DIR)"
142+
143+
## clean: Remove build artifacts
144+
clean:
145+
@echo "Cleaning build artifacts..."
146+
@rm -rf $(TARGET_DIR)
147+
@rm -rf $(BUILD_DIR)
148+
@rm -f $(DBSCHEME_FILE)
149+
@rm -f $(TREE_SITTER_QL)
150+
@cd $(EXTRACTOR_DIR) && $(CARGO) clean
151+
@echo "✓ Clean complete"
152+
153+
## clean-all: Remove all generated files
154+
clean-all: clean
155+
@echo "Removing all generated files..."
156+
@find . -name "*.lock" -delete
157+
@find . -name ".DS_Store" -delete
158+
@echo "✓ Full clean complete"
159+
160+
## dist: Create distribution package
161+
dist: build
162+
@echo "Creating distribution package..."
163+
@mkdir -p $(BUILD_DIR)/php
164+
@cp -r $(QL_LIB_DIR) $(BUILD_DIR)/php/
165+
@cp -r $(QL_SRC_DIR) $(BUILD_DIR)/php/
166+
@cp $(EXTRACTOR_BIN) $(BUILD_DIR)/php/extractor
167+
@cp codeql-extractor.yml $(BUILD_DIR)/php/
168+
@cp README.md $(BUILD_DIR)/php/
169+
@tar -czf $(BUILD_DIR)/php-support.tar.gz -C $(BUILD_DIR) php
170+
@echo "✓ Distribution package created: $(BUILD_DIR)/php-support.tar.gz"
171+
172+
## extract-example: Extract example PHP file
173+
extract-example: build
174+
@echo "Extracting example PHP file..."
175+
@mkdir -p build/trap
176+
@echo '<?php echo "Hello, World!"; ?>' > build/example.php
177+
$(EXTRACTOR_BIN) extract \
178+
--output build/trap \
179+
--source-root build/example.php \
180+
--verbose
181+
@echo "✓ Extraction complete. TRAP files in build/trap/"
182+
183+
## profile: Profile the extractor
184+
profile: build
185+
@echo "Profiling extractor..."
186+
cd $(EXTRACTOR_DIR) && $(CARGO) build --profile=bench
187+
@echo "✓ Profiling complete"
188+
189+
## version: Print version information
190+
version:
191+
@echo "CodeQL PHP Extractor Version Information"
192+
@echo "========================================"
193+
@$(EXTRACTOR_BIN) --version
194+
@$(EXTRACTOR_BIN) diag
195+
196+
.SILENT: help version

0 commit comments

Comments
 (0)