Skip to content

Commit

Permalink
remove ill defined dependency type, support generic remappings
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Sep 27, 2023
1 parent 13c0f4b commit d2a1db7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion example/chanterelle.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"modules": [ "Token"
, "SimplePaidStorage"
],
"dependencies": [ "openzeppelin-contracts" ],
"remappings": [ "openzeppelin-contracts=node_modules/openzeppelin-contracts" ],
"solc-output-selection": [],
"purescript-generator": {
"output-path": "src",
Expand Down
3 changes: 2 additions & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let upstream =
https://raw.githubusercontent.com/f-o-a-m/package-sets/921ac217454768ec3f614a9571c109b2ad542c07/purs-0.15.7-web3.dhall
sha256:818d12df6f7ce455657ff559798e50ec14e098f8d6acc655f674f26c7a007e3d
with solc = ../purescript-solc/spago.dhall as Location

let additions =
{ solc =
Expand All @@ -27,7 +28,7 @@ let additions =
, "tuples"
]
, repo = "https://github.com/f-o-a-m/purescript-solc.git"
, version = "v4.1.0"
, version = "cb1fcd29b2e5ccd35a78bf13165e78fcdfeb349a"
}
, web3-generator =
{ dependencies =
Expand Down
8 changes: 5 additions & 3 deletions src/Chanterelle/Compile.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Chanterelle.Logging (LogLevel(..), log, logSolcError)
import Chanterelle.Types.Artifact (Artifact(..))
import Chanterelle.Types.Bytecode (Bytecode(..), flattenLinkReferences)
import Chanterelle.Types.Compile (CompileError(..))
import Chanterelle.Types.Project (ChanterelleModule(..), ChanterelleProject(..), ChanterelleProjectSpec(..), Dependency(..), getSolc, partitionSelectionSpecs)
import Chanterelle.Types.Project (ChanterelleModule(..), ChanterelleProject(..), ChanterelleProjectSpec(..), getSolc, partitionSelectionSpecs)
import Chanterelle.Utils (assertDirectory', fileIsDirty)
import Chanterelle.Utils.Error (withExceptT')
import Control.Error.Util (note)
Expand Down Expand Up @@ -169,9 +169,11 @@ makeSolcInput moduleName sourcePath = do
{ cls: requestedContractSelections, fls: requestedFileSelections } = partitionSelectionSpecs spec.solcOutputSelection
contractLevelSelections = [ ST.ABI, ST.EvmOutputSelection (Just $ ST.BytecodeSelection Nothing), ST.EvmOutputSelection (Just $ ST.DeployedBytecodeSelection Nothing) ] <> requestedContractSelections
outputSelection = Just $ ST.OutputSelections (M.singleton "*" (ST.OutputSelection { file: requestedFileSelections, contract: M.singleton "*" contractLevelSelections }))
depMappings = (\(Dependency dep) -> ST.Remapping { from: dep, to: (project.root <> "/node_modules/" <> dep) }) <$> spec.dependencies
sourceDirMapping = [ ST.GlobalRemapping { to: (Path.concat [ project.root, spec.sourceDir ]) } ]
remappings = sourceDirMapping <> depMappings
f remapping = case remapping of
ST.Remapping { from, to } -> ST.Remapping { from, to: Path.concat [ project.root, to ] }
g -> g
remappings = sourceDirMapping <> map f spec.remappings
optimizer = spec.solcOptimizerSettings
evmVersion = spec.solcEvmVersion
metadata = Nothing
Expand Down
22 changes: 5 additions & 17 deletions src/Chanterelle/Types/Project.purs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ import Node.Path as Path
-- | Chanterelle Project Types
--------------------------------------------------------------------------------

newtype Dependency = Dependency String

derive instance eqDependency :: Eq Dependency

instance encodeJsonDependency :: EncodeJson Dependency where
encodeJson (Dependency d) = encodeJson d

instance decodeJsonDependency :: DecodeJson Dependency where
decodeJson d = Dependency <$> decodeJson d

---------------------------------------------------------------------

newtype Library = Library { name :: String, sourceRoot :: Maybe FilePath, sourceFile :: FilePath }

derive instance newtypeLibrary :: Newtype Library _
Expand Down Expand Up @@ -274,7 +262,7 @@ newtype ChanterelleProjectSpec =
, artifactsDir :: FilePath
, libArtifactsDir :: FilePath
, modules :: Array String
, dependencies :: Array Dependency
, remappings :: Array ST.Remapping
, extraAbis :: Maybe FilePath
, libraries :: Libraries
, networks :: Networks
Expand All @@ -298,8 +286,8 @@ instance EncodeJson ChanterelleProjectSpec where
~> "source-dir" := project.sourceDir
~> "artifacts-dir" := project.artifactsDir
~> "modules" := project.modules
~> "dependencies" := project.dependencies
~> "extra-abis" := project.dependencies
~> "remappings" := project.remappings
~> "extra-abis" := project.extraAbis
~> "libraries" := project.libraries
~> "networks" := project.networks
~> "purescript-generator" := psGenEncode
Expand Down Expand Up @@ -328,7 +316,7 @@ instance DecodeJson ChanterelleProjectSpec where
artifactsDir <- obj .:! "artifacts-dir" .!= "build"
libArtifactsDir <- obj .:! "library-artifacts-dir" .!= (Path.concat [ artifactsDir, "libraries" ])
modules <- obj .: "modules"
dependencies <- obj .:! "dependencies" .!= mempty
remappings <- obj .:! "remappings" .!= mempty
extraAbis <- obj .:! "extra-abis"
libraries <- obj .:! "libraries" .!= mempty
networks <- obj .:! "networks" .!= mempty
Expand All @@ -337,7 +325,7 @@ instance DecodeJson ChanterelleProjectSpec where
solcOutputSelection <- obj .:! "solc-output-selection" .!= mempty
solcEvmVersion <- obj .:! "solc-evm-version"
psGen <- psGenDecode =<< obj .: "purescript-generator"
pure $ ChanterelleProjectSpec { name, version, sourceDir, artifactsDir, libArtifactsDir, modules, dependencies, extraAbis, libraries, networks, psGen, solcVersion, solcEvmVersion, solcOptimizerSettings, solcOutputSelection }
pure $ ChanterelleProjectSpec { name, version, sourceDir, artifactsDir, libArtifactsDir, modules, remappings, extraAbis, libraries, networks, psGen, solcVersion, solcEvmVersion, solcOptimizerSettings, solcOutputSelection }

where
psGenDecode psj = do
Expand Down

0 comments on commit d2a1db7

Please sign in to comment.