Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate Anonymous Apex #649

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
version: 2
jobs:
build:
docker:
- image: cimg/go:1.20
machine:
image: ubuntu-2204:2023.07.2
steps:
- checkout
- run: go install github.com/mitchellh/[email protected]
- run: go install github.com/tcnksm/[email protected]
- run: sudo apt-get update && sudo apt-get install p7zip-full
- run: sudo bash -c "curl -L --output - https://github.com/crazy-max/xgo/releases/download/v0.30.0/xgo_0.30.0_linux_amd64.tar.gz | tar xvz -C /usr/local/bin/ ./xgo"
- restore_cache: # restores saved cache if no changes are detected since last run
keys:
- go-mod-v4-{{ checksum "go.sum" }}
- run: make dist
- run:
command: |
sudo chmod 666 /var/run/docker.sock
if [ -f /var/run/docker-temp.sock ]; then
sudo chmod 666 /var/run/docker-temp.sock
fi
- run:
command: |
export GOPATH=/home/circleci/.go_workspace
make dist
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
Expand Down
42 changes: 29 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
VERSION=$(shell git describe --abbrev=0 --always)
LDFLAGS = -ldflags "-X github.com/ForceCLI/force/lib.Version=${VERSION}"
LDFLAGS = -ldflags "-s -w -X github.com/ForceCLI/force/lib.Version=${VERSION}"
LINUX_LDFLAGS = -ldflags "-s -w -extldflags '-static' -X github.com/ForceCLI/force/lib.Version=${VERSION}"
GCFLAGS = -gcflags="all=-N -l"
EXECUTABLE=force
WINDOWS=$(EXECUTABLE)_windows_amd64.exe
LINUX=$(EXECUTABLE)_linux_amd64
OSX_AMD64=$(EXECUTABLE)_osx_amd64
OSX_ARM64=$(EXECUTABLE)_osx_arm64
PACKAGE=.
WINDOWS=$(EXECUTABLE)-windows-amd64.exe
LINUX=$(EXECUTABLE)-linux-amd64
OSX_AMD64=$(EXECUTABLE)-darwin-amd64
OSX_ARM64=$(EXECUTABLE)-darwin-arm64
ALL=$(WINDOWS) $(LINUX) $(OSX_AMD64) $(OSX_ARM64)

default:
Expand All @@ -17,17 +19,27 @@ install:
install-debug:
go install ${LDFLAGS} ${GCFLAGS}

$(WINDOWS):
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) ${LDFLAGS}
$(WINDOWS): checkcmd-xgo
xgo -go 1.21 -out $(EXECUTABLE) -dest . ${LDFLAGS} -buildmode default -trimpath -targets windows/amd64 -pkg ${PACKAGE} -x .

$(LINUX):
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) ${LDFLAGS}
# Build static binaries on linux
$(LINUX): checkcmd-x86_64-linux-gnu-gcc checkcmd-x86_64-linux-gnu-g++
env \
GOOS=linux \
GOARCH=amd64 \
CC=x86_64-linux-gnu-gcc \
CXX=x86_64-linux-gnu-g++ \
CGO_ENABLED=1 \
CGO_FLAGS="-static"
go build -v -tags 'netgo osusergo' -o $(LINUX) ${LINUX_LDFLAGS} ${PACKAGE}

$(OSX_AMD64):
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -v -o $(OSX_AMD64) ${LDFLAGS}
# Build macOS binaries using docker images that contain SDK
# See https://github.com/crazy-max/xgo and https://github.com/tpoechtrager/osxcross
$(OSX_ARM64): checkcmd-xgo
xgo -go 1.21 -out $(EXECUTABLE) -dest . ${LDFLAGS} -buildmode default -trimpath -targets darwin/arm64 -pkg ${PACKAGE} -x .

$(OSX_ARM64):
env CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -v -o $(OSX_ARM64) ${LDFLAGS}
$(OSX_AMD64): checkcmd-xgo
xgo -go 1.21 -out $(EXECUTABLE) -dest . ${LDFLAGS} -buildmode default -trimpath -targets darwin/amd64 -pkg ${PACKAGE} -x .

$(basename $(WINDOWS)).zip: $(WINDOWS)
zip $@ $<
Expand All @@ -54,4 +66,8 @@ test:
clean:
-rm -f $(EXECUTABLE) $(EXECUTABLE)_*

checkcmd-%:
@hash $(*) > /dev/null 2>&1 || \
(echo "ERROR: '$(*)' must be installed and available on your PATH."; exit 1)

.PHONY: default dist clean docs
14 changes: 14 additions & 0 deletions command/apex.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import (
"os"

. "github.com/ForceCLI/force/error"
"github.com/ForceCLI/force/lib/apex"
"github.com/spf13/cobra"
)

var skipValidation bool

func init() {
apexCmd.Flags().BoolVar(&skipValidation, "skip-validation", false, "do not validate the apex before executing")
apexCmd.Flags().BoolP("test", "t", false, "run in test context")
RootCmd.AddCommand(apexCmd)
}
Expand Down Expand Up @@ -40,6 +44,11 @@ var apexCmd = &cobra.Command{
func runApexFromStdin(testContext bool) {
fmt.Println(">> Start typing Apex code; press CTRL-D(for Mac/Linux) / Ctrl-Z (for Windows) when finished")
code, err := ioutil.ReadAll(os.Stdin)
if !skipValidation {
if err = apex.ValidateAnonymous(code); err != nil {
ErrorAndExit(err.Error())
}
}
fmt.Println("\n\n>> Executing code...")
var output string
if testContext {
Expand All @@ -58,6 +67,11 @@ func runApexInFile(filename string, testContext bool) {
if err != nil {
ErrorAndExit(err.Error())
}
if !skipValidation {
if err = apex.ValidateAnonymous(code); err != nil {
ErrorAndExit(err.Error())
}
}
var output string
if testContext {
output, err = executeAsTest(code)
Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ require (
github.com/hamba/avro/v2 v2.16.0
github.com/linkedin/goavro/v2 v2.12.0
github.com/obeattie/ohmyglob v0.0.0-20150811221449-290764208a0d
github.com/octoberswimmer/go-tree-sitter-sfapex v0.0.0-20231116160255-e631b59d5292
github.com/olekukonko/tablewriter v0.0.5
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.10.0
github.com/onsi/gomega v1.23.0
github.com/pkg/errors v0.9.1
github.com/rgalanakis/golangal v0.0.0-20210923203926-e36008487518
github.com/smacker/go-tree-sitter v0.0.0-20230223055714-4d4cba2a4780
github.com/spf13/cobra v1.7.0
golang.org/x/crypto v0.14.0
google.golang.org/grpc v1.39.0-dev
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637
)
Expand All @@ -37,9 +39,10 @@ require (
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hpcloud/tail v1.0.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down Expand Up @@ -67,11 +70,9 @@ require (
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/genproto v0.0.0-20230222225845-10f96fb3dbec // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading