Skip to content

Commit

Permalink
support remappings, drop support for dependencies (#144)
Browse files Browse the repository at this point in the history
* remove ill defined dependency type, support generic remappings

* pin solc version
  • Loading branch information
martyall committed Sep 27, 2023
1 parent 13c0f4b commit 3878dfe
Show file tree
Hide file tree
Showing 4 changed files with 12 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
2 changes: 1 addition & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let additions =
, "tuples"
]
, repo = "https://github.com/f-o-a-m/purescript-solc.git"
, version = "v4.1.0"
, version = "v4.2.0"
}
, 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 3878dfe

Please sign in to comment.